@wafertools/wafermap 0.36.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +385 -0
  3. package/README.md +7 -7
  4. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  6. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  10. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  13. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  15. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/patCard.d.ts +23 -0
  17. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  18. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  19. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  20. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  21. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  23. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  24. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  25. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  26. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  27. package/dist/packages/canvas-adapter/dieList.js +2 -2
  28. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  29. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  30. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  31. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  32. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  34. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  35. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  36. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  37. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  38. package/dist/packages/canvas-adapter/icons.js +1 -1
  39. package/dist/packages/canvas-adapter/insightsTab.d.ts +52 -2
  40. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  41. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  42. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  43. package/dist/packages/canvas-adapter/patMode.d.ts +27 -0
  44. package/dist/packages/canvas-adapter/patMode.js +1 -0
  45. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  46. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  47. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  48. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  49. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  50. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  51. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  52. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  53. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  54. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  55. package/dist/packages/canvas-adapter/summaryPanel.d.ts +15 -5
  56. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  57. package/dist/packages/canvas-adapter/toolbar.d.ts +17 -2
  58. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  59. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  60. package/dist/packages/canvas-adapter/userGuideHtml.js +590 -140
  61. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  62. package/dist/packages/canvas-adapter/version.js +1 -1
  63. package/dist/packages/core/classify.d.ts +11 -0
  64. package/dist/packages/core/classify.js +1 -1
  65. package/dist/packages/core/dies.d.ts +2 -0
  66. package/dist/packages/core/dies.js +1 -1
  67. package/dist/packages/core/wafer.d.ts +2 -2
  68. package/dist/packages/renderer/buildView.js +1 -1
  69. package/dist/packages/renderer/buildWaferMap.d.ts +2 -0
  70. package/dist/packages/renderer/buildWaferMap.js +1 -1
  71. package/dist/packages/renderer/deprecate.d.ts +2 -8
  72. package/dist/packages/renderer/deprecate.js +1 -1
  73. package/dist/packages/renderer/fmt.js +1 -1
  74. package/dist/packages/renderer/testLabel.d.ts +0 -11
  75. package/dist/packages/renderer/testLabel.js +1 -1
  76. package/dist/packages/stats/analyzeWaferLot.d.ts +6 -0
  77. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  78. package/dist/packages/stats/analyzeWaferMap.d.ts +8 -0
  79. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  80. package/dist/packages/stats/binPareto.d.ts +2 -54
  81. package/dist/packages/stats/binPareto.js +1 -1
  82. package/dist/packages/stats/binRows.js +1 -1
  83. package/dist/packages/stats/capability.d.ts +10 -0
  84. package/dist/packages/stats/capability.js +1 -1
  85. package/dist/packages/stats/cardSpec.d.ts +53 -0
  86. package/dist/packages/stats/cardSpec.js +1 -0
  87. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  88. package/dist/packages/stats/chartCatalogue.js +1 -0
  89. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  90. package/dist/packages/stats/clusterDetection.js +1 -1
  91. package/dist/packages/stats/commonality.d.ts +62 -0
  92. package/dist/packages/stats/commonality.js +1 -0
  93. package/dist/packages/stats/control.d.ts +21 -0
  94. package/dist/packages/stats/control.js +1 -0
  95. package/dist/packages/stats/correlation.d.ts +9 -3
  96. package/dist/packages/stats/correlation.js +1 -1
  97. package/dist/packages/stats/dieRegions.d.ts +4 -1
  98. package/dist/packages/stats/dieRegions.js +1 -1
  99. package/dist/packages/stats/differenceMap.d.ts +22 -0
  100. package/dist/packages/stats/differenceMap.js +1 -0
  101. package/dist/packages/stats/examplePicks.d.ts +22 -0
  102. package/dist/packages/stats/examplePicks.js +1 -0
  103. package/dist/packages/stats/filterFile.d.ts +41 -0
  104. package/dist/packages/stats/filterFile.js +2 -0
  105. package/dist/packages/stats/filterFindings.d.ts +20 -5
  106. package/dist/packages/stats/filterFindings.js +1 -1
  107. package/dist/packages/stats/groupCompare.d.ts +87 -0
  108. package/dist/packages/stats/groupCompare.js +1 -0
  109. package/dist/packages/stats/guideSections.d.ts +55 -0
  110. package/dist/packages/stats/guideSections.js +1 -0
  111. package/dist/packages/stats/index.d.ts +3 -1
  112. package/dist/packages/stats/index.js +1 -1
  113. package/dist/packages/stats/math.d.ts +29 -4
  114. package/dist/packages/stats/math.js +1 -1
  115. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  116. package/dist/packages/stats/metadataColumns.js +1 -1
  117. package/dist/packages/stats/pat.d.ts +58 -0
  118. package/dist/packages/stats/pat.js +1 -0
  119. package/dist/packages/stats/patSummary.d.ts +45 -0
  120. package/dist/packages/stats/patSummary.js +1 -0
  121. package/dist/packages/stats/patternClassification.d.ts +3 -3
  122. package/dist/packages/stats/patternClassification.js +1 -1
  123. package/dist/packages/stats/plotData.d.ts +294 -17
  124. package/dist/packages/stats/plotData.js +1 -1
  125. package/dist/packages/stats/plotId.d.ts +2 -0
  126. package/dist/packages/stats/plotId.js +1 -1
  127. package/dist/packages/stats/plotReferences.d.ts +17 -0
  128. package/dist/packages/stats/plotReferences.js +1 -0
  129. package/dist/packages/stats/plotSpec.d.ts +239 -3
  130. package/dist/packages/stats/plotSpec.js +4 -4
  131. package/dist/packages/stats/regions.js +1 -1
  132. package/dist/packages/stats/renderSummaryReport.js +31 -31
  133. package/dist/packages/stats/reportHtml.js +9 -13
  134. package/dist/packages/stats/synthesis.d.ts +44 -16
  135. package/dist/packages/stats/synthesis.js +1 -1
  136. package/dist/packages/stats/testPassRate.d.ts +7 -0
  137. package/dist/packages/stats/testPassRate.js +1 -1
  138. package/dist/packages/stats/types.d.ts +13 -8
  139. package/dist/packages/stats/yield.d.ts +3 -11
  140. package/dist/packages/stats/yield.js +1 -1
  141. package/llms.txt +1 -1
  142. package/package.json +10 -2
  143. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  144. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  145. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  146. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  147. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  148. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  149. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  150. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  151. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  152. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  153. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  154. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  155. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  156. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  157. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  158. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1 +1 @@
1
- import{normalizeInput as st}from"./normalizeInput.js";import{autoDecision as ot,testValueStatus as at}from"./testValueBudget.js";import{computeCapability as rt,computeTestFlagYield as ft,computeRegionYield as lt}from"./summaryFigures.js";import{binPassSets as Ee}from"../renderer/binColors.js";import{diePassStatus as be,isYieldEligibleDie as ye,getDieKey as Se,isPositionedDie as Ke,positionKey as ve}from"../core/dies.js";import{dieHasValues as ct,testsPresent as Oe,testValue as Y}from"../core/dieTable.js";import{stackBinsAreData as ut}from"../core/aggregates.js";import{getTestPassStatus as le,isParametricTest as X}from"../renderer/buildWaferMap.js";import{markedTestLabel as I,derivedFields as ce}from"../renderer/testLabel.js";import{buildQuadrantRegions as dt,buildReticlePositionRegions as mt,buildRingRegions as ht,buildSectorRegions as pt,buildTestSiteRegions as gt,sectorCompassNames as Le,areQuadrantsAdjacent as bt,parseRegionKey as Z,QUADRANT_CYCLE as we,regionAngleBins as yt}from"./regions.js";import{buildClusterFindings as St}from"./clusterDetection.js";import{classifyPattern as vt,patternExplains as wt,patternFailVerdict as $t,PATTERN_LABELS as Rt}from"./patternClassification.js";import{requirePassBins as kt}from"../core/passBins.js";import{requireRingCount as Mt}from"../core/ringCount.js";import{benjaminiHochberg as Dt,fisherExact as zt,fiveNumberSummary as Bt,sampleVariance as $e,zPValue as Ae}from"./math.js";import{mean as ue,maxOf as Ft}from"../core/utils.js";import{classifySpec as de,isOutOfSpec as Re}from"../renderer/spec.js";const xt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},qe=[4,8,16];export function resolveOptions(e){const t=Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0)),s={...ie,...t},o=[],n=[];for(const a of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:u,max:l}=xt[a],d=s[a];if(typeof d!="number"||!Number.isFinite(d)){n.push(`${a}=${String(d)} is not a finite number (using ${ie[a]})`),s[a]=ie[a];continue}const f=Math.min(l,Math.max(u,d));f!==d&&(n.push(`${a}=${d} is outside ${u}\u2013${l} (using ${f})`),s[a]=f)}if(qe.includes(s.sectorCount)||(n.push(`sectorCount=${s.sectorCount} is not one of ${qe.join(", ")} (using ${ie.sectorCount})`),s.sectorCount=ie.sectorCount),n.length){const a=`analyzeWaferMap: ${n.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const i=["passBins","ringCount"].filter(a=>t[a]!==void 0);if(i.length){const a=`analyzeWaferMap: ${i.join(" and ")} ${i.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${i.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const r=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(a=>t[a]!==void 0);if(r.length){const a=`analyzeWaferMap: ${r.join(", ")} ${r.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}return{resolved:s,warnings:o}}const ie={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:"auto",computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function Pt(e,t){const s={...e};return s.minimumClusterSize=Math.max(5,Math.round(t*.003)),s}function Te(e){return ye(e)?e.hbin!==void 0||e.sbin!==void 0||ct(e):!1}function Nt(e,t,s){if(!e||t)return;const o=(s??[]).filter(n=>X(n)&&(n.limitLow!==void 0||n.limitHigh!==void 0));if(o.length!==0)return n=>{for(const i of o)if(Re(de(Y(n,i.testNumber),i)))return!0;return!1}}function Ct(e,t,s){const o=new Set,n=new Set,i=new Set,r=new Map,a=new Map;for(const u of Oe(e))o.add(u);for(const u of e)u.hbin!==void 0&&n.add(u.hbin),u.sbin!==void 0&&i.add(u.sbin),ye(u)&&(u.hbin!==void 0&&r.set(u.hbin,(r.get(u.hbin)??0)+1),u.sbin!==void 0&&a.set(u.sbin,(a.get(u.sbin)??0)+1));return{totalDies:e.length,analyzedDies:t,excludedDies:e.length-t,yieldPercent:s,testsConsidered:[...o].sort((u,l)=>u-l),hardBinsConsidered:[...n].sort((u,l)=>u-l),softBinsConsidered:[...i].sort((u,l)=>u-l),...r.size?{hardBinCounts:Object.fromEntries(r)}:{},...a.size?{softBinCounts:Object.fromEntries(a)}:{}}}function Vt(e,t,s){if(!t?.length)return;const o=t.filter(i=>X(i)&&(i.limitLow!==void 0||i.limitHigh!==void 0));if(!o.length)return;const n=[];for(const i of o){const r=i.testNumber;let a=0,u=0,l=0,d=0;for(const f of e){if(f.partial||f.edgeExcluded)continue;const p=de(Y(f,r),i);if(p!==null){if(d++,p==="failLow")u++;else if(p==="failHigh")l++;else{a++;continue}s?.(r,f)}}n.push({testNumber:r,label:i.name,passDies:a,failLowDies:u,failHighDies:l,totalDies:d,yieldPercent:d>0?a/d*100:null})}return n.length?n:void 0}export function computeFunctionalYield(e,t,s){if(!t?.length)return;const o=t.filter(i=>!X(i));if(!o.length)return;const n=[];for(const i of o){const r=i.testNumber;let a=0,u=0;for(const d of e){if(d.partial||d.edgeExcluded)continue;const f=le(d,r,i);if(f!==void 0){if(f){a++;continue}u++,s?.(r,d)}}const l=a+u;n.push({testNumber:r,label:I(i,r),...ce(i),passDies:a,failDies:u,totalDies:l,passRatePercent:l>0?a/l*100:null})}return n.length?n:void 0}function Et(e,t,s,o){const n=[];for(const i of t){const r=[];for(const f of e){if(f.partial||f.edgeExcluded)continue;const p=Y(f,i);p!==void 0&&Number.isFinite(p)&&r.push(p)}if(r.length<o)continue;const a=ue(r),u=Math.sqrt($e(r,a)),l=Bt(Float64Array.from(r)),d=s?.find(f=>f.testNumber===i)?.name??String(i);n.push({testNumber:i,label:d,count:r.length,min:l.min,max:l.max,mean:a,stddev:u,median:l.median,q1:l.q1,q3:l.q3})}return n.length?n:void 0}export function twoProportionZ(e,t,s,o){const n=(e+s)/(t+o),i=n*(1-n)*(1/t+1/o);return!Number.isFinite(i)||i<=0?0:(e/t-s/o)/Math.sqrt(i)}const Kt=5;function T(e,t,s,o){const n=t+o,i=e+s;if((n>0?Math.min(i,n-i)*Math.min(t,o)/n:0)<Kt)return{pValue:zt(e,t-e,s,o-s),method:"fisher-exact"};const a=twoProportionZ(e,t,s,o);return{pValue:a===0?1:Ae(a),method:"two-proportion-z"}}function Ot(e,t,s,o){return T(e,t,s,o).pValue}export function adjustPValues(e){const t=e.filter(o=>o.stats.pValue!==void 0),s=Dt(t.map(o=>o.stats.pValue));return t.forEach((o,n)=>{o.stats.adjustedPValue=s[n]}),e}export function rateRelativeEffect(e){const t=(e.passRate?e.n-e.hits:e.hits)/e.n,s=(e.passRate?e.restN-e.restHits:e.restHits)/e.restN;return s===0?t===0?0:1/0:Math.abs(t-s)/s}export function severityForFinding(e,t,s){const o=Math.abs(t),n=s;return e<=.01&&(o>=.3||n>=2.5)?"unusual":e<=.05&&(o>=.2||n>=1.5)?"notable":"info"}export function severityForScore(e,t){return e<=.01&&Math.abs(t)>=.5?"unusual":e<=.05&&Math.abs(t)>=.15?"notable":"info"}function me(e){return e==="reticle-position"?"other reticle positions":e==="test-site"?"other test sites":"the rest of the map"}function J(e){return e==="reticle-position"?"Other reticle positions":e==="test-site"?"Other test sites":"Rest of map"}function ke(e,t,s){const o=(Math.abs(t)*100).toFixed(1);return`${e} yield is ${o} percentage points ${t>0?"higher":"lower"} than ${me(s)}`}function Me(e,t){return t==="quadrant"&&!e.startsWith("Quadrant")?`quadrant ${e}`:e}function je(e){return/^(Rings|Sectors|Quadrants)\b/.test(e)?"have":"has"}function De(e,t,s,o){const n=Me(e,o),i=(Math.abs(s)*100).toFixed(1);return`${n} ${je(n)} ${t} occurrence ${i} percentage points ${s>0?"higher":"lower"} than ${me(o)}`}function ze(e,t,s,o){const n=Me(e,o),i=(Math.abs(s)*100).toFixed(1);return`${n} ${je(n)} ${t} pass rate ${i} percentage points ${s>0?"higher":"lower"} than ${me(o)}`}function Be(e,t,s,o,n,i){const r=Me(e,n),a=me(n),u=s>0?"higher":"lower";if(o!==void 0&&Number.isFinite(o)){const d=(Math.abs(o)*100).toFixed(1);return`${r} mean ${t} is ${d}% ${u} than ${a}`}const l=i?` ${i}`:"";return`${r} mean ${t} is ${Math.abs(s).toPrecision(3)}${l} ${u} than ${a}`}function He(e,t,s){const o=t?.find(n=>n.bin===e);return o?.name?`${s} ${e} (${o.name})`:`${s} ${e}`}function Lt(e,t){const s=t?.find(o=>o.testNumber===e);return{label:I(s,e),unit:s?.unit,...ce(s)}}const Ie=new WeakMap,We=new WeakMap,Ye=new WeakMap;function se(e,t){const s=t.highlight.dieKeys;return s&&Ye.set(s,e),t}let ee=null,oe;const _e=new WeakMap;export function candidatesOf(e){return _e.get(e)}function Qe(e,t,s,o){if(!ee)return;const n=Ue(e);if(!n)return;const i=e.id.slice(0,e.id.indexOf(":")),r=i==="specLimit"?"limitFail":i,{kind:a,bin:u,index:l}=e.variable;ee.push({key:[r,a,u??"",l??"",n.family,n.key].join("|"),source:r,variable:e.variable,label:e.variable.label,comparison:e.comparison,region:n,z:t,delta:e.effect.absoluteDelta??0,effectSize:e.effect.effectSize??0,relativeDelta:e.effect.relativeDelta,rate:s,mean:o})}export function describeRegional(e,t,s){const o=e.comparison.left,n=e.region.family;switch(e.source){case"yield":return ke(o,t,n);case"hardBin":case"softBin":return De(o,e.label,t,n);case"functional":return ze(o,e.label.replace(/ pass rate$/,""),t,n);case"limitFail":return Fe(o,e.label,t);case"test":return Be(o,e.label,t,s,n,e.variable.unit)}}function Fe(e,t,s){return`${e} limit fail rate for ${t} is ${(Math.abs(s)*100).toFixed(1)} pp ${s>0?"higher":"lower"} than the rest of the wafer`}const _=new WeakMap;function he(e,t){return _.set(e,t),e}function Ue(e){const t=e.highlight.dieKeys;return t?Ye.get(t):void 0}const Ge=new WeakMap;function Q(e){let t=Ge.get(e);return t||Ge.set(e,t=e.map(ve)),t}function At(e){let t=Ie.get(e);return t||Ie.set(e,t=e.map(Se)),t}function pe(e,t){let s=We.get(e);s||We.set(e,s={members:new Set(e),byFamily:new WeakMap});const o=s.byFamily.get(t);if(o)return o;const{members:n}=s,i=new Map;for(const r of t)i.set(r.key,r.dies.filter(a=>n.has(a)));return s.byFamily.set(t,i),i}function qt(e,t){adjustPValues(e);for(const n of e){const i=_.get(n);Qe(n,twoProportionZ(i.hits,i.n,i.restHits,i.restN),i)}const s=e.filter(n=>passesRateGate(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(_.get(n)),t)),o=confirmRegionalFindings(s,Xe,(n,i)=>Tt(n,i,t),n=>isRateLoss(_.get(n)),e);return s.filter(n=>o.has(n)).map(n=>({...n,severity:severityForFinding(n.stats.adjustedPValue??n.stats.pValue??1,n.effect.absoluteDelta??0,rateRelativeEffect(_.get(n)))}))}export function passesRateGate(e,t,s,o){return e<=o.significanceLevel&&(Math.abs(t)>=o.minimumEffectSize||s>=o.minimumRelativeEffect)}export function claimForPattern(e,t,s,o,n){const i=[];for(const r of s){const a=r.comparison.family,u=a==="ring"?o(r):[];e.some(l=>wt(l,a,u,n))&&(i.push(r.id),t!=="info"&&(a==="ring"||a==="quadrant"||a==="sector")&&(r.severity="info"))}return i}export function confirmRegionalFindings(e,t,s,o,n=e){const i=new Map;for(const u of e)(i.get(t(u))??i.set(t(u),[]).get(t(u))).push(u);const r=new Map;if(o)for(const u of n)o(u)&&(r.get(t(u))??r.set(t(u),[]).get(t(u))).push(u);const a=new Set;for(const[u,l]of i){const d=r.get(u)??[],f=(h,m)=>o&&!o(h)?s(h,[...new Set([...m,...d])].filter(g=>g!==h)):s(h,m);if(l.length===1&&(!o||o(l[0])||d.length===0)){a.add(l[0]);continue}const p=[];let c=[...l];for(;;){let h;for(const m of c){const g=f(m,p);if(g==="baseline-too-small"||!g.passes)continue;const S=o?.(m)??!1;(!h||S&&!h.loss||S===h.loss&&g.pValue<h.p)&&(h={t:m,p:g.pValue,loss:S})}if(!h)break;p.push(h.t),c=c.filter(m=>m!==h.t)}for(;;){let h;for(const m of p){const g=f(m,p.filter(S=>S!==m));g==="baseline-too-small"||g.passes||(!h||g.pValue>h.p)&&(h={t:m,p:g.pValue})}if(!h)break;p.splice(p.indexOf(h.t),1)}for(const h of p)a.add(h)}return a}function Xe(e){return[e.variable.kind,e.variable.bin??"",e.variable.index??"",e.comparison.family].join("\0")}function Ze(e){const t=e.stats.pValue??1;return t>0?(e.stats.adjustedPValue??t)/t:1}export function isRateLoss(e){const t=e.hits/e.n-e.restHits/e.restN;return e.passRate?t<0:t>0}function Tt(e,t,s){const o=_.get(e);let{restHits:n,restN:i}=o;for(const l of t){const d=_.get(l);d&&(n-=d.hits,i-=d.n)}if(i<s.minimumSampleSize)return"baseline-too-small";const r=o.hits/o.n-n/i,a=Math.min(1,Ot(o.hits,o.n,n,i)*Ze(e)),u=Math.sign(r)===Math.sign(e.effect.absoluteDelta??0)&&passesRateGate(a,r,rateRelativeEffect({...o,restHits:n,restN:i}),s);return{pValue:a,passes:u}}const xe=new WeakMap;export function welchOfSums(e,t,s,o){const n=(i,r,a)=>a>1?Math.max(0,i-r*r/a)/(a-1):0;return welchFromStats(e.n,e.sum/e.n,n(e.sq,e.sum,e.n),t,s/t,n(o,s,t))}function jt(e,t,s){const o=xe.get(e);let{restN:n,restSum:i,restSq:r}=o;for(const p of t){const c=xe.get(p);c&&(n-=c.n,i-=c.sum,r-=c.sq)}if(n<s.minimumSampleSize)return"baseline-too-small";const{pValue:a,effectSize:u,delta:l}=welchOfSums(o,n,i,r),d=Math.min(1,a*Ze(e)),f=Math.sign(l)===Math.sign(e.effect.absoluteDelta??0)&&d<=s.significanceLevel&&Math.abs(u)>=s.minimumEffectSize;return{pValue:d,passes:f}}function ae(e,t,s,o){const n=new Set(s),i=pe(e,t),r=new Map,a=new Map;for(const[l,d]of i){let f=0,p=0;for(const c of d)c.hbin!==void 0&&(p++,n.has(c.hbin)&&f++);r.set(l,f),a.set(l,p)}const u=[];for(const l of t){const d=a.get(l.key)??0,f=r.get(l.key)??0;let p=0,c=0;for(const[k,w]of a)k!==l.key&&(p+=w,c+=r.get(k)??0);if(d<o.minimumSampleSize||p<o.minimumSampleSize)continue;const h=f/d,m=c/p,g=h-m,{pValue:S,method:F}=T(f,d,c,p);u.push(he(se(l,{id:`yield:${l.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:l.family,left:l.label,right:J(l.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:m===0?void 0:g/m,effectSize:g},stats:{method:F,pValue:S,sampleSizeLeft:d,sampleSizeRight:p},summary:ke(l.label,g,l.family),highlight:{kind:"region",regionFamily:l.family,regionKeys:[l.key],dieKeys:[...l.dieKeys]}}),{hits:f,n:d,restHits:c,restN:p,passRate:!0}))}return u}function q(e,t,s,o,n,i){const r=h=>s==="soft"?h.sbin:h.hbin,a=[...new Set(e.map(r).filter(h=>h!==void 0))].sort((h,m)=>h-m),u=pe(e,t),l=new Map,d=new Map;for(const[h,m]of u){const g=new Map;for(const S of m){const F=r(S);F!==void 0&&g.set(F,(g.get(F)??0)+1)}l.set(h,g),d.set(h,m.length)}const f=[],p=n==="hardBin"?"HBin":"SBin",c=s==="hard"?new Set(i.passBins):i.softPassBins??Ee(e,i.passBins).soft;for(const h of t){const m=d.get(h.key)??0,g=l.get(h.key);let S=0;const F=new Map;for(const[k,w]of l)if(k!==h.key){S+=d.get(k)??0;for(const[B,z]of w)F.set(B,(F.get(B)??0)+z)}if(!(m<i.minimumSampleSize||S<i.minimumSampleSize))for(const k of a){const w=g.get(k)??0,B=F.get(k)??0,z=w/m,b=B/S,$=z-b,{pValue:M,method:v}=T(w,m,B,S),R=He(k,o,p);f.push(he(se(h,{id:`${n}:${k}:${h.key}`,level:"wafer",severity:"info",variable:{kind:n,bin:k,label:R},comparison:{family:h.family,left:h.label,right:J(h.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:b===0?void 0:$/b,effectSize:$},stats:{method:v,pValue:M,sampleSizeLeft:m,sampleSizeRight:S},summary:De(h.label,R,$,h.family),highlight:{kind:"bin",bin:k,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:w,n:m,restHits:B,restN:S,passRate:c.has(k)}))}}return f}function re(e,t,s,o){const n=(s??[]).filter(d=>!X(d));if(!n.length)return[];const i=n.map(d=>d.testNumber),r=pe(e,t),a=new Map,u=new Map;for(const[d,f]of r){const p=new Uint32Array(n.length),c=new Uint32Array(n.length);for(const h of f)for(let m=0;m<n.length;m++){const g=le(h,i[m],n[m]);g!==void 0&&(c[m]++,g&&p[m]++)}a.set(d,p),u.set(d,c)}const l=[];for(const d of t){const f=a.get(d.key),p=u.get(d.key);for(let c=0;c<n.length;c++){let h=0,m=0;for(const[$,M]of u)$!==d.key&&(m+=M[c],h+=a.get($)[c]);const g=p[c],S=f[c];if(g<o.minimumSampleSize||m<o.minimumSampleSize)continue;const F=S/g,k=h/m,w=F-k,{pValue:B,method:z}=T(S,g,h,m),b=i[c];l.push(he(se(d,{id:`functional:${b}:${d.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:b,label:`${I(n[c],b)} pass rate`,...ce(n[c])},comparison:{family:d.family,left:d.label,right:J(d.family)},effect:{direction:w===0?"different":w>0?"higher":"lower",absoluteDelta:w,relativeDelta:k===0?void 0:w/k,effectSize:w},stats:{method:z,pValue:B,sampleSizeLeft:g,sampleSizeRight:m},summary:ze(d.label,I(n[c],b),w,d.family),highlight:{kind:"region",regionFamily:d.family,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:S,n:g,restHits:h,restN:m,passRate:!0}))}}return l}export function welchFromStats(e,t,s,o,n,i){const r=Math.sqrt(s/e+i/o),a=t-n;if(!Number.isFinite(r)||r===0)return{pValue:1,effectSize:0,delta:a,z:0};const u=a/r,l=Math.sqrt(Math.max(0,(s+i)/2)),d=l===0?a:a/l;return{pValue:Ae(u),effectSize:d,delta:a,z:u}}function Ht(e,t){const s=ue(e),o=ue(t);return welchFromStats(e.length,s,$e(e,s),t.length,o,$e(t,o))}function Je(e,t,s){const o=n=>n.filter(i=>X(s?.find(r=>r.testNumber===i)));return o(t?t.slice().sort((n,i)=>n-i):Oe(e,"values"))}export function testValueSize(e,t){const s=e.dies.filter(Te);return{tests:Je(s,t.testNumbers,e.testDefs).length,dies:s.length}}export function recordedOptions(e){const t={};return e.enableTestValueAnalysis!==void 0&&(t.enableTestValueAnalysis=e.enableTestValueAnalysis),e.computePerTestStats!==void 0&&(t.computePerTestStats=e.computePerTestStats),e.sectorCount!==void 0&&(t.sectorCount=e.sectorCount),e.testNumbers!==void 0&&(t.testNumbers=[...e.testNumbers]),t}function It(e,t,s,o,n){const i=new Map;for(let m=0;m<t.length;m++)for(const g of Q(t[m].dies))i.set(g,m);const r=t.length,a=[],u=[];for(const m of e){const g=i.get(ve(m));g!==void 0&&(a.push(m),u.push(g))}const l=[],d=new Float64Array(r),f=new Float64Array(r),p=new Float64Array(r);for(const m of s){d.fill(0),f.fill(0),p.fill(0);let g=0,S=0,F=0,k;for(let w=0;w<a.length;w++){const B=a[w],z=Y(B,m);if(z===void 0)continue;k===void 0&&(k=z);const b=z-k,$=u[w];d[$]+=1,f[$]+=b,p[$]+=b*b,g+=1,S+=b,F+=b*b}if(k!==void 0)for(let w=0;w<r;w++){const B=d[w],z=g-B;if(B<n.minimumSampleSize||z<n.minimumSampleSize)continue;const b=f[w]/B,M=(S-f[w])/z,v=b+k,R=M+k,C=B>1?Math.max(0,p[w]-B*b*b)/(B-1):0,x=z>1?Math.max(0,F-p[w]-z*M*M)/(z-1):0,{pValue:V,effectSize:N,delta:D,z:K}=welchFromStats(B,v,C,z,R,x),P=t[w],{label:O,unit:E,...U}=Lt(m,o),j=R!==0?D/Math.abs(R):void 0,G=se(P,{id:`test:${m}:${P.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"mean",index:m,label:O,unit:E,...U},comparison:{family:P.family,left:P.label,right:J(P.family)},effect:{direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:j,effectSize:N},stats:{method:"welch-z-approx",pValue:V,sampleSizeLeft:B,sampleSizeRight:z},summary:Be(P.label,O,D,j,P.family,E),highlight:{kind:"region",regionFamily:P.family,regionKeys:[P.key],dieKeys:[...P.dieKeys]}}),y={n:B,sum:f[w],sq:p[w],restN:z,restSum:S-f[w],restSq:F-p[w],shift:k};xe.set(G,y),Qe(G,K,void 0,y),l.push(G)}}adjustPValues(l);const c=l.filter(m=>{const g=m.stats.adjustedPValue??m.stats.pValue??1,S=Math.abs(m.effect.effectSize??0);return g<=n.significanceLevel&&S>=n.minimumEffectSize}),h=confirmRegionalFindings(c,Xe,(m,g)=>jt(m,g,n));return c.filter(m=>h.has(m)).map(m=>({...m,severity:severityForScore(m.stats.adjustedPValue??m.stats.pValue??1,m.effect.effectSize??0)}))}function Wt(e,t,s,o){if(!s?.length)return[];const n=s.filter(r=>X(r)&&(r.limitLow!==void 0||r.limitHigh!==void 0));if(!n.length)return[];const i=[];for(const r of n){const a=r.testNumber;for(const u of t){const l=pe(e,u),d=[],f=new Map;let p=0,c=0;for(const[h,m]of l){let g=0,S=0;for(const F of m){const k=Y(F,a);k!==void 0&&(g++,Re(de(k,r))&&S++)}f.set(h,{valid:g,fail:S}),p+=g,c+=S}for(const h of u){const m=f.get(h.key),g=m.valid,S=p-m.valid;if(g<o.minimumSampleSize||S<o.minimumSampleSize)continue;const F=m.fail,k=c-m.fail,w=F/g,B=k/S,z=w-B,{pValue:b,method:$}=T(F,g,k,S);d.push(he(se(h,{id:`specLimit:${a}:${h.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"limitFailRate",index:a,label:I(r,a),...ce(r)},comparison:{family:h.family,left:h.label,right:J(h.family)},effect:{direction:z===0?"different":z>0?"higher":"lower",absoluteDelta:z,relativeDelta:B===0?void 0:z/B,effectSize:z},stats:{method:$,pValue:b,sampleSizeLeft:g,sampleSizeRight:S},summary:Fe(h.label,I(r,a),z),highlight:{kind:"region",regionFamily:h.family,regionKeys:[h.key],dieKeys:[...h.dieKeys]}}),{hits:F,n:g,restHits:k,restN:S,passRate:!1}))}i.push(...d)}}return i}function Pe(e,t){return e==="softBin"?t.softEligibleDies:e==="test"?t.testDies:t.eligibleDies}function Yt(e){return e.variable.measure==="limitFailRate"}function fe(e){return e.highlight.regionKeys??[]}function _t(e){const t=e.variable.bin??e.variable.index??"";return`${e.comparison.family}\0${et(e)}\0${e.variable.kind}\0${t}\0${e.effect.direction}`}function Qt(e,t){const s=Z(e);return s.family==="ring"?s.ring??0:s.family==="sector"?Le(t).indexOf(s.sector??""):0}export function inQuadrantOrder(e){const t=new Set(e),s=we.findIndex((n,i)=>t.has(n)&&!t.has(we[(i+3)%4])),o=s<0?0:s;return Array.from({length:4},(n,i)=>we[(o+i)%4]).filter(n=>t.has(n))}export function findContiguousRuns(e,t,s,o){if(t==="quadrant"){const u=new Map;for(const p of e){const c=Z(o(p)).quadrant;c&&u.set(c,p)}const l=[...u.keys()],d=new Set,f=[];for(const p of l){if(d.has(p))continue;const c=[],h=[p];for(d.add(p);h.length;){const m=h.pop();c.push(m);for(const g of l)!d.has(g)&&bt(m,g)&&(d.add(g),h.push(g))}f.push(inQuadrantOrder(c).map(m=>u.get(m)))}return f}const n=u=>Qt(o(u),s),i=[...e].sort((u,l)=>n(u)-n(l)),r=[];let a=[];for(const u of i){if(a.length===0){a.push(u);continue}const l=n(a[a.length-1]);n(u)-l===1?a.push(u):(r.push(a),a=[u])}if(a.length&&r.push(a),t==="sector"&&r.length>1){const l=Le(s).length,d=n(r[0][0]),f=n(r[r.length-1][r[r.length-1].length-1]);if(d===0&&f===l-1){const p=r.pop();r[0]=[...p,...r[0]]}}return r}export function mergedRegionLabel(e,t,s){if(e==="ring"){const n=t.map(u=>Z(u).ring).filter(u=>u!==void 0).sort((u,l)=>u-l),i=n[0],r=n[n.length-1];let a="";return i===r&&i===1&&s>1?a=" (core)":i===r&&i===s&&s>1&&(a=" (edge)"),i===r?`Ring ${i}${a}`:`Rings ${i}\u2013${r}`}if(e==="sector"){const n=t.map(i=>Z(i).sector??"");return n.length===1?`Sector ${n[0]}`:`Sectors ${n[0]}\u2013${n[n.length-1]}`}const o=t.map(n=>Z(n).quadrant??"");return o.length===1?o[0]:o.length===2?`Quadrants ${o[0]} & ${o[1]}`:`Quadrants ${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function Ne(e){return[...new Set(e)]}export function weakestMultiplier(e){return Ft(e.map(t=>{const s=t.stats.pValue??1;return s>0?(t.stats.adjustedPValue??s)/s:1}))}function te(e,t){return Math.min(1,e*t)}function Ut(e,t){const s=e[0],o=s.comparison.family,n=s.variable.kind,i=Ne(e.flatMap(fe));let r,a;const u=e.map(Ue);if(u.every(b=>b!==void 0)){const b=new Set;r=[];for(const M of u){const v=Q(M.dies);for(let R=0;R<v.length;R++)b.has(v[R])||(b.add(v[R]),r.push(M.dieKeys[R]))}const $=Q(Pe(s.variable.kind,t));a=M=>b.has($[M])}else{r=Ne(e.flatMap(M=>M.highlight.dieKeys??[]));const b=new Set(r),$=At(Pe(s.variable.kind,t));a=M=>b.has($[M])}const l=mergedRegionLabel(o,e.map(b=>fe(b)[0]??""),t.ringCount),d=Pe(n,t),f=t.regionDies[o],p=Q(d),c=[],h=[];for(let b=0;b<d.length;b++)f.has(p[b])&&(a(b)?c:h).push(d[b]);const m=weakestMultiplier(e);let g,S,F,k,w;if(Yt(s)){const b=s.variable.index,$=t.testDefs?.find(P=>P.testNumber===b),M=P=>{let O=0,E=0;for(const U of P){const j=Y(U,b);j!==void 0&&(O++,$&&Re(de(j,$))&&E++)}return{valid:O,fail:E}},v=M(c),R=M(h),C=v.valid>0?v.fail/v.valid:0,x=R.valid>0?R.fail/R.valid:0,V=C-x,{pValue:N,method:D}=T(v.fail,v.valid,R.fail,R.valid);g={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:x===0?void 0:V/x,effectSize:V},S={method:D,pValue:N,sampleSizeLeft:v.valid,sampleSizeRight:R.valid};const K=te(N,m);F=severityForFinding(K,V,rateRelativeEffect({hits:v.fail,n:v.valid,restHits:R.fail,restN:R.valid,passRate:!1})),k=Fe(l,I($,b),V),w=`specLimit:${b}`}else if(n==="test"){const b=s.variable.index,$=K=>Y(K,b),M=c.map($).filter(K=>K!==void 0),v=h.map($).filter(K=>K!==void 0),{pValue:R,effectSize:C,delta:x}=Ht(M,v),V=ue(v),N=V!==0?x/Math.abs(V):void 0;g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:N,effectSize:C},S={method:"welch-z-approx",pValue:R,sampleSizeLeft:M.length,sampleSizeRight:v.length};const D=te(R,m);F=severityForScore(D,C),k=Be(l,s.variable.label,x,N,o,s.variable.unit),w=`test:${b}`}else if(n==="yield"){const b=new Set(t.passBins),$=c.filter(E=>E.hbin!==void 0),M=h.filter(E=>E.hbin!==void 0),v=$.length,R=M.length,C=$.filter(E=>b.has(E.hbin)).length,x=M.filter(E=>b.has(E.hbin)).length,V=v>0?C/v:0,N=R>0?x/R:0,D=V-N,{pValue:K,method:P}=T(C,v,x,R);g={direction:D===0?"different":D>0?"higher":"lower",absoluteDelta:D,relativeDelta:N===0?void 0:D/N,effectSize:D},S={method:P,pValue:K,sampleSizeLeft:v,sampleSizeRight:R};const O=te(K,m);F=severityForFinding(O,D,rateRelativeEffect({hits:C,n:v,restHits:x,restN:R,passRate:!0})),k=ke(l,D,o),w="yield"}else if(n==="functionalTest"){const b=s.variable.index,$=t.testDefs?.find(O=>O.testNumber===b);let M=0,v=0,R=0,C=0;for(const O of c){const E=le(O,b,$);E!==void 0&&(v++,E&&M++)}for(const O of h){const E=le(O,b,$);E!==void 0&&(C++,E&&R++)}const x=v>0?M/v:0,V=C>0?R/C:0,N=x-V,{pValue:D,method:K}=T(M,v,R,C);g={direction:N===0?"different":N>0?"higher":"lower",absoluteDelta:N,relativeDelta:V===0?void 0:N/V,effectSize:N},S={method:K,pValue:D,sampleSizeLeft:v,sampleSizeRight:C};const P=te(D,m);F=severityForFinding(P,N,rateRelativeEffect({hits:M,n:v,restHits:R,restN:C,passRate:!0})),k=ze(l,I($,b),N,o),w=`functional:${b}`}else{const b=s.variable.bin,$=P=>n==="softBin"?P.sbin:P.hbin,M=c.filter(P=>$(P)===b).length,v=h.filter(P=>$(P)===b).length,R=M/c.length,C=v/h.length,x=R-C,{pValue:V,method:N}=T(M,c.length,v,h.length);g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:C===0?void 0:x/C,effectSize:x},S={method:N,pValue:V,sampleSizeLeft:c.length,sampleSizeRight:h.length};const D=te(V,m);F=severityForFinding(D,x,rateRelativeEffect({hits:M,n:c.length,restHits:v,restN:h.length,passRate:!1}));const K=n==="softBin"?t.sbinDefs:t.hbinDefs;k=De(l,He(b,K,n==="softBin"?"SBin":"HBin"),x,o),w=`${n}:${b}`}S={...S,adjustedPValue:te(S.pValue??1,m)};const B=Ne(i.map(b=>b.replace(`${o}:`,""))).join("-"),z=n==="hardBin"||n==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:i,dieKeys:r}:{kind:"region",regionFamily:o,regionKeys:i,dieKeys:r};return{...s,id:`${w}:${o}:${B}`,severity:F,comparison:{family:o,left:l,right:J(o)},effect:g,stats:S,summary:k,highlight:z,relatedIds:e.map(b=>b.id)}}function Gt(e,t){const s=new Set(["ring","quadrant","sector"]),o=[],n=new Map;for(const r of e){if(!s.has(r.comparison.family)){o.push(r);continue}const a=_t(r),u=n.get(a)??[];u.push(r),n.set(a,u)}const i=[];for(const r of n.values()){if(r.length===1){i.push(r[0]);continue}const a=r[0].comparison.family;for(const u of findContiguousRuns(r,a,t.sectorCount,l=>fe(l)[0]??""))i.push(u.length===1?u[0]:Ut(u,t))}return[...o,...i]}function Xt(e){const t=new Map,s=new Map;for(const n of e){const i=ve(n);n.hbin!==void 0&&n.hbin!==null&&(t.get(n.hbin)??t.set(n.hbin,new Set).get(n.hbin)).add(i),n.sbin!==void 0&&n.sbin!==null&&(s.get(n.sbin)??s.set(n.sbin,new Set).get(n.sbin)).add(i)}const o=new Set;for(const[n,i]of t)for(const[r,a]of s){if(i.size!==a.size)continue;let u=!0;for(const l of i)if(!a.has(l)){u=!1;break}u&&o.add(`${n}:${r}`)}return o}function Zt(e,t){const s=new Set(t);let o;for(const n of e){const i=be(n,s);if(i!==void 0&&i){if(n.sbin==null||o!==void 0&&n.sbin!==o)return;o=n.sbin}}if(o!==void 0){for(const n of e)if(n.sbin===o&&be(n,s)!==!0)return;return o}}function Jt(e){return`${e.comparison.family}\0${e.comparison.left}`}export function redundancyFacts(e,t,s){return{coincident:Xt(e),yieldSoftBin:Zt(e,t),passBins:t,sectorCount:s}}const en=3/5;function et(e){return/^(?:lot-region:)?([^:|]+)/.exec(e.id)?.[1]??e.id}function tn(e){const t=fe(e);if(t.length)return t;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(e.id);return s?s[2].split("-").map(o=>`${s[1]}:${o}`):[]}function tt(e,t){const s=new Set;for(const o of tn(e)){const n=yt(o,t);if(!n)return;for(const i of n)s.add(i)}return s.size?s:void 0}export function collapseRedundantFindings(e,t){const{coincident:s,yieldSoftBin:o,passBins:n}=t,i=(l,d)=>{l.absorbedIds=[...l.absorbedIds??[],d.id]},r=new Map;for(const l of e){const d=Jt(l);(r.get(d)??r.set(d,[]).get(d)).push(l)}const a=new Set;for(const l of r.values()){for(const f of l)if(!(f.variable.kind!=="hardBin"||f.variable.bin===void 0))for(const p of l){if(p.variable.kind!=="softBin"||p.variable.bin===void 0||a.has(p.id)||!s.has(`${f.variable.bin}:${p.variable.bin}`)||p.effect.direction!==f.effect.direction)continue;i(f,p),a.add(p.id);const c=f.variable.label.replace(/^HBin\s+/,""),h=p.variable.label.replace(/^SBin\s+/,""),m=c===h?`HBin and SBin ${c} (same dies)`:`${f.variable.label} and ${p.variable.label} (same dies)`;f.summary=f.summary.replace(f.variable.label,m),f.variable.label=m;break}const d=l.find(f=>f.variable.kind==="yield");if(d){for(const f of l)if(!(f===d||a.has(f.id)||!(f.variable.kind==="hardBin"&&n.length===1&&f.variable.bin===n[0]||f.variable.kind==="softBin"&&f.variable.bin===o))){i(d,f),a.add(f.id);for(const c of f.absorbedIds??[])d.absorbedIds=[...d.absorbedIds??[],c]}}}const u=new Map;for(const l of e){if(a.has(l.id)||l.comparison.family!=="sector"&&l.comparison.family!=="quadrant")continue;const d=[et(l),l.variable.kind,l.variable.bin??"",l.variable.index??"",l.effect.direction].join("\0");(u.get(d)??u.set(d,[]).get(d)).push(l)}for(const l of u.values()){const d=[];for(const f of l.filter(p=>p.comparison.family==="sector")){const p=tt(f,t.sectorCount);if(p)for(const c of l.filter(h=>h.comparison.family==="quadrant")){const h=tt(c,t.sectorCount);if(!h)continue;let m=0;for(const S of p)h.has(S)&&m++;const g=p.size+h.size-m;m/g>=en-1e-9&&d.push({sector:f,quadrant:c,overlap:m/g})}}d.sort((f,p)=>p.overlap-f.overlap);for(const{sector:f,quadrant:p}of d){if(a.has(f.id)||a.has(p.id))continue;const c=(p.stats.pValue??1)<(f.stats.pValue??1),[h,m]=c?[p,f]:[f,p];i(h,m),a.add(m.id),h.absorbedIds=[...h.absorbedIds??[],...m.absorbedIds??[]]}}}export function analyzeWaferMap(e,t={}){return analyzeWaferMapDecided(e,t)}export function analyzeWaferMapDecided(e,t={},s){const o=ee,n=oe,i=[];ee=i,oe=void 0;try{const r=nn(e,t,s);return _e.set(r,{candidates:i,facts:oe}),r}finally{ee=o,oe=n}}function nn(e,t,s){const{resolved:o,warnings:n}=resolveOptions(t),i=st(e),r={...o,passBins:[...kt(i,"analyzeWaferMap")],ringCount:Mt(i,"analyzeWaferMap")},a=i.isLotStack,u=i.aggrMethod,l=ut(a,u),d=l,f=i.dies.filter(y=>Te(y)),p=f.filter(Ke),c=Pt(r,f.length);c.softPassBins=Ee(f,c.passBins).soft;const h=Je(f,c.testNumbers,i.testDefs),m=c.enableTestValueAnalysis,g=m===!1?"off":m===!0?"done":s??ot(h.length*f.length),S=i.dies.filter(y=>ye(y)),F=S.filter(Ke),k=l?f.filter(y=>y.sbin!==void 0):[],w=d&&f.some(y=>y.hbin!==void 0)||k.length>0||m!==!1,B=w?ht(F,i.wafer,c.ringCount):[],z=w?dt(F,i.wafer,c.ringCount):[],b=w?mt(F,i.reticleConfig):[],$=w?gt(S,!1):[],M=w?pt(F,i.wafer,c.sectorCount):[],v=[],R=[];d&&R.push(...ae(f,B,c.passBins,c),...ae(f,z,c.passBins,c),...ae(f,b,c.passBins,c),...ae(f,$,c.passBins,c),...ae(f,M,c.passBins,c)),d&&R.push(...q(f,B,"hard",i.hbinDefs,"hardBin",c),...q(f,z,"hard",i.hbinDefs,"hardBin",c),...q(f,b,"hard",i.hbinDefs,"hardBin",c),...q(f,$,"hard",i.hbinDefs,"hardBin",c),...q(f,M,"hard",i.hbinDefs,"hardBin",c));{const y=k;R.push(...q(y,B,"soft",i.sbinDefs,"softBin",c),...q(y,z,"soft",i.sbinDefs,"softBin",c),...q(y,b,"soft",i.sbinDefs,"softBin",c),...q(y,$,"soft",i.sbinDefs,"softBin",c),...q(y,M,"soft",i.sbinDefs,"softBin",c))}const C=[...n];let x;if(m!==!1){if(g==="done"){for(const y of[B,z,b,$,M])v.push(...It(f,y,h,i.testDefs,c));x=h}R.push(...Wt(f,[B,z,b,$,M],i.testDefs,c)),R.push(...re(f,B,i.testDefs,c),...re(f,z,i.testDefs,c),...re(f,b,i.testDefs,c),...re(f,$,i.testDefs,c),...re(f,M,i.testDefs,c))}v.push(...qt(R,c));{const y=Nt(a,d,i.testDefs);(!a||d||y!==void 0)&&v.push(...St(p,i.wafer,{...c,isFailingDie:y}))}const V=Gt(v,{eligibleDies:f,softEligibleDies:k,testDies:f,passBins:c.passBins,ringCount:c.ringCount,sectorCount:c.sectorCount,regionDies:{ring:new Set(B.flatMap(y=>Q(y.dies))),quadrant:new Set(z.flatMap(y=>Q(y.dies))),sector:new Set(M.flatMap(y=>Q(y.dies)))},hbinDefs:i.hbinDefs,sbinDefs:i.sbinDefs,testDefs:i.testDefs});v.length=0,v.push(...V);let N;if(d){const y=vt(p,i.wafer,{passBins:c.passBins,ringCount:c.ringCount});if(N=y??void 0,y!==null&&y.pattern!=="random"&&y.pattern!=="none"){const L=Rt[y.pattern],H=y.confidence==="high"?"unusual":y.confidence==="medium"?"notable":"info",A=y.features,ne=W=>`${(W*100).toFixed(0)}%`,nt=y.pattern==="edge-ring"||y.pattern==="edge-local"?`${ne(A.edgeRdd)} of edge dies failing`:y.pattern==="center"?`centroid at ${ne(A.centroidDistNorm)} of wafer radius from centre`:y.pattern==="donut"?`${ne(Math.max(A.radialFailRates[1],A.radialFailRates[2]))} of dies failing at mid-radius, ${ne(A.radialFailRates[0])} at the centre`:y.pattern==="scratch"?`a line ${Math.round(A.lineLength)} dies long and about ${Math.max(1,Math.round(A.lineWidth*2))} wide`:`${ne(A.globalRdd)} of dies failing`,it=new Set(c.passBins),Ce=f.filter(W=>$t(W,it)===!0),Ve=claimForPattern([y.pattern],H,v,W=>fe(W).map(ge=>Z(ge).ring).filter(ge=>ge!==void 0),c.ringCount);v.push({id:`spatial-pattern:${y.pattern}`,level:"wafer",severity:H,variable:{kind:"spatialPattern",label:L},comparison:{family:"spatial-pattern",left:L,right:"Wafer"},effect:{direction:"different",effectSize:A.globalRdd},stats:{method:"geometry",sampleSizeLeft:Ce.length,sampleSizeRight:f.length},summary:`Spatial pattern: ${L.toLowerCase()} (${y.confidence} confidence) \u2014 ${nt}${y.note?` [${y.note}]`:""}`,highlight:{kind:"dies",dieKeys:Ce.map(W=>Se(W))},relatedIds:Ve.length>0?Ve:void 0})}}v.sort((y,L)=>{const H=y.stats.adjustedPValue??y.stats.pValue??1,A=L.stats.adjustedPValue??L.stats.pValue??1;return H!==A?H-A:Math.abs(L.effect.absoluteDelta??0)-Math.abs(y.effect.absoluteDelta??0)});const D=Ct(i.dies,f.length,i.yield.yieldPercent);a&&(D.isLotStack=!0,u&&(D.aggregationMethod=u));const K=new Set(r.passBins),P={},O=(y,L)=>{const H=P[y]??={dieKeys:[],lostDies:0};H.dieKeys.push(Se(L)),be(L,K)!==!0&&H.lostDies++},E=Vt(i.dies,i.testDefs,O);E&&(D.testSpecYield=E);const U=computeFunctionalYield(i.dies,i.testDefs,O);if(U&&(D.functionalYield=U),Object.keys(P).length&&(D.testFailures=P),N&&(D.spatialPattern=N),x===void 0&&c.computePerTestStats&&(x=h),h.length&&(D.testValueAnalysis=at(g,h.length,f.length)),x?.length){const y=Et(i.dies,x,i.testDefs,c.minimumSampleSize);y&&(D.perTestStats=y);const L=rt([{dies:i.dies}],i.testDefs,x);L&&(D.capability=L)}Object.assign(D,ft(i.dies,i.testDefs));const j=lt([{dies:i.dies,wafer:i.wafer,passBins:c.passBins,ringCount:c.ringCount}]);j&&(D.regionYield=j),C.length>0&&(D.warnings=C);const G=redundancyFacts(f,c.passBins,c.sectorCount);return collapseRedundantFindings(v,G),ee&&(oe=G),{level:"wafer",hasNotableFindings:v.some(y=>y.severity==="notable"||y.severity==="unusual"),findings:v,wafer:i.wafer.metadata??void 0,analysisOptions:recordedOptions(t),stats:D}}
1
+ import{normalizeInput as dt}from"./normalizeInput.js";import{autoDecision as mt,testValueStatus as ht}from"./testValueBudget.js";import{computeCapability as pt,computeTestFlagYield as gt,computeRegionYield as bt}from"./summaryFigures.js";import{binPassSets as Ke}from"../renderer/binColors.js";import{diePassStatus as oe,isYieldEligibleDie as X,getDieKey as de,isPositionedDie as Ae,positionKey as we}from"../core/dies.js";import{dieHasValues as yt,testsPresent as Te,testValue as W}from"../core/dieTable.js";import{stackBinsAreData as St}from"../core/aggregates.js";import{getTestPassStatus as me,isParametricTest as Z}from"../renderer/buildWaferMap.js";import{markedTestLabel as I,derivedFields as he}from"../renderer/testLabel.js";import{buildQuadrantRegions as vt,buildReticlePositionRegions as wt,buildRingRegions as $t,buildSectorRegions as Rt,buildTestSiteRegions as Dt,sectorCompassNames as qe,areQuadrantsAdjacent as Mt,parseRegionKey as J,QUADRANT_CYCLE as $e,regionAngleBins as kt}from"./regions.js";import{buildClusterFindings as Ie}from"./clusterDetection.js";import{classifyPattern as zt,patternExplains as Bt,patternFailVerdict as Ft,PATTERN_LABELS as Ct}from"./patternClassification.js";import{requirePassBins as Nt}from"../core/passBins.js";import{requireRingCount as xt}from"../core/ringCount.js";import{benjaminiHochberg as Pt,fisherExact as Vt,fiveNumberSummary as Et,sampleVariance as Re,zPValue as je}from"./math.js";import{mean as pe,maxOf as Lt}from"../core/utils.js";import{classifySpec as ge,isOutOfSpec as De}from"../renderer/spec.js";import{ringOf as Ot}from"../core/classify.js";import{SEVERITY_ORDER as He,isOneBinCluster as _e}from"./filterFindings.js";const Kt={significanceLevel:{min:1e-6,max:1},minimumEffectSize:{min:0,max:1},minimumRelativeEffect:{min:0,max:Number.MAX_SAFE_INTEGER}},We=[4,8,16];export function resolveOptions(e){const t=Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0)),s={...ae,...t},o=[],i=[];for(const a of["significanceLevel","minimumEffectSize","minimumRelativeEffect"]){const{min:p,max:r}=Kt[a],u=s[a];if(typeof u!="number"||!Number.isFinite(u)){i.push(`${a}=${String(u)} is not a finite number (using ${ae[a]})`),s[a]=ae[a];continue}const c=Math.min(r,Math.max(p,u));c!==u&&(i.push(`${a}=${u} is outside ${p}\u2013${r} (using ${c})`),s[a]=c)}if(We.includes(s.sectorCount)||(i.push(`sectorCount=${s.sectorCount} is not one of ${We.join(", ")} (using ${ae.sectorCount})`),s.sectorCount=ae.sectorCount),i.length){const a=`analyzeWaferMap: ${i.join("; ")}. The analysis ran with the corrected values.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const n=["passBins","ringCount"].filter(a=>t[a]!==void 0);if(n.length){const a=`analyzeWaferMap: ${n.join(" and ")} ${n.length>1?"are":"is"} no longer an analysis option and was ignored. Set ${n.length>1?"them":"it"} on buildWaferMap; the analysis used the value the map was built with.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}const f=["enableYieldAnalysis","enableHardBinAnalysis","enableSoftBinAnalysis","enableReticlePositionAnalysis","enableTestSiteAnalysis","enableClusterAnalysis","enableAngularAnalysis","enablePatternClassification"].filter(a=>t[a]!==void 0);if(f.length){const a=`analyzeWaferMap: ${f.join(", ")} ${f.length>1?"are":"is"} no longer an option and was ignored: every analysis now runs. Filter the findings (filterFindings) to show fewer.`;console.warn(`[wafermap] ${a}`),o.push({code:"analysis-option-corrected",message:a,severity:"warning"})}return{resolved:s,warnings:o}}const ae={significanceLevel:.05,minimumEffectSize:.2,minimumRelativeEffect:1,minimumSampleSize:5,enableTestValueAnalysis:"auto",computePerTestStats:!1,sectorCount:8,minimumClusterSize:5};function At(e,t){const s={...e};return s.minimumClusterSize=Math.max(5,Math.round(t*.003)),s}function Ye(e){return X(e)?e.hbin!==void 0||e.sbin!==void 0||yt(e):!1}function Tt(e,t,s){if(!e||t)return;const o=(s??[]).filter(i=>Z(i)&&(i.limitLow!==void 0||i.limitHigh!==void 0));if(o.length!==0)return i=>{for(const n of o)if(De(ge(W(i,n.testNumber),n)))return!0;return!1}}const qt=8,It=.8,jt=.8,Ht=.5;function _t(e,t,s,o,i){const n=new Set(o.passBins),f=e.filter(m=>oe(m,n)!==void 0),a=new Map;let p=0;for(const m of f)oe(m,n)||(p++,m.hbin!==void 0&&a.set(m.hbin,(a.get(m.hbin)??0)+1));const r=[...a].filter(([,m])=>m>=o.minimumClusterSize&&m<=It*p).sort((m,l)=>l[1]-m[1]||m[0]-l[0]).slice(0,qt).map(([m])=>m);if(!r.length)return[];const u=i.filter(m=>m.comparison.family==="cluster").map(be),c=[];for(const m of r){const l=Ie(f,t,{...o,significanceLevel:o.significanceLevel/r.length,isFailingDie:d=>d.hbin===m,bin:{bin:m,label:Ce(m,s,"HBin")}});c.push(...l.filter(d=>!u.some(h=>Yt(be(d),h))))}return c}const Wt=.5;export function claimForBinClusters(e){const t=e.filter(s=>(s.comparison.family==="ring"||s.comparison.family==="quadrant"||s.comparison.family==="sector")&&s.variable.kind==="hardBin"&&s.effect.direction==="higher");for(const s of e){if(!_e(s))continue;const o=be(s),i=t.filter(n=>{if(n.variable.bin!==s.variable.bin||He[n.severity]<He[s.severity])return!1;const f=(n.effect.absoluteDelta??0)*n.stats.sampleSizeLeft;let a=0;for(const p of be(n))o.has(p)&&a++;return f>0&&a>=Wt*f});if(s.severity!=="info")for(const n of i)n.severity="info";i.length&&(s.relatedIds=i.map(n=>n.id))}}function be(e){return new Set("dieKeys"in e.highlight?e.highlight.dieKeys??[]:[])}function Yt(e,t){let s=0;for(const o of e)t.has(o)&&s++;return s>=jt*e.size&&e.size>=Ht*t.size}function Ut(e,t,s,o){const i=new Set,n=new Set,f=new Set,a=new Map,p=new Map;for(const r of Te(e))i.add(r);for(const r of o?e:[])r.hbin!==void 0&&n.add(r.hbin),r.sbin!==void 0&&f.add(r.sbin),X(r)&&(r.hbin!==void 0&&a.set(r.hbin,(a.get(r.hbin)??0)+1),r.sbin!==void 0&&p.set(r.sbin,(p.get(r.sbin)??0)+1));return{totalDies:e.length,analyzedDies:t,excludedDies:e.length-t,yieldPercent:s,testsConsidered:[...i].sort((r,u)=>r-u),hardBinsConsidered:[...n].sort((r,u)=>r-u),softBinsConsidered:[...f].sort((r,u)=>r-u),...a.size?{hardBinCounts:Object.fromEntries(a)}:{},...p.size?{softBinCounts:Object.fromEntries(p)}:{}}}function Qt(e,t,s){if(!t?.length)return;const o=t.filter(n=>Z(n)&&(n.limitLow!==void 0||n.limitHigh!==void 0));if(!o.length)return;const i=[];for(const n of o){const f=n.testNumber;let a=0,p=0,r=0,u=0;for(const c of e){if(!X(c))continue;const m=ge(W(c,f),n);if(m!==null){if(u++,m==="failLow")p++;else if(m==="failHigh")r++;else{a++;continue}s?.(f,c)}}i.push({testNumber:f,label:I(n,f),passDies:a,failLowDies:p,failHighDies:r,totalDies:u,yieldPercent:u>0?a/u*100:null})}return i.length?i:void 0}export function computeFunctionalYield(e,t,s){if(!t?.length)return;const o=t.filter(n=>!Z(n));if(!o.length)return;const i=[];for(const n of o){const f=n.testNumber;let a=0,p=0;for(const u of e){if(!X(u))continue;const c=me(u,f,n);if(c!==void 0){if(c){a++;continue}p++,s?.(f,u)}}const r=a+p;i.push({testNumber:f,label:I(n,f),...he(n),passDies:a,failDies:p,totalDies:r,passRatePercent:r>0?a/r*100:null})}return i.length?i:void 0}function Gt(e,t,s,o){const i=[];for(const n of t){const f=[];for(const c of e){if(!X(c))continue;const m=W(c,n);m!==void 0&&Number.isFinite(m)&&f.push(m)}if(f.length<o)continue;const a=pe(f),p=Math.sqrt(Re(f,a)),r=Et(Float64Array.from(f)),u=s?.find(c=>c.testNumber===n)?.name??String(n);i.push({testNumber:n,label:u,count:f.length,min:r.min,max:r.max,mean:a,stddev:p,median:r.median,q1:r.q1,q3:r.q3})}return i.length?i:void 0}export function twoProportionZ(e,t,s,o){const i=(e+s)/(t+o),n=i*(1-i)*(1/t+1/o);return!Number.isFinite(n)||n<=0?0:(e/t-s/o)/Math.sqrt(n)}const Xt=5;function j(e,t,s,o){const i=t+o,n=e+s;if((i>0?Math.min(n,i-n)*Math.min(t,o)/i:0)<Xt)return{pValue:Vt(e,t-e,s,o-s),method:"fisher-exact"};const a=twoProportionZ(e,t,s,o);return{pValue:a===0?1:je(a),method:"two-proportion-z"}}function Zt(e,t,s,o){return j(e,t,s,o).pValue}export function adjustPValues(e){const t=e.filter(o=>o.stats.pValue!==void 0),s=Pt(t.map(o=>o.stats.pValue));return t.forEach((o,i)=>{o.stats.adjustedPValue=s[i]}),e}export function rateRelativeEffect(e){const t=(e.passRate?e.n-e.hits:e.hits)/e.n,s=(e.passRate?e.restN-e.restHits:e.restHits)/e.restN;return s===0?t===0?0:1/0:Math.abs(t-s)/s}export function severityForFinding(e,t,s){const o=Math.abs(t),i=s;return e<=.01&&(o>=.3||i>=2.5)?"unusual":e<=.05&&(o>=.2||i>=1.5)?"notable":"info"}export function severityForScore(e,t){return e<=.01&&Math.abs(t)>=.5?"unusual":e<=.05&&Math.abs(t)>=.15?"notable":"info"}function ye(e){return e==="reticle-position"?"other reticle positions":e==="test-site"?"other test sites":"the rest of the map"}function ee(e){return e==="reticle-position"?"Other reticle positions":e==="test-site"?"Other test sites":"Rest of map"}function Me(e,t,s){const o=(Math.abs(t)*100).toFixed(1);return`${e} yield is ${o} percentage points ${t>0?"higher":"lower"} than ${ye(s)}`}function ke(e,t){return t==="quadrant"&&!e.startsWith("Quadrant")?`quadrant ${e}`:e}function Ue(e){return/^(Rings|Sectors|Quadrants)\b/.test(e)?"have":"has"}function ze(e,t,s,o){const i=ke(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Ue(i)} ${t} occurrence ${n} percentage points ${s>0?"higher":"lower"} than ${ye(o)}`}function Be(e,t,s,o){const i=ke(e,o),n=(Math.abs(s)*100).toFixed(1);return`${i} ${Ue(i)} ${t} pass rate ${n} percentage points ${s>0?"higher":"lower"} than ${ye(o)}`}function Fe(e,t,s,o,i,n){const f=ke(e,i),a=ye(i),p=s>0?"higher":"lower";if(o!==void 0&&Number.isFinite(o)){const u=(Math.abs(o)*100).toFixed(1);return`${f} mean ${t} is ${u}% ${p} than ${a}`}const r=n?` ${n}`:"";return`${f} mean ${t} is ${Math.abs(s).toPrecision(3)}${r} ${p} than ${a}`}function Ce(e,t,s){const o=t?.find(i=>i.bin===e);return o?.name?`${s} ${e} (${o.name})`:`${s} ${e}`}function Jt(e,t){const s=t?.find(o=>o.testNumber===e);return{label:I(s,e),unit:s?.unit,...he(s)}}const Qe=new WeakMap,Ge=new WeakMap,Xe=new WeakMap;function re(e,t){const s=t.highlight.dieKeys;return s&&Xe.set(s,e),t}let te=null,fe;const Ze=new WeakMap;export function candidatesOf(e){return Ze.get(e)}function Je(e,t,s,o){if(!te)return;const i=et(e);if(!i)return;const n=e.id.slice(0,e.id.indexOf(":")),f=n==="specLimit"?"limitFail":n,{kind:a,bin:p,index:r}=e.variable;te.push({key:[f,a,p??"",r??"",i.family,i.key].join("|"),source:f,variable:e.variable,label:e.variable.label,comparison:e.comparison,region:i,z:t,delta:e.effect.absoluteDelta??0,effectSize:e.effect.effectSize??0,relativeDelta:e.effect.relativeDelta,rate:s,mean:o})}export function describeRegional(e,t,s){const o=e.comparison.left,i=e.region.family;switch(e.source){case"yield":return Me(o,t,i);case"hardBin":case"softBin":return ze(o,e.label,t,i);case"functional":return Be(o,e.label.replace(/ pass rate$/,""),t,i);case"limitFail":return Ne(o,e.label,t);case"test":return Fe(o,e.label,t,s,i,e.variable.unit)}}function Ne(e,t,s){return`${e} limit fail rate for ${t} is ${(Math.abs(s)*100).toFixed(1)} pp ${s>0?"higher":"lower"} than the rest of the wafer`}const Y=new WeakMap;function Se(e,t){return Y.set(e,t),e}function et(e){const t=e.highlight.dieKeys;return t?Xe.get(t):void 0}const tt=new WeakMap;function U(e){let t=tt.get(e);return t||tt.set(e,t=e.map(we)),t}function en(e){let t=Qe.get(e);return t||Qe.set(e,t=e.map(de)),t}function ve(e,t){let s=Ge.get(e);s||Ge.set(e,s={members:new Set(e),byFamily:new WeakMap});const o=s.byFamily.get(t);if(o)return o;const{members:i}=s,n=new Map;for(const f of t)n.set(f.key,f.dies.filter(a=>i.has(a)));return s.byFamily.set(t,n),n}function tn(e,t){adjustPValues(e);for(const i of e){const n=Y.get(i);Je(i,twoProportionZ(n.hits,n.n,n.restHits,n.restN),n)}const s=e.filter(i=>passesRateGate(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(Y.get(i)),t)),o=confirmRegionalFindings(s,nt,(i,n)=>nn(i,n,t),i=>isRateLoss(Y.get(i)),e);return s.filter(i=>o.has(i)).map(i=>({...i,severity:severityForFinding(i.stats.adjustedPValue??i.stats.pValue??1,i.effect.absoluteDelta??0,rateRelativeEffect(Y.get(i)))}))}export function passesRateGate(e,t,s,o){return e<=o.significanceLevel&&(Math.abs(t)>=o.minimumEffectSize||s>=o.minimumRelativeEffect)}export function claimForPattern(e,t,s,o,i){const n=[];for(const f of s){const a=f.comparison.family,p=a==="ring"||a==="cluster"?o(f):[];e.some(r=>Bt(r,a,p,i))&&(n.push(f.id),t!=="info"&&(a==="ring"||a==="quadrant"||a==="sector")&&(f.severity="info"))}return n}export function confirmRegionalFindings(e,t,s,o,i=e){const n=new Map;for(const p of e)(n.get(t(p))??n.set(t(p),[]).get(t(p))).push(p);const f=new Map;if(o)for(const p of i)o(p)&&(f.get(t(p))??f.set(t(p),[]).get(t(p))).push(p);const a=new Set;for(const[p,r]of n){const u=f.get(p)??[],c=(d,h)=>o&&!o(d)?s(d,[...new Set([...h,...u])].filter(g=>g!==d)):s(d,h);if(r.length===1&&(!o||o(r[0])||u.length===0)){a.add(r[0]);continue}const m=[];let l=[...r];for(;;){let d;for(const h of l){const g=c(h,m);if(g==="baseline-too-small"||!g.passes)continue;const v=o?.(h)??!1;(!d||v&&!d.loss||v===d.loss&&g.pValue<d.p)&&(d={t:h,p:g.pValue,loss:v})}if(!d)break;m.push(d.t),l=l.filter(h=>h!==d.t)}for(;;){let d;for(const h of m){const g=c(h,m.filter(v=>v!==h));g==="baseline-too-small"||g.passes||(!d||g.pValue>d.p)&&(d={t:h,p:g.pValue})}if(!d)break;m.splice(m.indexOf(d.t),1)}for(const d of m)a.add(d)}return a}function nt(e){return[e.variable.kind,e.variable.bin??"",e.variable.index??"",e.comparison.family].join("\0")}function it(e){const t=e.stats.pValue??1;return t>0?(e.stats.adjustedPValue??t)/t:1}export function isRateLoss(e){const t=e.hits/e.n-e.restHits/e.restN;return e.passRate?t<0:t>0}function nn(e,t,s){const o=Y.get(e);let{restHits:i,restN:n}=o;for(const r of t){const u=Y.get(r);u&&(i-=u.hits,n-=u.n)}if(n<s.minimumSampleSize)return"baseline-too-small";const f=o.hits/o.n-i/n,a=Math.min(1,Zt(o.hits,o.n,i,n)*it(e)),p=Math.sign(f)===Math.sign(e.effect.absoluteDelta??0)&&passesRateGate(a,f,rateRelativeEffect({...o,restHits:i,restN:n}),s);return{pValue:a,passes:p}}const xe=new WeakMap;export function welchOfSums(e,t,s,o){const i=(n,f,a)=>a>1?Math.max(0,n-f*f/a)/(a-1):0;return welchFromStats(e.n,e.sum/e.n,i(e.sq,e.sum,e.n),t,s/t,i(o,s,t))}function sn(e,t,s){const o=xe.get(e);let{restN:i,restSum:n,restSq:f}=o;for(const m of t){const l=xe.get(m);l&&(i-=l.n,n-=l.sum,f-=l.sq)}if(i<s.minimumSampleSize)return"baseline-too-small";const{pValue:a,effectSize:p,delta:r}=welchOfSums(o,i,n,f),u=Math.min(1,a*it(e)),c=Math.sign(r)===Math.sign(e.effect.absoluteDelta??0)&&u<=s.significanceLevel&&Math.abs(p)>=s.minimumEffectSize;return{pValue:u,passes:c}}function le(e,t,s,o){const i=new Set(s),n=ve(e,t),f=new Map,a=new Map;for(const[r,u]of n){let c=0,m=0;for(const l of u)l.hbin!==void 0&&(m++,i.has(l.hbin)&&c++);f.set(r,c),a.set(r,m)}const p=[];for(const r of t){const u=a.get(r.key)??0,c=f.get(r.key)??0;let m=0,l=0;for(const[D,w]of a)D!==r.key&&(m+=w,l+=f.get(D)??0);if(u<o.minimumSampleSize||m<o.minimumSampleSize)continue;const d=c/u,h=l/m,g=d-h,{pValue:v,method:F}=j(c,u,l,m);p.push(Se(re(r,{id:`yield:${r.key}`,level:"wafer",severity:"info",variable:{kind:"yield",label:"Yield"},comparison:{family:r.family,left:r.label,right:ee(r.family)},effect:{direction:g===0?"different":g>0?"higher":"lower",absoluteDelta:g,relativeDelta:h===0?void 0:g/h,effectSize:g},stats:{method:F,pValue:v,sampleSizeLeft:u,sampleSizeRight:m},summary:Me(r.label,g,r.family),highlight:{kind:"region",regionFamily:r.family,regionKeys:[r.key],dieKeys:[...r.dieKeys]}}),{hits:c,n:u,restHits:l,restN:m,passRate:!0}))}return p}function q(e,t,s,o,i,n){const f=d=>s==="soft"?d.sbin:d.hbin,a=[...new Set(e.map(f).filter(d=>d!==void 0))].sort((d,h)=>d-h),p=ve(e,t),r=new Map,u=new Map;for(const[d,h]of p){const g=new Map;for(const v of h){const F=f(v);F!==void 0&&g.set(F,(g.get(F)??0)+1)}r.set(d,g),u.set(d,h.length)}const c=[],m=i==="hardBin"?"HBin":"SBin",l=s==="hard"?new Set(n.passBins):n.softPassBins??Ke(e,n.passBins).soft;for(const d of t){const h=u.get(d.key)??0,g=r.get(d.key);let v=0;const F=new Map;for(const[D,w]of r)if(D!==d.key){v+=u.get(D)??0;for(const[B,z]of w)F.set(B,(F.get(B)??0)+z)}if(!(h<n.minimumSampleSize||v<n.minimumSampleSize))for(const D of a){const w=g.get(D)??0,B=F.get(D)??0,z=w/h,b=B/v,$=z-b,{pValue:M,method:S}=j(w,h,B,v),R=Ce(D,o,m);c.push(Se(re(d,{id:`${i}:${D}:${d.key}`,level:"wafer",severity:"info",variable:{kind:i,bin:D,label:R},comparison:{family:d.family,left:d.label,right:ee(d.family)},effect:{direction:$===0?"different":$>0?"higher":"lower",absoluteDelta:$,relativeDelta:b===0?void 0:$/b,effectSize:$},stats:{method:S,pValue:M,sampleSizeLeft:h,sampleSizeRight:v},summary:ze(d.label,R,$,d.family),highlight:{kind:"bin",bin:D,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:w,n:h,restHits:B,restN:v,passRate:l.has(D)}))}}return c}function ce(e,t,s,o){const i=(s??[]).filter(u=>!Z(u));if(!i.length)return[];const n=i.map(u=>u.testNumber),f=ve(e,t),a=new Map,p=new Map;for(const[u,c]of f){const m=new Uint32Array(i.length),l=new Uint32Array(i.length);for(const d of c)for(let h=0;h<i.length;h++){const g=me(d,n[h],i[h]);g!==void 0&&(l[h]++,g&&m[h]++)}a.set(u,m),p.set(u,l)}const r=[];for(const u of t){const c=a.get(u.key),m=p.get(u.key);for(let l=0;l<i.length;l++){let d=0,h=0;for(const[$,M]of p)$!==u.key&&(h+=M[l],d+=a.get($)[l]);const g=m[l],v=c[l];if(g<o.minimumSampleSize||h<o.minimumSampleSize)continue;const F=v/g,D=d/h,w=F-D,{pValue:B,method:z}=j(v,g,d,h),b=n[l];r.push(Se(re(u,{id:`functional:${b}:${u.key}`,level:"wafer",severity:"info",variable:{kind:"functionalTest",index:b,label:`${I(i[l],b)} pass rate`,...he(i[l])},comparison:{family:u.family,left:u.label,right:ee(u.family)},effect:{direction:w===0?"different":w>0?"higher":"lower",absoluteDelta:w,relativeDelta:D===0?void 0:w/D,effectSize:w},stats:{method:z,pValue:B,sampleSizeLeft:g,sampleSizeRight:h},summary:Be(u.label,I(i[l],b),w,u.family),highlight:{kind:"region",regionFamily:u.family,regionKeys:[u.key],dieKeys:[...u.dieKeys]}}),{hits:v,n:g,restHits:d,restN:h,passRate:!0}))}}return r}export function welchFromStats(e,t,s,o,i,n){const f=Math.sqrt(s/e+n/o),a=t-i;if(!Number.isFinite(f)||f===0)return{pValue:1,effectSize:0,delta:a,z:0};const p=a/f,r=Math.sqrt(Math.max(0,(s+n)/2)),u=r===0?a:a/r;return{pValue:je(p),effectSize:u,delta:a,z:p}}function on(e,t){const s=pe(e),o=pe(t);return welchFromStats(e.length,s,Re(e,s),t.length,o,Re(t,o))}function st(e,t,s){const o=new Map;for(const n of s??[])o.has(n.testNumber)||o.set(n.testNumber,n);const i=n=>n.filter(f=>Z(o.get(f)));return i(t?t.slice().sort((n,f)=>n-f):Te(e,"values"))}export function testValueSize(e,t){const s=e.dies.filter(Ye);return{tests:st(s,t.testNumbers,e.testDefs).length,dies:s.length}}export function recordedOptions(e){const t={};return e.enableTestValueAnalysis!==void 0&&(t.enableTestValueAnalysis=e.enableTestValueAnalysis),e.computePerTestStats!==void 0&&(t.computePerTestStats=e.computePerTestStats),e.sectorCount!==void 0&&(t.sectorCount=e.sectorCount),e.testNumbers!==void 0&&(t.testNumbers=[...e.testNumbers]),t}function an(e,t,s,o,i){const n=new Map;for(let h=0;h<t.length;h++)for(const g of U(t[h].dies))n.set(g,h);const f=t.length,a=[],p=[];for(const h of e){const g=n.get(we(h));g!==void 0&&(a.push(h),p.push(g))}const r=[],u=new Float64Array(f),c=new Float64Array(f),m=new Float64Array(f);for(const h of s){u.fill(0),c.fill(0),m.fill(0);let g=0,v=0,F=0,D;for(let w=0;w<a.length;w++){const B=a[w],z=W(B,h);if(z===void 0)continue;D===void 0&&(D=z);const b=z-D,$=p[w];u[$]+=1,c[$]+=b,m[$]+=b*b,g+=1,v+=b,F+=b*b}if(D!==void 0)for(let w=0;w<f;w++){const B=u[w],z=g-B;if(B<i.minimumSampleSize||z<i.minimumSampleSize)continue;const b=c[w]/B,M=(v-c[w])/z,S=b+D,R=M+D,P=B>1?Math.max(0,m[w]-B*b*b)/(B-1):0,C=z>1?Math.max(0,F-m[w]-z*M*M)/(z-1):0,{pValue:V,effectSize:x,delta:k,z:O}=welchFromStats(B,S,P,z,R,C),N=t[w],{label:K,unit:E,...Q}=Jt(h,o),H=R!==0?k/Math.abs(R):void 0,G=re(N,{id:`test:${h}:${N.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"mean",index:h,label:K,unit:E,...Q},comparison:{family:N.family,left:N.label,right:ee(N.family)},effect:{direction:k===0?"different":k>0?"higher":"lower",absoluteDelta:k,relativeDelta:H,effectSize:x},stats:{method:"welch-z-approx",pValue:V,sampleSizeLeft:B,sampleSizeRight:z},summary:Fe(N.label,K,k,H,N.family,E),highlight:{kind:"region",regionFamily:N.family,regionKeys:[N.key],dieKeys:[...N.dieKeys]}}),y={n:B,sum:c[w],sq:m[w],restN:z,restSum:v-c[w],restSq:F-m[w],shift:D};xe.set(G,y),Je(G,O,void 0,y),r.push(G)}}adjustPValues(r);const l=r.filter(h=>{const g=h.stats.adjustedPValue??h.stats.pValue??1,v=Math.abs(h.effect.effectSize??0);return g<=i.significanceLevel&&v>=i.minimumEffectSize}),d=confirmRegionalFindings(l,nt,(h,g)=>sn(h,g,i));return l.filter(h=>d.has(h)).map(h=>({...h,severity:severityForScore(h.stats.adjustedPValue??h.stats.pValue??1,h.effect.effectSize??0)}))}function rn(e,t,s,o){if(!s?.length)return[];const i=s.filter(f=>Z(f)&&(f.limitLow!==void 0||f.limitHigh!==void 0));if(!i.length)return[];const n=[];for(const f of i){const a=f.testNumber;for(const p of t){const r=ve(e,p),u=[],c=new Map;let m=0,l=0;for(const[d,h]of r){let g=0,v=0;for(const F of h){const D=W(F,a);D!==void 0&&(g++,De(ge(D,f))&&v++)}c.set(d,{valid:g,fail:v}),m+=g,l+=v}for(const d of p){const h=c.get(d.key),g=h.valid,v=m-h.valid;if(g<o.minimumSampleSize||v<o.minimumSampleSize)continue;const F=h.fail,D=l-h.fail,w=F/g,B=D/v,z=w-B,{pValue:b,method:$}=j(F,g,D,v);u.push(Se(re(d,{id:`specLimit:${a}:${d.key}`,level:"wafer",severity:"info",variable:{kind:"test",measure:"limitFailRate",index:a,label:I(f,a),...he(f)},comparison:{family:d.family,left:d.label,right:ee(d.family)},effect:{direction:z===0?"different":z>0?"higher":"lower",absoluteDelta:z,relativeDelta:B===0?void 0:z/B,effectSize:z},stats:{method:$,pValue:b,sampleSizeLeft:g,sampleSizeRight:v},summary:Ne(d.label,I(f,a),z),highlight:{kind:"region",regionFamily:d.family,regionKeys:[d.key],dieKeys:[...d.dieKeys]}}),{hits:F,n:g,restHits:D,restN:v,passRate:!1}))}n.push(...u)}}return n}function Pe(e,t){return e==="softBin"?t.softEligibleDies:e==="test"?t.testDies:t.eligibleDies}function fn(e){return e.variable.measure==="limitFailRate"}function ue(e){return e.highlight.regionKeys??[]}function ln(e){const t=e.variable.bin??e.variable.index??"";return`${e.comparison.family}\0${ot(e)}\0${e.variable.kind}\0${t}\0${e.effect.direction}`}function cn(e,t){const s=J(e);return s.family==="ring"?s.ring??0:s.family==="sector"?qe(t).indexOf(s.sector??""):0}export function inQuadrantOrder(e){const t=new Set(e),s=$e.findIndex((i,n)=>t.has(i)&&!t.has($e[(n+3)%4])),o=s<0?0:s;return Array.from({length:4},(i,n)=>$e[(o+n)%4]).filter(i=>t.has(i))}export function findContiguousRuns(e,t,s,o){if(t==="quadrant"){const p=new Map;for(const m of e){const l=J(o(m)).quadrant;l&&p.set(l,m)}const r=[...p.keys()],u=new Set,c=[];for(const m of r){if(u.has(m))continue;const l=[],d=[m];for(u.add(m);d.length;){const h=d.pop();l.push(h);for(const g of r)!u.has(g)&&Mt(h,g)&&(u.add(g),d.push(g))}c.push(inQuadrantOrder(l).map(h=>p.get(h)))}return c}const i=p=>cn(o(p),s),n=[...e].sort((p,r)=>i(p)-i(r)),f=[];let a=[];for(const p of n){if(a.length===0){a.push(p);continue}const r=i(a[a.length-1]);i(p)-r===1?a.push(p):(f.push(a),a=[p])}if(a.length&&f.push(a),t==="sector"&&f.length>1){const r=qe(s).length,u=i(f[0][0]),c=i(f[f.length-1][f[f.length-1].length-1]);if(u===0&&c===r-1){const m=f.pop();f[0]=[...m,...f[0]]}}return f}export function mergedRegionLabel(e,t,s){if(e==="ring"){const i=t.map(p=>J(p).ring).filter(p=>p!==void 0).sort((p,r)=>p-r),n=i[0],f=i[i.length-1];let a="";return n===f&&n===1&&s>1?a=" (core)":n===f&&n===s&&s>1&&(a=" (edge)"),n===f?`Ring ${n}${a}`:`Rings ${n}\u2013${f}`}if(e==="sector"){const i=t.map(n=>J(n).sector??"");return i.length===1?`Sector ${i[0]}`:`Sectors ${i[0]}\u2013${i[i.length-1]}`}const o=t.map(i=>J(i).quadrant??"");return o.length===1?o[0]:o.length===2?`Quadrants ${o[0]} & ${o[1]}`:`Quadrants ${o.slice(0,-1).join(", ")} & ${o[o.length-1]}`}function Ve(e){return[...new Set(e)]}export function weakestMultiplier(e){return Lt(e.map(t=>{const s=t.stats.pValue??1;return s>0?(t.stats.adjustedPValue??s)/s:1}))}function ne(e,t){return Math.min(1,e*t)}function un(e,t){const s=e[0],o=s.comparison.family,i=s.variable.kind,n=Ve(e.flatMap(ue));let f,a;const p=e.map(et);if(p.every(b=>b!==void 0)){const b=new Set;f=[];for(const M of p){const S=U(M.dies);for(let R=0;R<S.length;R++)b.has(S[R])||(b.add(S[R]),f.push(M.dieKeys[R]))}const $=U(Pe(s.variable.kind,t));a=M=>b.has($[M])}else{f=Ve(e.flatMap(M=>M.highlight.dieKeys??[]));const b=new Set(f),$=en(Pe(s.variable.kind,t));a=M=>b.has($[M])}const r=mergedRegionLabel(o,e.map(b=>ue(b)[0]??""),t.ringCount),u=Pe(i,t),c=t.regionDies[o],m=U(u),l=[],d=[];for(let b=0;b<u.length;b++)c.has(m[b])&&(a(b)?l:d).push(u[b]);const h=weakestMultiplier(e);let g,v,F,D,w;if(fn(s)){const b=s.variable.index,$=t.testDefs?.find(N=>N.testNumber===b),M=N=>{let K=0,E=0;for(const Q of N){const H=W(Q,b);H!==void 0&&(K++,$&&De(ge(H,$))&&E++)}return{valid:K,fail:E}},S=M(l),R=M(d),P=S.valid>0?S.fail/S.valid:0,C=R.valid>0?R.fail/R.valid:0,V=P-C,{pValue:x,method:k}=j(S.fail,S.valid,R.fail,R.valid);g={direction:V===0?"different":V>0?"higher":"lower",absoluteDelta:V,relativeDelta:C===0?void 0:V/C,effectSize:V},v={method:k,pValue:x,sampleSizeLeft:S.valid,sampleSizeRight:R.valid};const O=ne(x,h);F=severityForFinding(O,V,rateRelativeEffect({hits:S.fail,n:S.valid,restHits:R.fail,restN:R.valid,passRate:!1})),D=Ne(r,I($,b),V),w=`specLimit:${b}`}else if(i==="test"){const b=s.variable.index,$=O=>W(O,b),M=l.map($).filter(O=>O!==void 0),S=d.map($).filter(O=>O!==void 0),{pValue:R,effectSize:P,delta:C}=on(M,S),V=pe(S),x=V!==0?C/Math.abs(V):void 0;g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:x,effectSize:P},v={method:"welch-z-approx",pValue:R,sampleSizeLeft:M.length,sampleSizeRight:S.length};const k=ne(R,h);F=severityForScore(k,P),D=Fe(r,s.variable.label,C,x,o,s.variable.unit),w=`test:${b}`}else if(i==="yield"){const b=new Set(t.passBins),$=l.filter(E=>E.hbin!==void 0),M=d.filter(E=>E.hbin!==void 0),S=$.length,R=M.length,P=$.filter(E=>b.has(E.hbin)).length,C=M.filter(E=>b.has(E.hbin)).length,V=S>0?P/S:0,x=R>0?C/R:0,k=V-x,{pValue:O,method:N}=j(P,S,C,R);g={direction:k===0?"different":k>0?"higher":"lower",absoluteDelta:k,relativeDelta:x===0?void 0:k/x,effectSize:k},v={method:N,pValue:O,sampleSizeLeft:S,sampleSizeRight:R};const K=ne(O,h);F=severityForFinding(K,k,rateRelativeEffect({hits:P,n:S,restHits:C,restN:R,passRate:!0})),D=Me(r,k,o),w="yield"}else if(i==="functionalTest"){const b=s.variable.index,$=t.testDefs?.find(K=>K.testNumber===b);let M=0,S=0,R=0,P=0;for(const K of l){const E=me(K,b,$);E!==void 0&&(S++,E&&M++)}for(const K of d){const E=me(K,b,$);E!==void 0&&(P++,E&&R++)}const C=S>0?M/S:0,V=P>0?R/P:0,x=C-V,{pValue:k,method:O}=j(M,S,R,P);g={direction:x===0?"different":x>0?"higher":"lower",absoluteDelta:x,relativeDelta:V===0?void 0:x/V,effectSize:x},v={method:O,pValue:k,sampleSizeLeft:S,sampleSizeRight:P};const N=ne(k,h);F=severityForFinding(N,x,rateRelativeEffect({hits:M,n:S,restHits:R,restN:P,passRate:!0})),D=Be(r,I($,b),x,o),w=`functional:${b}`}else{const b=s.variable.bin,$=N=>i==="softBin"?N.sbin:N.hbin,M=l.filter(N=>$(N)===b).length,S=d.filter(N=>$(N)===b).length,R=M/l.length,P=S/d.length,C=R-P,{pValue:V,method:x}=j(M,l.length,S,d.length);g={direction:C===0?"different":C>0?"higher":"lower",absoluteDelta:C,relativeDelta:P===0?void 0:C/P,effectSize:C},v={method:x,pValue:V,sampleSizeLeft:l.length,sampleSizeRight:d.length};const k=ne(V,h);F=severityForFinding(k,C,rateRelativeEffect({hits:M,n:l.length,restHits:S,restN:d.length,passRate:!1}));const O=i==="softBin"?t.sbinDefs:t.hbinDefs;D=ze(r,Ce(b,O,i==="softBin"?"SBin":"HBin"),C,o),w=`${i}:${b}`}v={...v,adjustedPValue:ne(v.pValue??1,h)};const B=Ve(n.map(b=>b.replace(`${o}:`,""))).join("-"),z=i==="hardBin"||i==="softBin"?{kind:"bin",bin:s.variable.bin,regionKeys:n,dieKeys:f}:{kind:"region",regionFamily:o,regionKeys:n,dieKeys:f};return{...s,id:`${w}:${o}:${B}`,severity:F,comparison:{family:o,left:r,right:ee(o)},effect:g,stats:v,summary:D,highlight:z,relatedIds:e.map(b=>b.id)}}function dn(e,t){const s=new Set(["ring","quadrant","sector"]),o=[],i=new Map;for(const f of e){if(!s.has(f.comparison.family)){o.push(f);continue}const a=ln(f),p=i.get(a)??[];p.push(f),i.set(a,p)}const n=[];for(const f of i.values()){if(f.length===1){n.push(f[0]);continue}const a=f[0].comparison.family;for(const p of findContiguousRuns(f,a,t.sectorCount,r=>ue(r)[0]??""))n.push(p.length===1?p[0]:un(p,t))}return[...o,...n]}function mn(e){const t=new Map,s=new Map;for(const i of e){const n=we(i);i.hbin!==void 0&&i.hbin!==null&&(t.get(i.hbin)??t.set(i.hbin,new Set).get(i.hbin)).add(n),i.sbin!==void 0&&i.sbin!==null&&(s.get(i.sbin)??s.set(i.sbin,new Set).get(i.sbin)).add(n)}const o=new Set;for(const[i,n]of t)for(const[f,a]of s){if(n.size!==a.size)continue;let p=!0;for(const r of n)if(!a.has(r)){p=!1;break}p&&o.add(`${i}:${f}`)}return o}function hn(e,t){const s=new Set(t);let o;for(const i of e){const n=oe(i,s);if(n!==void 0&&n){if(i.sbin==null||o!==void 0&&i.sbin!==o)return;o=i.sbin}}if(o!==void 0){for(const i of e)if(i.sbin===o&&oe(i,s)!==!0)return;return o}}function pn(e){return`${e.comparison.family}\0${e.comparison.left}`}export function redundancyFacts(e,t,s){return{coincident:mn(e),yieldSoftBin:hn(e,t),passBins:t,sectorCount:s}}const gn=3/5;function ot(e){return/^(?:lot-region:)?([^:|]+)/.exec(e.id)?.[1]??e.id}function bn(e){const t=ue(e);if(t.length)return t;const s=/(ring|sector|quadrant):([^:|]+)$/.exec(e.id);return s?s[2].split("-").map(o=>`${s[1]}:${o}`):[]}function at(e,t){const s=new Set;for(const o of bn(e)){const i=kt(o,t);if(!i)return;for(const n of i)s.add(n)}return s.size?s:void 0}export function collapseRedundantFindings(e,t){const{coincident:s,yieldSoftBin:o,passBins:i}=t,n=(r,u)=>{r.absorbedIds=[...r.absorbedIds??[],u.id]},f=new Map;for(const r of e){const u=pn(r);(f.get(u)??f.set(u,[]).get(u)).push(r)}const a=new Set;for(const r of f.values()){for(const c of r)if(!(c.variable.kind!=="hardBin"||c.variable.bin===void 0))for(const m of r){if(m.variable.kind!=="softBin"||m.variable.bin===void 0||a.has(m.id)||!s.has(`${c.variable.bin}:${m.variable.bin}`)||m.effect.direction!==c.effect.direction)continue;n(c,m),a.add(m.id);const l=c.variable.label.replace(/^HBin\s+/,""),d=m.variable.label.replace(/^SBin\s+/,""),h=l===d?`HBin and SBin ${l} (same dies)`:`${c.variable.label} and ${m.variable.label} (same dies)`;c.summary=c.summary.replace(c.variable.label,h),c.variable.label=h;break}const u=r.find(c=>c.variable.kind==="yield");if(u){for(const c of r)if(!(c===u||a.has(c.id)||!(c.variable.kind==="hardBin"&&i.length===1&&c.variable.bin===i[0]||c.variable.kind==="softBin"&&c.variable.bin===o))){n(u,c),a.add(c.id);for(const l of c.absorbedIds??[])u.absorbedIds=[...u.absorbedIds??[],l]}}}const p=new Map;for(const r of e){if(a.has(r.id)||r.comparison.family!=="sector"&&r.comparison.family!=="quadrant")continue;const u=[ot(r),r.variable.kind,r.variable.bin??"",r.variable.index??"",r.effect.direction].join("\0");(p.get(u)??p.set(u,[]).get(u)).push(r)}for(const r of p.values()){const u=[];for(const c of r.filter(m=>m.comparison.family==="sector")){const m=at(c,t.sectorCount);if(m)for(const l of r.filter(d=>d.comparison.family==="quadrant")){const d=at(l,t.sectorCount);if(!d)continue;let h=0;for(const v of m)d.has(v)&&h++;const g=m.size+d.size-h;h/g>=gn-1e-9&&u.push({sector:c,quadrant:l,overlap:h/g})}}u.sort((c,m)=>m.overlap-c.overlap);for(const{sector:c,quadrant:m}of u){if(a.has(c.id)||a.has(m.id))continue;const l=(m.stats.pValue??1)<(c.stats.pValue??1),[d,h]=l?[m,c]:[c,m];n(d,h),a.add(h.id),d.absorbedIds=[...d.absorbedIds??[],...h.absorbedIds??[]]}}}export function analyzeWaferMap(e,t={}){return analyzeWaferMapDecided(e,t)}export function analyzeWaferMapDecided(e,t={},s){const o=te,i=fe,n=[];te=n,fe=void 0;try{const f=yn(e,t,s);return Ze.set(f,{candidates:n,facts:fe}),f}finally{te=o,fe=i}}function yn(e,t,s){const{resolved:o,warnings:i}=resolveOptions(t),n=dt(e),f={...o,passBins:[...Nt(n,"analyzeWaferMap")],ringCount:xt(n,"analyzeWaferMap")},a=n.isLotStack,p=n.aggrMethod,r=St(a,p),u=r,c=n.dies.filter(y=>Ye(y)),m=c.filter(Ae),l=At(f,c.length);l.softPassBins=Ke(c,l.passBins).soft;const d=st(c,l.testNumbers,n.testDefs),h=l.enableTestValueAnalysis,g=h===!1?"off":h===!0?"done":s??mt(d.length*c.length),v=n.dies.filter(y=>X(y)),F=v.filter(Ae),D=r?c.filter(y=>y.sbin!==void 0):[],w=u&&c.some(y=>y.hbin!==void 0)||D.length>0||h!==!1,B=w?$t(F,n.wafer,l.ringCount):[],z=w?vt(F,n.wafer,l.ringCount):[],b=w?wt(F,n.reticleConfig):[],$=w?Dt(v,!1):[],M=w?Rt(F,n.wafer,l.sectorCount):[],S=[],R=[];u&&R.push(...le(c,B,l.passBins,l),...le(c,z,l.passBins,l),...le(c,b,l.passBins,l),...le(c,$,l.passBins,l),...le(c,M,l.passBins,l)),u&&R.push(...q(c,B,"hard",n.hbinDefs,"hardBin",l),...q(c,z,"hard",n.hbinDefs,"hardBin",l),...q(c,b,"hard",n.hbinDefs,"hardBin",l),...q(c,$,"hard",n.hbinDefs,"hardBin",l),...q(c,M,"hard",n.hbinDefs,"hardBin",l));{const y=D;R.push(...q(y,B,"soft",n.sbinDefs,"softBin",l),...q(y,z,"soft",n.sbinDefs,"softBin",l),...q(y,b,"soft",n.sbinDefs,"softBin",l),...q(y,$,"soft",n.sbinDefs,"softBin",l),...q(y,M,"soft",n.sbinDefs,"softBin",l))}const P=[...i];let C;if(h!==!1){if(g==="done"){for(const y of[B,z,b,$,M])S.push(...an(c,y,d,n.testDefs,l));C=d}R.push(...rn(c,[B,z,b,$,M],n.testDefs,l)),R.push(...ce(c,B,n.testDefs,l),...ce(c,z,n.testDefs,l),...ce(c,b,n.testDefs,l),...ce(c,$,n.testDefs,l),...ce(c,M,n.testDefs,l))}S.push(...tn(R,l));{const y=Tt(a,u,n.testDefs);if(!a||u||y!==void 0){const A=Ie(m,n.wafer,{...l,isFailingDie:y});S.push(...A),u&&S.push(..._t(m,n.wafer,n.hbinDefs,l,A))}}const V=dn(S,{eligibleDies:c,softEligibleDies:D,testDies:c,passBins:l.passBins,ringCount:l.ringCount,sectorCount:l.sectorCount,regionDies:{ring:new Set(B.flatMap(y=>U(y.dies))),quadrant:new Set(z.flatMap(y=>U(y.dies))),sector:new Set(M.flatMap(y=>U(y.dies)))},hbinDefs:n.hbinDefs,sbinDefs:n.sbinDefs,testDefs:n.testDefs});S.length=0,S.push(...V),claimForBinClusters(S);let x;if(u){const y=zt(m,n.wafer,{passBins:l.passBins,ringCount:l.ringCount});if(x=y??void 0,y!==null&&y.pattern!=="random"&&y.pattern!=="none"){const A=Ct[y.pattern],_=y.confidence==="high"?"unusual":y.confidence==="medium"?"notable":"info",T=y.features,ie=L=>`${(L*100).toFixed(0)}%`,rt=y.pattern==="edge-ring"||y.pattern==="edge-local"?`${ie(T.edgeRdd)} of edge dies failing`:y.pattern==="center"?`centroid at ${ie(T.centroidDistNorm)} of wafer radius from centre`:y.pattern==="donut"?`${ie(Math.max(T.radialFailRates[1],T.radialFailRates[2]))} of dies failing at mid-radius, ${ie(T.radialFailRates[0])} at the centre`:y.pattern==="scratch"?`a line ${Math.round(T.lineLength)} dies long and about ${Math.max(1,Math.round(T.lineWidth*2))} wide`:`${ie(T.globalRdd)} of dies failing`,ft=new Set(l.passBins),Ee=c.filter(L=>Ft(L,ft)===!0),{center:Le,radius:lt}=n.wafer,ct=new Map(m.map(L=>[de(L),Ot(L.physX-Le.x,L.physY-Le.y,lt,l.ringCount)])),ut=new Set(S.flatMap(L=>_e(L)?L.relatedIds??[]:[])),Oe=claimForPattern([y.pattern],_,S.filter(L=>!ut.has(L.id)),L=>L.comparison.family==="cluster"?[...new Set(L.highlight.kind==="dies"?L.highlight.dieKeys.map(se=>ct.get(se)??0):[])]:ue(L).map(se=>J(se).ring).filter(se=>se!==void 0),l.ringCount);S.push({id:`spatial-pattern:${y.pattern}`,level:"wafer",severity:_,variable:{kind:"spatialPattern",label:A},comparison:{family:"spatial-pattern",left:A,right:"Wafer"},effect:{direction:"different",effectSize:T.globalRdd},stats:{method:"geometry",sampleSizeLeft:Ee.length,sampleSizeRight:c.length},summary:`Spatial pattern: ${A.toLowerCase()} (${y.confidence} confidence) \u2014 ${rt}${y.note?` [${y.note}]`:""}`,highlight:{kind:"dies",dieKeys:Ee.map(L=>de(L))},relatedIds:Oe.length>0?Oe:void 0})}}S.sort((y,A)=>{const _=y.stats.adjustedPValue??y.stats.pValue??1,T=A.stats.adjustedPValue??A.stats.pValue??1;return _!==T?_-T:Math.abs(A.effect.absoluteDelta??0)-Math.abs(y.effect.absoluteDelta??0)});const k=Ut(n.dies,c.length,n.yield.yieldPercent,r);a&&(k.isLotStack=!0,p&&(k.aggregationMethod=p));const O=new Set(f.passBins),N={},K=(y,A)=>{const _=N[y]??={dieKeys:[],lostDies:0};_.dieKeys.push(de(A)),(!r||oe(A,O)!==!0)&&_.lostDies++},E=Qt(n.dies,n.testDefs,K);E&&(k.testSpecYield=E);const Q=computeFunctionalYield(n.dies,n.testDefs,K);if(Q&&(k.functionalYield=Q),Object.keys(N).length&&(k.testFailures=N),x&&(k.spatialPattern=x),C===void 0&&l.computePerTestStats&&(C=d),d.length&&(k.testValueAnalysis=ht(g,d.length,c.length)),C?.length){const y=Gt(n.dies,C,n.testDefs,l.minimumSampleSize);y&&(k.perTestStats=y);const A=pt([{dies:n.dies}],n.testDefs,C);A&&(k.capability=A)}Object.assign(k,gt(n.dies,n.testDefs));const H=bt([{dies:n.dies,wafer:n.wafer,passBins:l.passBins,ringCount:l.ringCount}]);H&&(k.regionYield=H),P.length>0&&(k.warnings=P);const G=redundancyFacts(c,l.passBins,l.sectorCount);return collapseRedundantFindings(S,G),te&&(fe=G),{level:"wafer",hasNotableFindings:S.some(y=>y.severity==="notable"||y.severity==="unusual"),findings:S,wafer:n.wafer.metadata??void 0,analysisOptions:recordedOptions(t),stats:k}}
@@ -1,61 +1,9 @@
1
- import type { Die } from '../core/dies.js';
2
- import type { ChartDatum } from './yield.js';
3
- export type BinType = 'hbin' | 'sbin';
4
- export interface BinItem {
5
- dies?: Die[];
6
- /**
7
- * Precomputed bin counts for this item (e.g. `StatsSummary.stats.hardBinCounts`/
8
- * `.softBinCounts`, already scoped to the same yield-eligible population).
9
- * When supplied, used directly instead of re-walking `dies` — avoids
10
- * re-deriving the same counts `analyzeWaferMap` already computed.
11
- */
12
- hardBinCounts?: Record<number, number>;
13
- softBinCounts?: Record<number, number>;
14
- }
15
- /**
16
- * One bar per bin, across all `items`, sorted by count descending. Excludes
17
- * partial/edge-excluded dies via `isYieldEligibleDie` — the same population
18
- * the adjacent Yield panel uses — so the two panels' totals reconcile for
19
- * the same wafer/group. Items carrying precomputed `hardBinCounts`/
20
- * `softBinCounts` (see `BinItem`) contribute those directly, skipping the
21
- * per-die walk for that item.
22
- */
23
- export declare function buildBinParetoData(items: BinItem[], binType: BinType): ChartDatum[];
24
- /** One bin's clustered bars: a count per group (aligned to `BinClusterData.groups`). */
25
- export interface BinCluster {
26
- binCode: number;
27
- label: string;
28
- /** Total dies of this bin across all groups — drives pareto ordering. */
29
- total: number;
30
- /** Per-group die counts for this bin, aligned to `BinClusterData.groups`. */
31
- counts: number[];
32
- }
33
- /** Clustered bin pareto: the group list (legend order) plus one cluster per bin. */
34
- export interface BinClusterData {
35
- groups: string[];
36
- bins: BinCluster[];
37
- }
38
- /**
39
- * Clustered bin pareto: every group's bin counts side by side, so groups
40
- * compare directly bin-by-bin. Unlike the plain pareto, this is never a
41
- * restrict-to-one-group view — all groups are always shown at once,
42
- * matching tsmap's actual behavior (a wholly different panel swapped in for
43
- * bin pareto when grouping is active, not a variant of it).
44
- */
45
- export declare function buildBinClusterData(groups: {
46
- key: string;
47
- items: BinItem[];
48
- }[], binType: BinType): BinClusterData;
49
1
  /**
50
2
  * Display order for a bin breakdown: pass bins first (in bin order), then failing
51
3
  * bins by descending count, ties broken by bin number.
52
4
  *
53
- * The single source of this ordering. It previously existed as three separate
54
- * ascending-bin-number sorts — the Summary panel's bin section and the summary
55
- * report's two bin tables (per-wafer and lot) — none of which agreed with this
56
- * module's own `buildBinParetoData`, which has always been count-descending. The
57
- * effect was that the same wafer's bins came out in one order in the Insights bin
58
- * chart and a different one in the panel and the report.
5
+ * The single source of this ordering, for the Summary panel's bin section, the summary report's bin tables (per wafer
6
+ * and lot), the legends and the gallery strip, so a wafer's bins are listed in one order everywhere.
59
7
  *
60
8
  * Pass bins are pinned to the top rather than competing on count: they are the
61
9
  * reference the failures are read against, not themselves a failure mode.
@@ -1 +1 @@
1
- import{isYieldEligibleDie as p}from"../core/dies.js";export function buildBinParetoData(l,u){const s=new Map;let n=0;for(const o of l){const i=u==="hbin"?o.hardBinCounts:o.softBinCounts;if(i){for(const[a,t]of Object.entries(i)){const e=Number(a);n+=t,s.set(e,(s.get(e)??0)+t)}continue}for(const a of o.dies??[]){if(!p(a))continue;const t=u==="hbin"?a.hbin:a.sbin;t!==void 0&&(n++,s.set(t,(s.get(t)??0)+1))}}const c=Array.from(s.entries()).map(([o,i])=>({label:`Bin ${o}`,value:i,percent:n>0?i/n*100:0,itemCount:1,binCode:o}));return c.sort((o,i)=>i.value-o.value),c}export function buildBinClusterData(l,u){const s=l.map(t=>t.key),n=new Map,c=[];function o(t,e,f){let r=n.get(t);r||(r={total:0,counts:[]},n.set(t,r),c.push(t)),r.total+=f,r.counts[e]=(r.counts[e]??0)+f}l.forEach((t,e)=>{for(const f of t.items){const r=u==="hbin"?f.hardBinCounts:f.softBinCounts;if(r){for(const[d,b]of Object.entries(r))o(Number(d),e,b);continue}for(const d of f.dies??[]){if(!p(d))continue;const b=u==="hbin"?d.hbin:d.sbin;b!==void 0&&o(b,e,1)}}});const a=c.slice().sort((t,e)=>n.get(e).total-n.get(t).total).map(t=>{const e=n.get(t);return{binCode:t,label:`Bin ${t}`,total:e.total,counts:s.map((f,r)=>e.counts[r]??0)}});return{groups:s,bins:a}}export function sortBinsForDisplay(l,u){const s=new Set(u);return[...l].sort((n,c)=>{const o=s.has(n[0]),i=s.has(c[0]);return o!==i?o?-1:1:o&&i?n[0]-c[0]:c[1]-n[1]||n[0]-c[0]})}
1
+ export function sortBinsForDisplay(o,i){const n=new Set(i);return[...o].sort((s,r)=>{const t=n.has(s[0]),e=n.has(r[0]);return t!==e?t?-1:1:t&&e?s[0]-r[0]:r[1]-s[1]||s[0]-r[0]})}
@@ -1 +1 @@
1
- import{sortBinsForDisplay as u}from"./binPareto.js";export function binCountsFrom(e,r,s){const o=new Map;if(s){for(const[n,i]of Object.entries(s))o.set(Number(n),i);return o}for(const n of e){if(n.partial||n.edgeExcluded)continue;const i=r==="hard"?n.hbin:n.sbin;i!=null&&o.set(i,(o.get(i)??0)+1)}return o}export function pooledBinCounts(e,r,s){const o=s==="hard"?"hardBinCounts":"softBinCounts";if(e?.length&&e.every(n=>n.stats[o]!==void 0)){const n=new Map;for(const i of e)for(const[t,a]of Object.entries(i.stats[o]))n.set(Number(t),(n.get(Number(t))??0)+a);return n}return binCountsFrom(r,s)}export function binBreakdownRows(e,r,s){const o=new Set(s),n=[...e.values()].reduce((t,a)=>t+a,0),i=r?new Map(r.map(t=>[t.bin,t.name])):void 0;return u(e.entries(),o).map(([t,a])=>{const c=i?.get(t);return{bin:t,...c?{name:c}:{},label:c?`Bin ${t} \xB7 ${c}`:`Bin ${t}`,count:a,percent:n?a/n*100:0,passing:o.has(t)}})}export const binBreakdownTitle=(e,r)=>`${e==="hard"?"Hard":"Soft"} Bin Breakdown \u2014 % of dies (N=${r.toLocaleString("en-GB")})`,totalOf=e=>[...e.values()].reduce((r,s)=>r+s,0);
1
+ import{isYieldEligibleDie as f}from"../core/dies.js";import{sortBinsForDisplay as u}from"./binPareto.js";export function binCountsFrom(e,r,s){const o=new Map;if(s){for(const[n,i]of Object.entries(s))o.set(Number(n),i);return o}for(const n of e){if(!f(n))continue;const i=r==="hard"?n.hbin:n.sbin;i!=null&&o.set(i,(o.get(i)??0)+1)}return o}export function pooledBinCounts(e,r,s){const o=s==="hard"?"hardBinCounts":"softBinCounts";if(e?.length&&e.every(n=>n.stats[o]!==void 0)){const n=new Map;for(const i of e)for(const[t,a]of Object.entries(i.stats[o]))n.set(Number(t),(n.get(Number(t))??0)+a);return n}return binCountsFrom(r,s)}export function binBreakdownRows(e,r,s){const o=new Set(s),n=[...e.values()].reduce((t,a)=>t+a,0),i=r?new Map(r.map(t=>[t.bin,t.name])):void 0;return u(e.entries(),o).map(([t,a])=>{const c=i?.get(t);return{bin:t,...c?{name:c}:{},label:c?`Bin ${t} \xB7 ${c}`:`Bin ${t}`,count:a,percent:n?a/n*100:0,passing:o.has(t)}})}export const binBreakdownTitle=(e,r)=>`${e==="hard"?"Hard":"Soft"} Bin Breakdown \u2014 % of dies (N=${r.toLocaleString("en-GB")})`,totalOf=e=>[...e.values()].reduce((r,s)=>r+s,0);
@@ -55,6 +55,15 @@ export interface CapabilityItem {
55
55
  /** One item's dies — typically one wafer, the natural short-term subgroup for Cp/Cpk. */
56
56
  dies?: Die[];
57
57
  }
58
+ /** The limits capability is judged against, and which kind they are. */
59
+ interface CapabilityLimits {
60
+ lsl: number;
61
+ usl: number;
62
+ basis: 'spec' | 'test';
63
+ }
64
+ /** Spec limits when both are given, else the test limits when both are, else none. The plot builder's
65
+ * normalisation to limits uses the same rule, so a plot and the capability chart place a test alike. */
66
+ export declare function capabilityLimits(def: TestDef): CapabilityLimits | undefined;
58
67
  /**
59
68
  * Process-capability data for every test in `testDefs` that has at least one
60
69
  * recorded value. Tests with both `limitLow` and `limitHigh` defined get the
@@ -134,4 +143,5 @@ export declare function buildCapabilityFigures(items: CapabilityItem[], testDefs
134
143
  * from the lot's merged `testDefs`, as they would for a direct computation.
135
144
  */
136
145
  export declare function poolCapabilityFigures(perWafer: readonly TestCapability[][], testDefs: TestDef[]): TestCapability[];
146
+ export {};
137
147
  //# sourceMappingURL=capability.d.ts.map
@@ -1 +1 @@
1
- import{isYieldEligibleDie as v}from"../core/dies.js";import{excludedCounts as H,testValuesReader as E}from"../core/dieTable.js";import{drain as C}from"../core/utils.js";import{isParametricTest as O}from"../renderer/buildWaferMap.js";import{countOutOfSpec as P,hasSpecLimits as V}from"../renderer/spec.js";import{testLabel as _,derivedFields as I}from"../renderer/testLabel.js";import{describeValues as z}from"./math.js";const R=25e4;function j(n){if(n.specLow!==void 0&&n.specHigh!==void 0&&n.specHigh>n.specLow)return{lsl:n.specLow,usl:n.specHigh,basis:"spec"};if(n.limitLow!==void 0&&n.limitHigh!==void 0&&n.limitHigh>n.limitLow)return{lsl:n.limitLow,usl:n.limitHigh,basis:"test"}}function A(n){const s=new Map,e=new Map;for(const l of n){const t=l.testNumber;if(t===void 0||!O(l))continue;e.set(t,l);const i=j(l);i&&s.set(t,i)}return{defByTestNumber:e,specByTest:s}}function*$(n,s,e){const l=[...s.keys()],t=l.length,i=new Float64Array(t),r=new Float64Array(t),o=new Float64Array(t),f=new Float64Array(t),p=new Float64Array(t),S=new Float64Array(t),y=new Float64Array(t),d=new Float64Array(t);let x=0;if(e)for(const m of n)x+=m.dies?.length??0;const g=e?Array.from({length:t},()=>new Float64Array(x)):[],u=E(l),b=new Float64Array(t),M=Math.max(500,Math.floor(R/Math.max(1,t)));let h=0;for(const m of n){S.fill(0),y.fill(0),d.fill(0);for(const c of m.dies??[])if(++h>=M&&(h=0,yield),!!v(c)){u(c,b);for(let a=0;a<t;a++){const w=b[a];Number.isFinite(w)&&(i[a]++,r[a]+=w,o[a]+=w*w,S[a]++,y[a]+=w,d[a]+=w*w,e&&(g[a][i[a]-1]=w))}}for(let c=0;c<t;c++){const a=S[c];if(a<2)continue;const w=y[c]/a,k=(d[c]-a*w*w)/(a-1);f[c]+=(a-1)*Math.max(0,k),p[c]+=a-1}}const N=new Map;for(let m=0;m<t;m++){if(i[m]===0)continue;const c=l[m];N.set(c,{n:i[m],sum:r[m],sumSq:o[m],withinNumerator:f[m],withinDenominator:p[m]}),e&&e.set(c,g[m].subarray(0,i[m]))}return N}function W(n,s,e){return C($(n,s,e))}function L(n,s,e,l){const{n:t,sum:i,sumSq:r,withinNumerator:o,withinDenominator:f}=l,p=i/t,S=t>=2?Math.max(0,(r-t*p*p)/(t-1)):0,y=Math.sqrt(S),d=f>0?Math.sqrt(o/f):NaN;let x=null,g=null,u=null,b=null;if(e){const{lsl:M,usl:h}=e,N=h-M;u=y>0?N/(6*y):null,b=y>0?Math.min((h-p)/(3*y),(p-M)/(3*y)):null,x=Number.isFinite(d)&&d>0?N/(6*d):null,g=Number.isFinite(d)&&d>0?Math.min((h-p)/(3*d),(p-M)/(3*d)):null}return{testNumber:n,label:_(s,n),unit:s.unit,...I(s),hasSpec:e!==void 0,lsl:e?.lsl,usl:e?.usl,...e?{limitBasis:e.basis}:{},mean:p,stdOverall:y,stdWithin:d,n:t,cp:x,cpk:g,pp:u,ppk:b}}function q(n){return n.sort((s,e)=>s.hasSpec!==e.hasSpec?s.hasSpec?-1:1:s.hasSpec?s.ppk===null&&e.ppk===null?0:s.ppk===null?1:e.ppk===null?-1:s.ppk-e.ppk:e.stdOverall-s.stdOverall)}export function buildCapabilityData(n,s){return C(buildCapabilityDataSteps(n,s))}export function*buildCapabilityDataSteps(n,s){return(yield*pooledTestStatsSteps(n,s)).capability.slice()}const F=new Map,Y=4,B=new WeakMap;let K=1;function U(n,s){const e=[];for(const t of n){const i=t.dies;if(!i){e.push(0);continue}let r=B.get(i);r===void 0&&(r=K++,B.set(i,r)),e.push(r)}const l=s.filter(t=>t.testNumber!==void 0&&O(t)).map(t=>`${t.testNumber}${t.testType??"P"}${t.limitLow??""}${t.limitHigh??""}${t.specLow??""}${t.specHigh??""}${t.name??""}${t.unit??""}`);return`${e.join(",")}${l.join("")}`}export function clearPooledTestStatsCache(){F.clear();for(const n of T.values())n.work.return(void 0);T.clear()}export function*pooledTestStatsSteps(n,s){const e=U(n,s),l=F.get(e);if(l)return F.delete(e),F.set(e,l),l;let t=T.get(e);t||(t={work:G(n,s,e),callers:0},T.set(e,t));const i=t;i.callers++;try{for(;;){if(i.result)return i.result;const r=i.work.next();if(r.done)return i.result=r.value,T.delete(e),r.value;yield}}finally{i.callers--,!i.result&&i.callers===0&&(i.work.return(void 0),T.get(e)===i&&T.delete(e))}}const T=new Map;function*G(n,s,e){const l={stats:new Map,specTally:new Map,capability:[]},{defByTestNumber:t,specByTest:i}=A(s);if(t.size===0)return l;const r=new Map,o=yield*$(n,t,r),f=new Map,p=new Map,S=[],y=new Map;let d;for(const g of n){const u=H((g.dies??[]).filter(b=>v(b)));if(u){d??=u.by;for(const[b,M]of u.counts)y.set(b,(y.get(b)??0)+M)}}for(const g of s){yield;const u=g.testNumber;if(u===void 0)continue;const b=o.get(u);if(!b||b.n===0||!t.has(u))continue;const M=r.get(u);r.delete(u),V(g)&&p.set(u,{n:M.length,fail:P(M,g)});const h=z(M);f.set(u,h);const N=i.get(u),m=L(u,g,N,b);let c;if(N){const w=N.usl-N.lsl;c=k=>(k-N.lsl)/w}else{const w=h.min,k=h.max-w;c=k>0?D=>(D-w)/k:()=>.5}const a=y.get(u);S.push({...m,...a&&d?{excluded:{count:a,limitSet:d}}:{},min:c(h.min),q1:c(h.q1),median:c(h.median),q3:c(h.q3),max:c(h.max)})}const x={stats:f,specTally:p,capability:q(S)};return F.set(e,x),F.size>Y&&F.delete(F.keys().next().value),x}export function buildCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(s);if(e.size===0)return[];const t=W(n,e,null),i=[];for(const[r,o]of t)o.n!==0&&i.push(L(r,e.get(r),l.get(r),o));return q(i)}export function poolCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(s),t=new Map;for(const r of n)for(const o of r){if(!e.has(o.testNumber)||o.n===0)continue;let f=t.get(o.testNumber);f||(f={n:0,sum:0,sumSq:0,withinNumerator:0,withinDenominator:0},t.set(o.testNumber,f));const p=o.stdOverall*o.stdOverall;f.n+=o.n,f.sum+=o.n*o.mean,f.sumSq+=(o.n-1)*p+o.n*o.mean*o.mean,o.n>=2&&(f.withinNumerator+=(o.n-1)*p,f.withinDenominator+=o.n-1)}const i=[];for(const[r,o]of t)i.push(L(r,e.get(r),l.get(r),o));return q(i)}
1
+ import{isYieldEligibleDie as v}from"../core/dies.js";import{excludedCounts as H,testValuesReader as E}from"../core/dieTable.js";import{drain as C}from"../core/utils.js";import{isParametricTest as O}from"../renderer/buildWaferMap.js";import{countOutOfSpec as P,hasSpecLimits as V}from"../renderer/spec.js";import{testLabel as _,derivedFields as I}from"../renderer/testLabel.js";import{describeValues as z}from"./math.js";const R=25e4;export function capabilityLimits(n){if(n.specLow!==void 0&&n.specHigh!==void 0&&n.specHigh>n.specLow)return{lsl:n.specLow,usl:n.specHigh,basis:"spec"};if(n.limitLow!==void 0&&n.limitHigh!==void 0&&n.limitHigh>n.limitLow)return{lsl:n.limitLow,usl:n.limitHigh,basis:"test"}}function A(n){const s=new Map,e=new Map;for(const l of n){const t=l.testNumber;if(t===void 0||!O(l))continue;e.set(t,l);const i=capabilityLimits(l);i&&s.set(t,i)}return{defByTestNumber:e,specByTest:s}}function*$(n,s,e){const l=[...s.keys()],t=l.length,i=new Float64Array(t),r=new Float64Array(t),o=new Float64Array(t),f=new Float64Array(t),p=new Float64Array(t),S=new Float64Array(t),y=new Float64Array(t),d=new Float64Array(t);let x=0;if(e)for(const m of n)x+=m.dies?.length??0;const g=e?Array.from({length:t},()=>new Float64Array(x)):[],u=E(l),b=new Float64Array(t),M=Math.max(500,Math.floor(R/Math.max(1,t)));let h=0;for(const m of n){S.fill(0),y.fill(0),d.fill(0);for(const c of m.dies??[])if(++h>=M&&(h=0,yield),!!v(c)){u(c,b);for(let a=0;a<t;a++){const w=b[a];Number.isFinite(w)&&(i[a]++,r[a]+=w,o[a]+=w*w,S[a]++,y[a]+=w,d[a]+=w*w,e&&(g[a][i[a]-1]=w))}}for(let c=0;c<t;c++){const a=S[c];if(a<2)continue;const w=y[c]/a,k=(d[c]-a*w*w)/(a-1);f[c]+=(a-1)*Math.max(0,k),p[c]+=a-1}}const N=new Map;for(let m=0;m<t;m++){if(i[m]===0)continue;const c=l[m];N.set(c,{n:i[m],sum:r[m],sumSq:o[m],withinNumerator:f[m],withinDenominator:p[m]}),e&&e.set(c,g[m].subarray(0,i[m]))}return N}function j(n,s,e){return C($(n,s,e))}function L(n,s,e,l){const{n:t,sum:i,sumSq:r,withinNumerator:o,withinDenominator:f}=l,p=i/t,S=t>=2?Math.max(0,(r-t*p*p)/(t-1)):0,y=Math.sqrt(S),d=f>0?Math.sqrt(o/f):NaN;let x=null,g=null,u=null,b=null;if(e){const{lsl:M,usl:h}=e,N=h-M;u=y>0?N/(6*y):null,b=y>0?Math.min((h-p)/(3*y),(p-M)/(3*y)):null,x=Number.isFinite(d)&&d>0?N/(6*d):null,g=Number.isFinite(d)&&d>0?Math.min((h-p)/(3*d),(p-M)/(3*d)):null}return{testNumber:n,label:_(s,n),unit:s.unit,...I(s),hasSpec:e!==void 0,lsl:e?.lsl,usl:e?.usl,...e?{limitBasis:e.basis}:{},mean:p,stdOverall:y,stdWithin:d,n:t,cp:x,cpk:g,pp:u,ppk:b}}function q(n){return n.sort((s,e)=>s.hasSpec!==e.hasSpec?s.hasSpec?-1:1:s.hasSpec?s.ppk===null&&e.ppk===null?0:s.ppk===null?1:e.ppk===null?-1:s.ppk-e.ppk:e.stdOverall-s.stdOverall)}export function buildCapabilityData(n,s){return C(buildCapabilityDataSteps(n,s))}export function*buildCapabilityDataSteps(n,s){return(yield*pooledTestStatsSteps(n,s)).capability.slice()}const F=new Map,W=4,B=new WeakMap;let Y=1;function K(n,s){const e=[];for(const t of n){const i=t.dies;if(!i){e.push(0);continue}let r=B.get(i);r===void 0&&(r=Y++,B.set(i,r)),e.push(r)}const l=s.filter(t=>t.testNumber!==void 0&&O(t)).map(t=>`${t.testNumber}${t.testType??"P"}${t.limitLow??""}${t.limitHigh??""}${t.specLow??""}${t.specHigh??""}${t.name??""}${t.unit??""}`);return`${e.join(",")}${l.join("")}`}export function clearPooledTestStatsCache(){F.clear();for(const n of T.values())n.work.return(void 0);T.clear()}export function*pooledTestStatsSteps(n,s){const e=K(n,s),l=F.get(e);if(l)return F.delete(e),F.set(e,l),l;let t=T.get(e);t||(t={work:U(n,s,e),callers:0},T.set(e,t));const i=t;i.callers++;try{for(;;){if(i.result)return i.result;const r=i.work.next();if(r.done)return i.result=r.value,T.delete(e),r.value;yield}}finally{i.callers--,!i.result&&i.callers===0&&(i.work.return(void 0),T.get(e)===i&&T.delete(e))}}const T=new Map;function*U(n,s,e){const l={stats:new Map,specTally:new Map,capability:[]},{defByTestNumber:t,specByTest:i}=A(s);if(t.size===0)return l;const r=new Map,o=yield*$(n,t,r),f=new Map,p=new Map,S=[],y=new Map;let d;for(const g of n){const u=H((g.dies??[]).filter(b=>v(b)));if(u){d??=u.by;for(const[b,M]of u.counts)y.set(b,(y.get(b)??0)+M)}}for(const g of s){yield;const u=g.testNumber;if(u===void 0)continue;const b=o.get(u);if(!b||b.n===0||!t.has(u))continue;const M=r.get(u);r.delete(u),V(g)&&p.set(u,{n:M.length,fail:P(M,g)});const h=z(M);f.set(u,h);const N=i.get(u),m=L(u,g,N,b);let c;if(N){const w=N.usl-N.lsl;c=k=>(k-N.lsl)/w}else{const w=h.min,k=h.max-w;c=k>0?D=>(D-w)/k:()=>.5}const a=y.get(u);S.push({...m,...a&&d?{excluded:{count:a,limitSet:d}}:{},min:c(h.min),q1:c(h.q1),median:c(h.median),q3:c(h.q3),max:c(h.max)})}const x={stats:f,specTally:p,capability:q(S)};return F.set(e,x),F.size>W&&F.delete(F.keys().next().value),x}export function buildCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(s);if(e.size===0)return[];const t=j(n,e,null),i=[];for(const[r,o]of t)o.n!==0&&i.push(L(r,e.get(r),l.get(r),o));return q(i)}export function poolCapabilityFigures(n,s){const{defByTestNumber:e,specByTest:l}=A(s),t=new Map;for(const r of n)for(const o of r){if(!e.has(o.testNumber)||o.n===0)continue;let f=t.get(o.testNumber);f||(f={n:0,sum:0,sumSq:0,withinNumerator:0,withinDenominator:0},t.set(o.testNumber,f));const p=o.stdOverall*o.stdOverall;f.n+=o.n,f.sum+=o.n*o.mean,f.sumSq+=(o.n-1)*p+o.n*o.mean*o.mean,o.n>=2&&(f.withinNumerator+=(o.n-1)*p,f.withinDenominator+=o.n-1)}const i=[];for(const[r,o]of t)i.push(L(r,e.get(r),l.get(r),o));return q(i)}
@@ -0,0 +1,53 @@
1
+ import type { PlotColor, PlotField, PlotSpec } from './plotSpec.js';
2
+ import type { TestDef } from '../renderer/buildWaferMap.js';
3
+ /**
4
+ * A field the tab supplies:
5
+ * - `test`: the section's chosen test.
6
+ * - `groupBy`: the tab's Group by field, or the wafer when Group by is off.
7
+ */
8
+ export type CardSlot = {
9
+ slot: 'test';
10
+ } | {
11
+ slot: 'groupBy';
12
+ };
13
+ export type CardField = PlotField | CardSlot;
14
+ export interface CardSpec extends Omit<PlotSpec, 'fields'> {
15
+ fields: {
16
+ x?: CardField | CardField[];
17
+ y?: CardField;
18
+ color?: PlotColor;
19
+ rows?: CardField;
20
+ facet?: CardField;
21
+ };
22
+ }
23
+ /** What the slots are filled with. */
24
+ export interface CardSlotValues {
25
+ /** The section's test. Absent = none chosen yet. */
26
+ test?: number;
27
+ /** The tab's Group by key. Absent = Group by is off. */
28
+ groupBy?: string;
29
+ testDefs?: readonly TestDef[];
30
+ }
31
+ export declare const isCardSlot: (f: unknown) => f is CardSlot;
32
+ /**
33
+ * The plot `card` draws with these slot values, or why it cannot be drawn yet (no test chosen, or one the lot does not
34
+ * hold). The colour is left as the card states it: a colour that follows Group by keeps following it.
35
+ */
36
+ export declare function fillCard(card: CardSpec, values: CardSlotValues): {
37
+ spec: PlotSpec;
38
+ } | {
39
+ issue: string;
40
+ };
41
+ /**
42
+ * The reader's own plot made from `card` as it is drawn now (Edit as plot): the slots filled, a colour that follows the
43
+ * tab replaced by the field it follows (the Group by field; the wafer when Group by is off and several wafers are in
44
+ * view; no colour otherwise), under a new id. It then draws the same thing on any lot and follows nothing.
45
+ */
46
+ export declare function freezeCard(card: CardSpec, values: CardSlotValues & {
47
+ waferCount: number;
48
+ }, id: string): {
49
+ spec: PlotSpec;
50
+ } | {
51
+ issue: string;
52
+ };
53
+ //# sourceMappingURL=cardSpec.d.ts.map
@@ -0,0 +1 @@
1
+ export const isCardSlot=r=>typeof r=="object"&&r!==null&&"slot"in r;export function fillCard(r,t){let f;const n=d=>{if(!isCardSlot(d))return d;if(d.slot==="groupBy")return t.groupBy?{meta:t.groupBy}:{builtin:"wafer"};const i=t.test,u=i===void 0?void 0:t.testDefs?.find(c=>c.testNumber===i);return i===void 0||t.testDefs&&!u?(f??=i===void 0?"Choose a test":`Test ${i} is not in this data`,{test:i??0}):u?.name?{test:i,name:u.name}:{test:i}},{fields:e,...s}=r,o={};return e.x!==void 0&&(o.x=Array.isArray(e.x)?e.x.map(n):n(e.x)),e.y!==void 0&&(o.y=n(e.y)),e.rows!==void 0&&(o.rows=n(e.rows)),e.facet!==void 0&&(o.facet=n(e.facet)),e.color!==void 0&&(o.color=e.color),f?{issue:f}:{spec:{...s,fields:o}}}export function freezeCard(r,t,f){const n=fillCard(r,t);if("issue"in n)return n;const e={...n.spec,id:f,fields:{...n.spec.fields}},s=e.fields.color;return(s===void 0||"follow"in s)&&(e.fields.color=t.groupBy?{meta:t.groupBy}:t.waferCount>1?{builtin:"wafer"}:{none:!0}),{spec:e}}
@@ -0,0 +1,37 @@
1
+ import type { PlotChart } from './plotSpec.js';
2
+ import { type GuideSection } from './guideSections.js';
3
+ /** The built-in cards that are not plots. */
4
+ export type CardKind = 'capability' | 'correlation' | 'ring-yield' | 'quadrant-yield' | 'reticle-yield' | 'comparison' | 'commonality' | 'pat' | 'difference-map';
5
+ /** Where a chart or table is found in Insights; `drilldown` is the menu opened on picked dies. */
6
+ export type CatalogueTab = 'overview' | 'distributions' | 'correlation' | 'data' | 'plots' | 'drilldown';
7
+ /** What an entry is: a way of colouring the map, a chart, a built-in card (a chart or a table), or a table of the Data tab. */
8
+ export type CatalogueKind = 'map' | 'chart' | 'table';
9
+ export interface CatalogueEntry {
10
+ /** The heading anchor on the reference page, which is the slug of `title` (Zensical takes an anchor from the heading text alone): lower-case words joined by hyphens. Never reused or renamed once published. */
11
+ id: string;
12
+ kind: CatalogueKind;
13
+ /** What the entry is called on the reference page and in the gallery. */
14
+ title: string;
15
+ /** One line: what it shows. The text of the card's "About this chart" ("About this table" on a table). */
16
+ about: string;
17
+ /** The ids of the built-in Insights cards that draw it (a plot card's id, or a card of the drilldown window). */
18
+ cards?: readonly string[];
19
+ /** The plot chart type it is, for a reader's own plot. */
20
+ chart?: PlotChart;
21
+ /** The built-in card that is not a plot. */
22
+ card?: CardKind;
23
+ /** The plot mode of the map it is (`PlotMode`), for a map entry. */
24
+ mode?: readonly string[];
25
+ /** The Insights tab that draws it, for a built-in card or table; `plots` is My plots, where a reader's own plot is built. */
26
+ tab?: CatalogueTab;
27
+ /** The example page (under `docs/examples/`) that shows it live, where it is not on an Insights tab. */
28
+ example?: string;
29
+ /** The user-guide sections that explain the statistics behind it. */
30
+ guide?: readonly GuideSection[];
31
+ /** The ids of related entries: the neighbour to reach for instead, or the one that completes it. */
32
+ see?: readonly string[];
33
+ }
34
+ export declare const CHART_CATALOGUE: readonly CatalogueEntry[];
35
+ /** An entry by id. */
36
+ export declare function catalogueEntry(id: string): CatalogueEntry | undefined;
37
+ //# sourceMappingURL=chartCatalogue.d.ts.map
@@ -0,0 +1 @@
1
+ import{GUIDE_SECTIONS as e}from"./guideSections.js";export const CHART_CATALOGUE=[{id:"bin-map",kind:"map",title:"Bin map",mode:["hardBin","softBin"],example:"display-control.html",about:"Each die coloured by its hard or soft bin, passing bins in greens and failing bins in other colours, to show where the failures are.",see:["test-value-map","bin-pareto"]},{id:"test-value-map",kind:"map",title:"Test value map",mode:["value"],example:"test-values.html",about:"Each die coloured by one test\u2019s value on a colour scale, with the test\u2019s limits on the colour bar, to show where on the wafer the value shifts.",see:["bin-map","limit-passfail-map","test-passfail-map","value-histogram"]},{id:"limit-passfail-map",kind:"map",title:"Limit pass/fail map",example:"test-values.html",about:"Each die coloured by whether its value for one test lies inside the test\u2019s limits, with the dies below the low limit and above the high limit marked apart, to show where a test fails its limits.",see:["test-value-map","test-passfail-map","pass-rate-by-test"]},{id:"test-passfail-map",kind:"map",title:"Test pass/fail map",example:"test-values.html",about:"Each die coloured by the pass or fail the tester recorded for one test, to show where a test failed, whether or not it has a measured value.",see:["limit-passfail-map","test-value-map","pass-rate-by-test"]},{id:"die-attribute-map",kind:"map",title:"Die attribute map",mode:["metadata"],example:"metadata-mode.html",about:"Each die coloured by an attribute the data carries (a test site, a probe step, a zone), to show whether a pattern follows it.",see:["bin-map"]},{id:"stacked-map",kind:"map",title:"Stacked map",mode:["stackedBins","stackedSoftBins","stackedValues"],example:"lot-stack-analysis.html",about:"The wafers of a lot laid over one another die by die: how often a bin occurs, or a value\u2019s mean, median or spread at each position, to show what repeats from wafer to wafer.",see:["difference-map","reticle-cell-yield"]},{id:"pat-verdict-map",kind:"map",title:"PAT verdict map",tab:"overview",about:"Each die coloured by its part average testing verdict (within the limits, an outlier or failing), on the map or on every wafer of a gallery, to show where the PAT outliers sit.",see:["part-average-testing-pat","bin-map","test-value-map"]},{id:"difference-map",kind:"map",title:"Difference map",card:"difference-map",tab:"distributions",about:"One group\u2019s wafer map less another\u2019s, die position by die position, to show where on the wafer they differ.",guide:[e.heatmap],see:["stacked-map","comparison-by-group"]},{id:"yield-by-wafer",kind:"chart",title:"Yield by wafer",cards:["card-yield"],tab:"overview",about:"Yield of each wafer or group: passing dies as a share of judged dies, with partial and edge-excluded dies left out. The line is the median bar.",see:["bin-pareto","what-divides-yield"]},{id:"bin-pareto",kind:"chart",title:"Bin pareto",cards:["card-bin-pareto"],tab:"overview",about:"Dies in each bin, largest first, so the bins that cost the most yield lead. Shown alone, the line is the running share of all dies.",see:["bin-map","pareto"]},{id:"pass-rate-by-test",kind:"chart",title:"Pass rate by test",cards:["card-pass-rate"],tab:"overview",about:"The share of judged dies that pass each test, lowest first, so the tests that fail the most dies lead.",see:["process-capability","bin-pareto"]},{id:"ring-yield",kind:"chart",title:"Ring yield",card:"ring-yield",tab:"overview",about:"Yield of each ring, from the wafer centre to its edge, to show a radial pattern.",see:["quadrant-yield","bin-map"]},{id:"quadrant-yield",kind:"chart",title:"Quadrant yield",card:"quadrant-yield",tab:"overview",about:"Yield of each quarter of the wafer, to show a one-sided pattern.",see:["ring-yield","bin-map"]},{id:"reticle-cell-yield",kind:"chart",title:"Reticle cell yield",card:"reticle-yield",tab:"overview",about:"Yield of each position in the reticle, pooled over every shot on every wafer. A cell low everywhere points at the mask rather than the wafer.",see:["stacked-map","ring-yield"]},{id:"test-value-distribution",kind:"chart",title:"Test value distribution",cards:["card-box"],tab:"distributions",about:"How one test\u2019s values spread on each wafer or group: the box holds the middle half of the dies, the line inside it is the median, and the whiskers reach the lowest and highest values.",see:["box-plot","value-histogram"]},{id:"value-histogram",kind:"chart",title:"Value histogram",cards:["card-histogram"],tab:"distributions",about:"How one test\u2019s values are distributed: the number of dies in each value range, with the test\u2019s limits marked.",see:["histogram","probability-plot","test-value-map"]},{id:"histogram-of-the-dies-picked",kind:"chart",title:"Histogram of the dies picked",cards:["drill-histogram"],tab:"drilldown",about:"How one test\u2019s values are distributed over the dies picked: the number of dies in each value range, with the test\u2019s limits marked.",see:["value-histogram"]},{id:"wafer-to-wafer-trend",kind:"chart",title:"Wafer-to-wafer trend",cards:["card-trend"],tab:"distributions",about:"Each wafer\u2019s mean of one test in wafer order, with a band of one standard deviation either side, to show drift through the lot.",guide:[e.bands],see:["control-chart","line-chart"]},{id:"test-scatter",kind:"chart",title:"Test scatter",cards:["card-scatter"],tab:"correlation",about:"One test against another, a point per die, to show whether the two move together. r is the correlation coefficient and n the number of dies.",guide:[e.fit],see:["test-correlation-matrix","scatter-plot"]},{id:"test-correlation-matrix",kind:"chart",title:"Test correlation matrix",card:"correlation",tab:"correlation",about:"The correlation of every pair of tests. A strong colour means two tests move together; click a cell to show the pair in the scatter.",see:["test-scatter","heatmap"]},{id:"process-capability",kind:"chart",title:"Process capability",card:"capability",tab:"distributions",about:"Every test with limits on one scale, the low limit at 0 and the high limit at 1, sorted lowest Ppk first, so the tests closest to their limits lead.",guide:[e.goal],see:["capability-goal-plot","pass-rate-by-test"]},{id:"comparison-by-group",kind:"table",title:"Comparison by group",card:"comparison",tab:"distributions",about:"Yield and each test compared between groups, counting each wafer once, with how likely a difference this large is by chance.",guide:[e.groups],see:["what-divides-yield","difference-map","box-plot"]},{id:"what-divides-yield",kind:"table",title:"What divides yield",card:"commonality",tab:"overview",about:"The wafer and lot fields ranked by how strongly they divide yield, as places to look for a cause.",guide:[e.dividesYield],see:["comparison-by-group","yield-by-wafer"]},{id:"part-average-testing-pat",kind:"table",title:"Part average testing (PAT)",card:"pat",tab:"overview",about:"Dies outside part average testing limits, set from each wafer\u2019s own spread of each test (the AEC-Q001 method), by wafer and by test.",guide:[e.pat],see:["pat-verdict-map","process-capability","scatter-plot"]},{id:"scatter-plot",kind:"chart",title:"Scatter plot",chart:"scatter",tab:"plots",about:"One field against another, a point per die or per wafer, to show whether they move together.",guide:[e.fit],see:["test-scatter","heatmap"]},{id:"histogram",kind:"chart",title:"Histogram",chart:"histogram",tab:"plots",about:"How a value is distributed: the number of dies or wafers in each value range.",see:["value-histogram","probability-plot","box-plot"]},{id:"box-plot",kind:"chart",title:"Box plot",chart:"box",tab:"plots",about:"How a value spreads in each category: the box holds the middle half, the line inside it is the median, and the whiskers reach the lowest and highest values.",guide:[e.groups],see:["test-value-distribution","nested-categories","probability-plot"]},{id:"bar-chart",kind:"chart",title:"Bar chart",chart:"bar",tab:"plots",about:"A count, a share or a summary value for each category, side by side.",see:["pareto","stacked-bars-and-shares","yield-by-wafer"]},{id:"line-chart",kind:"chart",title:"Line chart",chart:"line",tab:"plots",about:"A summary value in order along the X axis (wafer order, a test, a condition), to show a trend.",guide:[e.bands],see:["control-chart","sweep","wafer-to-wafer-trend"]},{id:"sweep",kind:"chart",title:"Sweep",chart:"sweep",tab:"plots",about:"A measured value against a swept condition, a curve per series, to show how the part responds across the range.",see:["line-chart"]},{id:"probability-plot",kind:"chart",title:"Probability plot",chart:"probability",tab:"plots",about:"The share of values at or below each value, a curve per colour, so whole distributions compare, tails included.",guide:[e.probability],see:["histogram","box-plot"]},{id:"control-chart",kind:"chart",title:"Control chart",chart:"control",tab:"plots",about:"One value per wafer in order against its centre line and control limits, with the points that break a Western Electric rule marked.",guide:[e.control],see:["wafer-to-wafer-trend","line-chart","capability-goal-plot"]},{id:"capability-goal-plot",kind:"chart",title:"Capability goal plot",chart:"goal",tab:"plots",about:"Each test with both limits placed by how far its mean is off centre and how wide its spread is, as shares of its limit window. A test outside the solid triangle is short of Ppk 1.33.",guide:[e.goal],see:["process-capability","control-chart"]},{id:"heatmap",kind:"chart",title:"Heatmap",chart:"heatmap",tab:"plots",about:"A value for every pair of two categories, as a colour, to show where the two interact.",guide:[e.heatmap],see:["test-correlation-matrix","difference-map","bar-chart"]},{id:"pareto",kind:"chart",title:"Pareto",tab:"plots",about:"Categories largest first with a line for their running share, to show which few account for most of the total.",see:["bin-pareto","bar-chart"]},{id:"stacked-bars-and-shares",kind:"chart",title:"Stacked bars and shares",tab:"plots",about:"Each bar split into its colours, as counts or as each colour\u2019s share of its own total, to show what a category is made of.",see:["bar-chart"]},{id:"nested-categories",kind:"chart",title:"Nested categories",tab:"plots",about:"A box or bar with categories inside categories, such as lots with their wafers, to show whether variation sits between or within the groups.",guide:[e.ranges],see:["box-plot","bar-chart"]},{id:"panels-small-multiples",kind:"chart",title:"Panels (small multiples)",tab:"plots",about:"One small chart per value of a field, on shared axes, to compare the same view across groups side by side.",guide:[e.ranges],see:["box-plot","scatter-plot","histogram"]},{id:"statistics-table",kind:"table",title:"Statistics table",tab:"data",about:"One row per test and group: the count, mean, spread, extremes, limits and capability, to read the numbers behind the charts.",see:["dies-table","process-capability"]},{id:"dies-table",kind:"table",title:"Dies table",tab:"data",about:"One row per die with its position, bin and values, to see exactly which dies a chart counts; it exports to CSV.",see:["wafers-table","statistics-table"]},{id:"wafers-table",kind:"table",title:"Wafers table",tab:"data",about:"One row per wafer with its attributes and its yield, to check what each wafer is and to compare them.",see:["dies-table","yield-by-wafer"]}];export function catalogueEntry(t){return CHART_CATALOGUE.find(a=>a.id===t)}
@@ -11,6 +11,15 @@ interface ClusterOptions {
11
11
  ringCount: number;
12
12
  /** Optional override for the failure predicate. Default: hard bin, then soft bin, not in passBins. */
13
13
  isFailingDie?: (die: Die) => boolean;
14
+ /**
15
+ * The hard bin `isFailingDie` selects, when the run is for one bin. Its groups are reported as that
16
+ * bin's clusters (a rise in the bin, not a fall in yield), and edge arcs are left to the run over
17
+ * every fail bin, which the edge patterns already account for.
18
+ */
19
+ bin?: {
20
+ bin: number;
21
+ label: string;
22
+ };
14
23
  }
15
24
  export declare function buildClusterFindings(dies: PositionedDie[], wafer: Wafer, options: ClusterOptions): StatsFinding[];
16
25
  export {};
@@ -1 +1 @@
1
- import{seededRandom as et}from"./math.js";import{ringOf as nt}from"../core/classify.js";import{compassBucket as it,sectorCompassNames as st}from"./regions.js";import{getDieKey as ot,gridKey as N}from"../core/dies.js";import{findConnectedComponents as rt,LargestComponentSizer as at}from"./connectedComponents.js";function ct(t,n){return st(16)[it(t,n,16)]}function lt(t){if(t.length<2)return 0;const n=[...t].sort((s,e)=>s-e);let i=n[0]+2*Math.PI-n[n.length-1];for(let s=1;s<n.length;s++)i=Math.max(i,n[s]-n[s-1]);return 2*Math.PI-i}function ut(t,n,i,s){const e=s!==void 0?Math.abs(s):0;return t<=.01&&(n>=.25||e>=2||i>=.1)?"unusual":t<=.05&&(n>=.15||e>=1||i>=.03)?"notable":"info"}const ft=99,ht=9999,j=10;class mt{sizer;failCount;maxima=[];random;order;failing;constructor(n,i,s,e){this.sizer=n,this.failCount=s,this.random=et(e),this.order=new Int32Array(i);for(let f=0;f<i;f++)this.order[f]=f;this.failing=new Uint8Array(i)}at(n){const{order:i,failing:s,failCount:e,random:f}=this,m=i.length;for(;this.maxima.length<=n;){for(let r=0;r<e;r++){const M=r+Math.floor(f()*(m-r)),g=i[r];i[r]=i[M],i[M]=g,s[i[r]]=1}this.maxima.push(this.sizer.largest(s));for(let r=0;r<e;r++)s[i[r]]=0}return this.maxima[n]}pValue(n,i){let s=0;for(let e=0;e<i;e++)if(this.at(e)>=n&&++s===j)return j/(e+1);return(1+s)/(1+i)}}function gt(t){let n=0,i=0;for(let s=0;s<t.length;s++){let e=Math.imul(t[s].x|0,2654435761)^Math.imul(t[s].y|0,2246822507);e=Math.imul(e^e>>>16,2146121005),e=Math.imul(e^e>>>15,2221713035),n=n+(e^e>>>16)|0,i=i+Math.imul(e,668265263)+374761393|0}return`${t.length}:${n>>>0}:${i>>>0}`}function pt(t,n){return t<=20?t:Math.min(n,Math.ceil(20*1.05**Math.ceil(Math.log(t/20)/Math.log(1.05))))}const dt=new Map,yt=new Map;function G(t,n,i,s){let e=t.get(n);return e===void 0&&(e=s(),t.set(n,e),t.size>i&&t.delete(t.keys().next().value)),e}function Mt(t,n,i,s){const e=t.length,f=Math.min(ht,Math.max(ft,Math.ceil(1/s))),m=gt(t),r=pt(n,e),M=G(yt,`${m}:${r}`,16,()=>{const g=G(dt,m,4,()=>new at([...t].sort((v,d)=>v.y-d.y||v.x-d.x))),[,P,R]=m.split(":").map(Number);return new mt(g,e,r,(P^Math.imul(R,739982445)^Math.imul(r+1,2246822507))>>>0)});return i.map(g=>M.pValue(g,f))}export function buildClusterFindings(t,n,i){const{passBins:s,significanceLevel:e,minimumEffectSize:f,minimumRelativeEffect:m,minimumSampleSize:r,minimumClusterSize:M,ringCount:g}=i,P=new Set(s);if(t.length<r)return[];const R=o=>{const a=o.hbin??o.sbin;return a===void 0||!P.has(a)},v=i.isFailingDie??R,d=t.filter(v),x=d.length/t.length;if(d.length===0)return[];if(x===1&&f>0&&m>0)return[];const D=t[0],L=D?D.width:10,V=D?D.height:10,X=Math.max(L,V)*1.5,I=new Map;for(const o of t)I.set(N(o.x,o.y),o);const K=Math.ceil(X/L),T=Math.ceil(X/V),Z=rt(d),O=[],E=[],Y=n.center.x,k=n.center.y,q=n.radius;for(const o of Z){if(o.length<M)continue;const a=new Set(o.map(u=>N(u.x,u.y)));for(const u of o)for(let h=-T;h<=T;h++)for(let z=-K;z<=K;z++){const w=N(u.x+z,u.y+h);if(a.has(w))continue;const F=I.get(w);F&&Math.hypot(F.physX-u.physX,F.physY-u.physY)<=X&&a.add(w)}const l=[...a].map(u=>I.get(u)).filter(Boolean),p=o.length,b=l.length;if(b<r)continue;const S=p/b,$=S-x,y=x>0?$/x:void 0;($>=f||y!==void 0&&y>=m)&&E.push({component:o,k:p,clusterRate:S,delta:$,relativeDelta:y})}if(!E.length)return[];const H=Mt(t,d.length,E.map(o=>o.k),e);for(let o=0;o<E.length;o++){const{component:a,k:l,clusterRate:p,delta:b,relativeDelta:S}=E[o],$=H[o],y=$;if(y>e)continue;const A=a.reduce((c,C)=>c+C.physX,0)/l,u=a.reduce((c,C)=>c+C.physY,0)/l;let h=a[0],z=1/0;for(const c of a){const C=Math.hypot(c.physX-A,c.physY-u);C<z&&(z=C,h=c)}const w=lt(a.map(c=>Math.atan2(c.physY-k,c.physX-Y)))*180/Math.PI,B=a.filter(c=>nt(c.physX-Y,c.physY-k,q,g)===g).length>l/2&&w<120,U=B?"edge-arc":"cluster",_=ct(A-Y,u-k),J=B?`Edge arc ~${_}`:`Cluster at (${h.x}, ${h.y})`,Q=l/t.length,W=ut(y,b,Q,S),tt=a.map(c=>ot(c));O.push({id:`${U}:${h.x},${h.y}`,level:"wafer",severity:W,variable:{kind:"yield",label:"Yield"},comparison:{family:U,left:J,right:"Rest of wafer"},effect:{direction:"lower",absoluteDelta:-b,relativeDelta:S!==void 0?-S:void 0,effectSize:b},stats:{method:"permutation",pValue:$,adjustedPValue:y,sampleSizeLeft:l,sampleSizeRight:t.length-l},summary:B?`Edge arc near ${_}: ${l} contiguous failing dies (${(p*100).toFixed(0)}% vs ${(x*100).toFixed(0)}% background)`:`Failure cluster at (${h.x}, ${h.y}): ${l} contiguous failing dies (${(p*100).toFixed(0)}% vs ${(x*100).toFixed(0)}% background)`,highlight:{kind:"dies",dieKeys:tt}})}return O.sort((o,a)=>{const l=o.stats.pValue??1,p=a.stats.pValue??1;return l!==p?l-p:Math.abs(a.effect.effectSize??0)-Math.abs(o.effect.effectSize??0)})}
1
+ import{seededRandom as nt}from"./math.js";import{ringOf as it}from"../core/classify.js";import{compassBucket as st,sectorCompassNames as ot}from"./regions.js";import{diePassStatus as j,getDieKey as rt,gridKey as L}from"../core/dies.js";import{findConnectedComponents as at,LargestComponentSizer as ct}from"./connectedComponents.js";function lt(t,i){return ot(16)[st(t,i,16)]}function ut(t){if(t.length<2)return 0;const i=[...t].sort((s,n)=>s-n);let e=i[0]+2*Math.PI-i[i.length-1];for(let s=1;s<i.length;s++)e=Math.max(e,i[s]-i[s-1]);return 2*Math.PI-e}function ft(t,i,e,s){const n=s!==void 0?Math.abs(s):0;return t<=.01&&(i>=.25||n>=2||e>=.1)?"unusual":t<=.05&&(i>=.15||n>=1||e>=.03)?"notable":"info"}const ht=99,mt=9999,G=10;class dt{sizer;failCount;maxima=[];random;order;failing;constructor(i,e,s,n){this.sizer=i,this.failCount=s,this.random=nt(n),this.order=new Int32Array(e);for(let h=0;h<e;h++)this.order[h]=h;this.failing=new Uint8Array(e)}at(i){const{order:e,failing:s,failCount:n,random:h}=this,g=e.length;for(;this.maxima.length<=i;){for(let r=0;r<n;r++){const S=r+Math.floor(h()*(g-r)),p=e[r];e[r]=e[S],e[S]=p,s[e[r]]=1}this.maxima.push(this.sizer.largest(s));for(let r=0;r<n;r++)s[e[r]]=0}return this.maxima[i]}pValue(i,e){let s=0;for(let n=0;n<e;n++)if(this.at(n)>=i&&++s===G)return G/(n+1);return(1+s)/(1+e)}}function gt(t){let i=0,e=0;for(let s=0;s<t.length;s++){let n=Math.imul(t[s].x|0,2654435761)^Math.imul(t[s].y|0,2246822507);n=Math.imul(n^n>>>16,2146121005),n=Math.imul(n^n>>>15,2221713035),i=i+(n^n>>>16)|0,e=e+Math.imul(n,668265263)+374761393|0}return`${t.length}:${i>>>0}:${e>>>0}`}function pt(t,i){return t<=20?t:Math.min(i,Math.ceil(20*1.05**Math.ceil(Math.log(t/20)/Math.log(1.05))))}const yt=new Map,bt=new Map;function Z(t,i,e,s){let n=t.get(i);return n===void 0&&(n=s(),t.set(i,n),t.size>e&&t.delete(t.keys().next().value)),n}function xt(t,i,e,s){const n=t.length,h=Math.min(mt,Math.max(ht,Math.ceil(1/s))),g=gt(t),r=pt(i,n),S=Z(bt,`${g}:${r}`,16,()=>{const p=Z(yt,g,4,()=>new ct([...t].sort((x,m)=>x.y-m.y||x.x-m.x))),[,F,R]=g.split(":").map(Number);return new dt(p,n,r,(F^Math.imul(R,739982445)^Math.imul(r+1,2246822507))>>>0)});return e.map(p=>S.pValue(p,h))}export function buildClusterFindings(t,i,e){const{passBins:s,significanceLevel:n,minimumEffectSize:h,minimumRelativeEffect:g,minimumSampleSize:r,minimumClusterSize:S,ringCount:p}=e,F=new Set(s);if(e.isFailingDie||(t=t.filter(o=>j(o,F)!==void 0)),t.length<r)return[];const R=e.isFailingDie??(o=>j(o,F)===!1),x=t.filter(R),m=x.length/t.length;if(x.length===0)return[];if(m===1&&h>0&&g>0)return[];const D=t[0],V=D?D.width:10,K=D?D.height:10,X=Math.max(V,K)*1.5,B=new Map;for(const o of t)B.set(L(o.x,o.y),o);const T=Math.ceil(X/V),O=Math.ceil(X/K),q=at(x),U=[],v=[],Y=i.center.x,I=i.center.y,H=i.radius;for(const o of q){if(o.length<S)continue;const l=new Set(o.map(f=>L(f.x,f.y)));for(const f of o)for(let a=-O;a<=O;a++)for(let C=-T;C<=T;C++){const w=L(f.x+C,f.y+a);if(l.has(w))continue;const P=B.get(w);P&&Math.hypot(P.physX-f.physX,P.physY-f.physY)<=X&&l.add(w)}const u=[...l].map(f=>B.get(f)).filter(Boolean),d=o.length,y=u.length;if(y<r)continue;const M=d/y,z=M-m,$=m>0?z/m:void 0;(z>=h||$!==void 0&&$>=g)&&v.push({component:o,k:d,clusterRate:M,delta:z,relativeDelta:$})}if(!v.length)return[];const J=xt(t,x.length,v.map(o=>o.k),n);for(let o=0;o<v.length;o++){const{component:l,k:u,clusterRate:d,delta:y,relativeDelta:M}=v[o],z=J[o],$=z;if($>n)continue;const A=l.reduce((c,E)=>c+E.physX,0)/u,f=l.reduce((c,E)=>c+E.physY,0)/u;let a=l[0],C=1/0;for(const c of l){const E=Math.hypot(c.physX-A,c.physY-f);E<C&&(C=E,a=c)}const w=ut(l.map(c=>Math.atan2(c.physY-I,c.physX-Y)))*180/Math.PI,k=l.filter(c=>it(c.physX-Y,c.physY-I,H,p)===p).length>u/2&&w<120;if(k&&e.bin)continue;const N=k?"edge-arc":"cluster",_=lt(A-Y,f-I),b=e.bin,Q=k?`Edge arc ~${_}`:`Cluster at (${a.x}, ${a.y})`,W=u/t.length,tt=ft($,y,W,M),et=l.map(c=>rt(c));U.push({id:b?`${N}:hardBin:${b.bin}:${a.x},${a.y}`:`${N}:${a.x},${a.y}`,level:"wafer",severity:tt,variable:b?{kind:"hardBin",bin:b.bin,label:b.label}:{kind:"yield",label:"Yield"},comparison:{family:N,left:Q,right:"Rest of wafer"},effect:b?{direction:"higher",absoluteDelta:y,relativeDelta:M,effectSize:y}:{direction:"lower",absoluteDelta:-y,relativeDelta:M!==void 0?-M:void 0,effectSize:y},stats:{method:"permutation",pValue:z,adjustedPValue:$,sampleSizeLeft:u,sampleSizeRight:t.length-u},summary:k?`Edge arc near ${_}: ${u} contiguous failing dies (${(d*100).toFixed(0)}% vs ${(m*100).toFixed(0)}% background)`:b?`${b.label} cluster at (${a.x}, ${a.y}): ${u} contiguous dies (${(d*100).toFixed(0)}% vs ${(m*100).toFixed(0)}% background)`:`Failure cluster at (${a.x}, ${a.y}): ${u} contiguous failing dies (${(d*100).toFixed(0)}% vs ${(m*100).toFixed(0)}% background)`,highlight:{kind:"dies",dieKeys:et}})}return U.sort((o,l)=>{const u=o.stats.pValue??1,d=l.stats.pValue??1;return u!==d?u-d:Math.abs(l.effect.effectSize??0)-Math.abs(o.effect.effectSize??0)})}
@@ -0,0 +1,62 @@
1
+ import type { Die } from '../core/dies.js';
2
+ import type { WaferMetadata } from '../core/metadata.js';
3
+ import { type GroupComparison } from './groupCompare.js';
4
+ import { type FacetCuration } from './facets.js';
5
+ export interface CommonalityWafer {
6
+ metadata?: WaferMetadata;
7
+ dies: readonly Die[];
8
+ passBins: readonly number[];
9
+ }
10
+ export interface CommonalityField {
11
+ key: string;
12
+ label: string;
13
+ }
14
+ /** What is compared across a field's groups: the wafers' yield, or their share of judged dies in one hard bin. */
15
+ export type CommonalityMeasure = {
16
+ kind: 'yield';
17
+ } | {
18
+ kind: 'bin';
19
+ bin: number;
20
+ };
21
+ export interface CommonalityRow {
22
+ field: CommonalityField;
23
+ measure: CommonalityMeasure;
24
+ comparison: GroupComparison;
25
+ /** The group with the lowest yield (or the highest bin rate), and its mean over its wafers, in percent. */
26
+ worst: {
27
+ key: string;
28
+ mean: number;
29
+ };
30
+ /** The group at the other end. */
31
+ best: {
32
+ key: string;
33
+ mean: number;
34
+ };
35
+ /** `worst` to `best` in percentage points, always positive. */
36
+ spread: number;
37
+ /** Benjamini–Hochberg q of Welch's p (Kruskal–Wallis's where Welch cannot be computed), over every row. */
38
+ pAdjusted: number;
39
+ }
40
+ export interface CommonalityResult {
41
+ rows: CommonalityRow[];
42
+ /** Fields with no two groups of two or more wafers: nothing to compare. */
43
+ untestable: CommonalityField[];
44
+ /** The fail bins compared, most dies first. */
45
+ bins: number[];
46
+ /**
47
+ * Pairs of fields that divide the wafers identically (every group of one is a group of the other): the wafers cannot
48
+ * say which of the two it is.
49
+ */
50
+ confounded: Array<[CommonalityField, CommonalityField]>;
51
+ }
52
+ /** How many of the most common fail bins are compared, besides yield. */
53
+ export declare const COMMONALITY_BINS = 5;
54
+ /**
55
+ * Every field of `fields` ranked by how clearly its groups differ in yield and in the rate of each of the
56
+ * `COMMONALITY_BINS` most common fail bins (failing by each wafer's own pass bins). A wafer with no value for a field
57
+ * is left out of that field's comparison.
58
+ */
59
+ export declare function rankCommonality(wafers: readonly CommonalityWafer[], fields: readonly CommonalityField[], curation?: Record<string, FacetCuration>): CommonalityResult;
60
+ /** A measure as the reader names it: "Yield", "Hard bin 2". */
61
+ export declare const measureLabel: (m: CommonalityMeasure, binName?: (bin: number) => string | undefined) => string;
62
+ //# sourceMappingURL=commonality.d.ts.map
@@ -0,0 +1 @@
1
+ import{diePassStatus as I,isYieldEligibleDie as B}from"../core/dies.js";import{benjaminiHochberg as Y}from"./math.js";import{compareGroups as $,comparisonP as C}from"./groupCompare.js";import{facetValueOf as z}from"./facets.js";import{yieldCounts as E}from"./yield.js";import{compareNatural as H}from"../core/utils.js";export const COMMONALITY_BINS=5;function L(s,f){let r=0,a=0;for(const c of s.dies)!B(c)||c.hbin===void 0||(a++,c.hbin===f&&r++);return a?r/a*100:NaN}export function rankCommonality(s,f,r){const a=s.map(e=>{const{pass:n,total:o}=E(e.dies,e.passBins);return o?n/o*100:NaN}),c=new Map;for(const e of s){const n=new Set(e.passBins);for(const o of e.dies)B(o)&&o.hbin!==void 0&&I(o,n)===!1&&c.set(o.hbin,(c.get(o.hbin)??0)+1)}const p=[...c].sort((e,n)=>n[1]-e[1]||e[0]-n[0]).slice(0,COMMONALITY_BINS).map(([e])=>e),t=new Map(p.map(e=>[e,s.map(n=>L(n,e))])),u=[],w=[],h=new Map;for(const e of f){const n=s.map(i=>z(i.metadata,e.key,r)),o=[...new Set(n.filter(i=>i!==void 0))].sort(H);if(o.filter(i=>n.filter(y=>y===i).length>=2).length<2){w.push(e);continue}h.set(e.key,n.map(i=>i===void 0?"":String(o.indexOf(i))).join("|"));const P=[[{kind:"yield"},a],...p.map(i=>[{kind:"bin",bin:i},t.get(i)])];for(const[i,y]of P){const b=$(o.map(d=>({key:d,values:y.filter((l,F)=>n[F]===d)}))),g=b.groups.filter(d=>!b.tooSmall.includes(d.key)&&Number.isFinite(d.mean));if(g.length<2)continue;const k=g.reduce((d,l)=>l.mean<d.mean?l:d),N=g.reduce((d,l)=>l.mean>d.mean?l:d),[x,A]=i.kind==="yield"?[k,N]:[N,k];u.push({field:e,measure:i,comparison:b,worst:{key:x.key,mean:x.mean},best:{key:A.key,mean:A.mean},spread:N.mean-k.mean,pAdjusted:NaN})}}const j=u.filter(e=>Number.isFinite(C(e.comparison))),O=Y(j.map(e=>C(e.comparison)));j.forEach((e,n)=>{e.pAdjusted=O[n]});const M=e=>Number.isFinite(e.pAdjusted)?e.pAdjusted:1/0;u.sort((e,n)=>M(e)-M(n)||n.spread-e.spread);const S=[],m=f.filter(e=>h.has(e.key));for(let e=0;e<m.length;e++)for(let n=e+1;n<m.length;n++)_(h.get(m[e].key),h.get(m[n].key))&&S.push([m[e],m[n]]);return{rows:u,untestable:w,bins:p,confounded:S}}function _(s,f){const r=s.split("|"),a=f.split("|"),c=new Map,p=new Map;for(let t=0;t<r.length;t++){if(c.has(r[t])&&c.get(r[t])!==a[t]||p.has(a[t])&&p.get(a[t])!==r[t])return!1;c.set(r[t],a[t]),p.set(a[t],r[t])}return!0}export const measureLabel=(s,f)=>s.kind==="yield"?"Yield":`Hard bin ${s.bin}${f?.(s.bin)?` (${f(s.bin)})`:""}`;
@@ -0,0 +1,21 @@
1
+ /** d2 for subgroups of two: the expected range of two normal values in standard deviations. */
2
+ export declare const MR_D2 = 1.128;
3
+ export interface ControlLimits {
4
+ centre: number;
5
+ /** σ from the average moving range of the baseline. */
6
+ sigma: number;
7
+ ucl: number;
8
+ lcl: number;
9
+ /** Points the centre and σ were set from. */
10
+ baseline: number;
11
+ }
12
+ export interface ControlViolation {
13
+ index: number;
14
+ rules: number[];
15
+ }
16
+ export declare const CONTROL_RULE_TEXT: Readonly<Record<number, string>>;
17
+ /** The centre and ±3σ limits of `values` from its first `baseline` points (all when absent); undefined below three points. */
18
+ export declare function individualsLimits(values: readonly number[], baseline?: number): ControlLimits | undefined;
19
+ /** The points of `values` that complete a Western Electric rule against `lim`, each with the rules it completes. */
20
+ export declare function westernElectric(values: readonly number[], lim: ControlLimits): ControlViolation[];
21
+ //# sourceMappingURL=control.d.ts.map