qesuite 1.0.54 → 1.0.56
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.
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +85 -19
- package/dist/index.mjs +85 -19
- package/index.ts +103 -24
- package/package.json +1 -1
- package/versions/1_0_55.md +2 -0
- package/versions/1_0_56.md +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -200,6 +200,38 @@ declare const Capability: {
|
|
|
200
200
|
*/
|
|
201
201
|
Cpk(data: number[], spec: Specification, subgroupSize?: number): number;
|
|
202
202
|
/**
|
|
203
|
+
* Evaluates the capability index Cpk(overall).
|
|
204
|
+
* @customfunction
|
|
205
|
+
* @param data The data to evaluate.
|
|
206
|
+
* @param spec The specification to evaluate the capability against.
|
|
207
|
+
* @param target The target value of the process
|
|
208
|
+
*/
|
|
209
|
+
Cpm(data: number[], spec: Specification, target: number): number;
|
|
210
|
+
/**
|
|
211
|
+
* Calculates the defective parts per million.
|
|
212
|
+
* @customfunction
|
|
213
|
+
* @param data The data to evaluate.
|
|
214
|
+
* @param spec The specification to evaluate against.
|
|
215
|
+
* @param confidenceInterval [OPTIONAL] The desired confidence level of the analysis. DEFAULT = 0.95 (95%)
|
|
216
|
+
*/
|
|
217
|
+
DPPM(data: number[], spec: Specification, confidenceInterval?: number): {
|
|
218
|
+
LSL: {
|
|
219
|
+
PPM: number;
|
|
220
|
+
LB: number;
|
|
221
|
+
UB: number;
|
|
222
|
+
};
|
|
223
|
+
USL: {
|
|
224
|
+
PPM: number;
|
|
225
|
+
LB: number;
|
|
226
|
+
UB: number;
|
|
227
|
+
};
|
|
228
|
+
Total: {
|
|
229
|
+
PPM: number;
|
|
230
|
+
LB: number;
|
|
231
|
+
UB: number;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
203
235
|
* Evaluates the capability index Pp(within).
|
|
204
236
|
* @customfunction
|
|
205
237
|
* @param data The data to evaluate.
|
package/dist/index.d.ts
CHANGED
|
@@ -200,6 +200,38 @@ declare const Capability: {
|
|
|
200
200
|
*/
|
|
201
201
|
Cpk(data: number[], spec: Specification, subgroupSize?: number): number;
|
|
202
202
|
/**
|
|
203
|
+
* Evaluates the capability index Cpk(overall).
|
|
204
|
+
* @customfunction
|
|
205
|
+
* @param data The data to evaluate.
|
|
206
|
+
* @param spec The specification to evaluate the capability against.
|
|
207
|
+
* @param target The target value of the process
|
|
208
|
+
*/
|
|
209
|
+
Cpm(data: number[], spec: Specification, target: number): number;
|
|
210
|
+
/**
|
|
211
|
+
* Calculates the defective parts per million.
|
|
212
|
+
* @customfunction
|
|
213
|
+
* @param data The data to evaluate.
|
|
214
|
+
* @param spec The specification to evaluate against.
|
|
215
|
+
* @param confidenceInterval [OPTIONAL] The desired confidence level of the analysis. DEFAULT = 0.95 (95%)
|
|
216
|
+
*/
|
|
217
|
+
DPPM(data: number[], spec: Specification, confidenceInterval?: number): {
|
|
218
|
+
LSL: {
|
|
219
|
+
PPM: number;
|
|
220
|
+
LB: number;
|
|
221
|
+
UB: number;
|
|
222
|
+
};
|
|
223
|
+
USL: {
|
|
224
|
+
PPM: number;
|
|
225
|
+
LB: number;
|
|
226
|
+
UB: number;
|
|
227
|
+
};
|
|
228
|
+
Total: {
|
|
229
|
+
PPM: number;
|
|
230
|
+
LB: number;
|
|
231
|
+
UB: number;
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
203
235
|
* Evaluates the capability index Pp(within).
|
|
204
236
|
* @customfunction
|
|
205
237
|
* @param data The data to evaluate.
|
package/dist/index.js
CHANGED
|
@@ -215,16 +215,6 @@ var Specification = class {
|
|
|
215
215
|
tol_plus = Number(tol);
|
|
216
216
|
tol_minus = Number(tol);
|
|
217
217
|
}
|
|
218
|
-
if (!Number.isNaN(nominal) && !Number.isNaN(tol_plus) && !Number.isNaN(tol_minus)) {
|
|
219
|
-
USL = nominal + tol_plus;
|
|
220
|
-
let digits = String(tol_plus).split(".");
|
|
221
|
-
digits[1] = digits[1] ?? "0";
|
|
222
|
-
USL = Number(USL).toFixed(digits[1].length);
|
|
223
|
-
LSL = nominal - tol_minus;
|
|
224
|
-
digits = String(tol_minus).split(".");
|
|
225
|
-
digits[1] = digits[1] ?? "0";
|
|
226
|
-
LSL = Number(LSL).toFixed(digits[1].length);
|
|
227
|
-
}
|
|
228
218
|
if (tol) {
|
|
229
219
|
return {
|
|
230
220
|
nominal: nominal ?? NaN,
|
|
@@ -554,13 +544,35 @@ function RoundTO(number, digits) {
|
|
|
554
544
|
}
|
|
555
545
|
let str = number.toString();
|
|
556
546
|
let decimalIndex = str.indexOf(".");
|
|
547
|
+
let roundFinalDigit = Number(str.substring(decimalIndex + digits + 2, decimalIndex + digits + 3)) >= 5;
|
|
557
548
|
let returner = Number(str.substring(0, decimalIndex + digits + 1));
|
|
549
|
+
if (roundFinalDigit) {
|
|
550
|
+
returner = returner + Math.pow(10, -1 * digits);
|
|
551
|
+
}
|
|
558
552
|
let i = 0;
|
|
559
553
|
while (returner === 0) {
|
|
560
554
|
i++;
|
|
561
555
|
returner = Number(str.substring(0, decimalIndex + digits + 1 + i));
|
|
562
556
|
}
|
|
563
|
-
|
|
557
|
+
if (Math.abs(number) < 1e-4) {
|
|
558
|
+
let f_i = 0;
|
|
559
|
+
let l_i = 0;
|
|
560
|
+
let d_i = 0;
|
|
561
|
+
let i2 = 0;
|
|
562
|
+
while (d_i <= digits) {
|
|
563
|
+
if (str[i2] != "0" && str[i2] != ".") {
|
|
564
|
+
d_i += 1;
|
|
565
|
+
if (f_i == 0) {
|
|
566
|
+
f_i = i2;
|
|
567
|
+
}
|
|
568
|
+
;
|
|
569
|
+
}
|
|
570
|
+
i2 += 1;
|
|
571
|
+
}
|
|
572
|
+
l_i = i2;
|
|
573
|
+
return str[f_i] + "." + str.substring(f_i + 1, f_i + digits) + "e-" + (f_i - decimalIndex);
|
|
574
|
+
}
|
|
575
|
+
return Number(`${returner}`.substring(0, decimalIndex + digits + 1));
|
|
564
576
|
}
|
|
565
577
|
var Capability = {
|
|
566
578
|
/**
|
|
@@ -571,7 +583,6 @@ var Capability = {
|
|
|
571
583
|
* @param subgroupSize The size of the subgroup to use for calculating within standard deviation
|
|
572
584
|
*/
|
|
573
585
|
Analysis(data, spec, subgroupSize = 2) {
|
|
574
|
-
console.log(spec);
|
|
575
586
|
return {
|
|
576
587
|
Cp: Capability.Cp(data, spec, subgroupSize),
|
|
577
588
|
Cpk: Capability.Cpk(data, spec, subgroupSize),
|
|
@@ -615,6 +626,61 @@ var Capability = {
|
|
|
615
626
|
return Number(min / (3 * standarddeviation));
|
|
616
627
|
},
|
|
617
628
|
/**
|
|
629
|
+
* Evaluates the capability index Cpk(overall).
|
|
630
|
+
* @customfunction
|
|
631
|
+
* @param data The data to evaluate.
|
|
632
|
+
* @param spec The specification to evaluate the capability against.
|
|
633
|
+
* @param target The target value of the process
|
|
634
|
+
*/
|
|
635
|
+
Cpm(data, spec, target) {
|
|
636
|
+
return Math.min(spec.USL - target, target - spec.LSL) / (3 * Math.sqrt(SumSquaredDeviation(data, target) / data.length));
|
|
637
|
+
},
|
|
638
|
+
/**
|
|
639
|
+
* Calculates the defective parts per million.
|
|
640
|
+
* @customfunction
|
|
641
|
+
* @param data The data to evaluate.
|
|
642
|
+
* @param spec The specification to evaluate against.
|
|
643
|
+
* @param confidenceInterval [OPTIONAL] The desired confidence level of the analysis. DEFAULT = 0.95 (95%)
|
|
644
|
+
*/
|
|
645
|
+
DPPM(data, spec, confidenceInterval = 0.95) {
|
|
646
|
+
let mean = Mean(data);
|
|
647
|
+
let std = StDev.S(data);
|
|
648
|
+
let a = 1 - confidenceInterval;
|
|
649
|
+
let Z_1_a2 = Distributions.Normal.inv(1 - a / 2);
|
|
650
|
+
let Z_lsl = (mean - spec.LSL) / std;
|
|
651
|
+
let Z_usl = (spec.USL - mean) / std;
|
|
652
|
+
let v = data.length - 1;
|
|
653
|
+
let UL = Z_lsl + Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_lsl, 2) / (2 * v));
|
|
654
|
+
let LL = Z_lsl - Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_lsl, 2) / (2 * v));
|
|
655
|
+
let UU = Z_usl + Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_usl, 2) / (2 * v));
|
|
656
|
+
let LU = Z_usl - Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_usl, 2) / (2 * v));
|
|
657
|
+
let PPM_L = (1 - Distributions.Normal.cdf((mean - spec.LSL) / std, 0, 1)) * 1e6;
|
|
658
|
+
let PPM_U = (1 - Distributions.Normal.cdf((spec.USL - mean) / std, 0, 1)) * 1e6;
|
|
659
|
+
let p_hat = 1 - Distributions.Normal.cdf((mean - spec.LSL) / std, 0, 1) + (1 - Distributions.Normal.cdf((mean - spec.USL) / std, 0, 1));
|
|
660
|
+
let ln_p = Math.log(p_hat / (1 - p_hat));
|
|
661
|
+
let part_p_u = 1 / (p_hat * (1 - p_hat)) * (1 / std) * (Distributions.Normal.pdf((spec.USL - mean) / std) - Distributions.Normal.pdf((spec.LSL - mean) / std));
|
|
662
|
+
let part_p_v = 0.5 * (1 / (p_hat * (1 - p_hat))) * ((spec.USL - mean) / Math.pow(std, 3) * Distributions.Normal.pdf((spec.USL - mean) / std) - (spec.LSL - mean) / Math.pow(std, 3) * Distributions.Normal.pdf((spec.LSL - mean) / std));
|
|
663
|
+
let V_hat = Math.pow(part_p_u, 2) * Math.pow(std, 2) / mean + Math.pow(part_p_v, 2) * 2 * Math.pow(std, 4) / v;
|
|
664
|
+
let returner = {
|
|
665
|
+
LSL: {
|
|
666
|
+
PPM: PPM_L,
|
|
667
|
+
LB: 1e6 * (1 - Distributions.Normal.cdf(UL, 0, 1)),
|
|
668
|
+
UB: 1e6 * (1 - Distributions.Normal.cdf(LL, 0, 1))
|
|
669
|
+
},
|
|
670
|
+
USL: {
|
|
671
|
+
PPM: PPM_U,
|
|
672
|
+
LB: 1e6 * (1 - Distributions.Normal.cdf(UU, 0, 1)),
|
|
673
|
+
UB: 1e6 * (1 - Distributions.Normal.cdf(LU, 0, 1))
|
|
674
|
+
},
|
|
675
|
+
Total: {
|
|
676
|
+
PPM: PPM_L + PPM_U,
|
|
677
|
+
LB: Math.exp(ln_p - Z_1_a2 * Math.sqrt(V_hat)) / (1 + Math.exp(ln_p - Z_1_a2 * Math.sqrt(V_hat))) * 1e6,
|
|
678
|
+
UB: Math.exp(ln_p + Z_1_a2 * Math.sqrt(V_hat)) / (1 + Math.exp(ln_p + Z_1_a2 * Math.sqrt(V_hat))) * 1e6
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
return returner;
|
|
682
|
+
},
|
|
683
|
+
/**
|
|
618
684
|
* Evaluates the capability index Pp(within).
|
|
619
685
|
* @customfunction
|
|
620
686
|
* @param data The data to evaluate.
|
|
@@ -831,9 +897,11 @@ function CreateCapabilityPlot(data, specification) {
|
|
|
831
897
|
];
|
|
832
898
|
AddInfoTable(ctx, overallInfo, 3 * chartSettings.width / 4, chartSettings.margins.top, chartSettings.width / 4, chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom, "Overall");
|
|
833
899
|
const mean = Mean(data);
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
AddLinePlot(ctx,
|
|
900
|
+
let plotMin = !isNaN(specification.LSL) ? specification.LSL : Math.max(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
901
|
+
let plotMax = !isNaN(specification.USL) ? specification.USL : Math.min(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
902
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Overall");
|
|
903
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top + 40 + (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Within");
|
|
904
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [specification.LSL, specification.USL], chartSettings.width / 4 + 25, chartSettings.margins.top + 80 + 2 * (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Specs");
|
|
837
905
|
return canvas;
|
|
838
906
|
}
|
|
839
907
|
var Beta = {
|
|
@@ -2353,7 +2421,6 @@ var GoodnessOfFit = {
|
|
|
2353
2421
|
if (ADStar <= 0.2) {
|
|
2354
2422
|
p = 1 - Math.exp(-13.436 + 101.14 * ADStar - 223.73 * Math.pow(ADStar, 2));
|
|
2355
2423
|
}
|
|
2356
|
-
console.log(p, p > 1 || p < 5e-3);
|
|
2357
2424
|
return p > 1 || p < 5e-3 ? "<0.005" : p;
|
|
2358
2425
|
},
|
|
2359
2426
|
/**
|
|
@@ -2577,11 +2644,10 @@ function Median(data) {
|
|
|
2577
2644
|
}
|
|
2578
2645
|
function MovingRange(data, w = 2) {
|
|
2579
2646
|
let movingRange = [];
|
|
2580
|
-
for (let i =
|
|
2581
|
-
let h = i - w + 1;
|
|
2647
|
+
for (let i = 0; i < data.length + 1 - w; i++) {
|
|
2582
2648
|
let values = [];
|
|
2583
2649
|
for (let j = 0; j < w; j++) {
|
|
2584
|
-
values.push(Number(data[
|
|
2650
|
+
values.push(Number(data[i + j]));
|
|
2585
2651
|
}
|
|
2586
2652
|
movingRange.push(CalculateRange(values));
|
|
2587
2653
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -123,16 +123,6 @@ var Specification = class {
|
|
|
123
123
|
tol_plus = Number(tol);
|
|
124
124
|
tol_minus = Number(tol);
|
|
125
125
|
}
|
|
126
|
-
if (!Number.isNaN(nominal) && !Number.isNaN(tol_plus) && !Number.isNaN(tol_minus)) {
|
|
127
|
-
USL = nominal + tol_plus;
|
|
128
|
-
let digits = String(tol_plus).split(".");
|
|
129
|
-
digits[1] = digits[1] ?? "0";
|
|
130
|
-
USL = Number(USL).toFixed(digits[1].length);
|
|
131
|
-
LSL = nominal - tol_minus;
|
|
132
|
-
digits = String(tol_minus).split(".");
|
|
133
|
-
digits[1] = digits[1] ?? "0";
|
|
134
|
-
LSL = Number(LSL).toFixed(digits[1].length);
|
|
135
|
-
}
|
|
136
126
|
if (tol) {
|
|
137
127
|
return {
|
|
138
128
|
nominal: nominal ?? NaN,
|
|
@@ -462,13 +452,35 @@ function RoundTO(number, digits) {
|
|
|
462
452
|
}
|
|
463
453
|
let str = number.toString();
|
|
464
454
|
let decimalIndex = str.indexOf(".");
|
|
455
|
+
let roundFinalDigit = Number(str.substring(decimalIndex + digits + 2, decimalIndex + digits + 3)) >= 5;
|
|
465
456
|
let returner = Number(str.substring(0, decimalIndex + digits + 1));
|
|
457
|
+
if (roundFinalDigit) {
|
|
458
|
+
returner = returner + Math.pow(10, -1 * digits);
|
|
459
|
+
}
|
|
466
460
|
let i = 0;
|
|
467
461
|
while (returner === 0) {
|
|
468
462
|
i++;
|
|
469
463
|
returner = Number(str.substring(0, decimalIndex + digits + 1 + i));
|
|
470
464
|
}
|
|
471
|
-
|
|
465
|
+
if (Math.abs(number) < 1e-4) {
|
|
466
|
+
let f_i = 0;
|
|
467
|
+
let l_i = 0;
|
|
468
|
+
let d_i = 0;
|
|
469
|
+
let i2 = 0;
|
|
470
|
+
while (d_i <= digits) {
|
|
471
|
+
if (str[i2] != "0" && str[i2] != ".") {
|
|
472
|
+
d_i += 1;
|
|
473
|
+
if (f_i == 0) {
|
|
474
|
+
f_i = i2;
|
|
475
|
+
}
|
|
476
|
+
;
|
|
477
|
+
}
|
|
478
|
+
i2 += 1;
|
|
479
|
+
}
|
|
480
|
+
l_i = i2;
|
|
481
|
+
return str[f_i] + "." + str.substring(f_i + 1, f_i + digits) + "e-" + (f_i - decimalIndex);
|
|
482
|
+
}
|
|
483
|
+
return Number(`${returner}`.substring(0, decimalIndex + digits + 1));
|
|
472
484
|
}
|
|
473
485
|
var Capability = {
|
|
474
486
|
/**
|
|
@@ -479,7 +491,6 @@ var Capability = {
|
|
|
479
491
|
* @param subgroupSize The size of the subgroup to use for calculating within standard deviation
|
|
480
492
|
*/
|
|
481
493
|
Analysis(data, spec, subgroupSize = 2) {
|
|
482
|
-
console.log(spec);
|
|
483
494
|
return {
|
|
484
495
|
Cp: Capability.Cp(data, spec, subgroupSize),
|
|
485
496
|
Cpk: Capability.Cpk(data, spec, subgroupSize),
|
|
@@ -523,6 +534,61 @@ var Capability = {
|
|
|
523
534
|
return Number(min / (3 * standarddeviation));
|
|
524
535
|
},
|
|
525
536
|
/**
|
|
537
|
+
* Evaluates the capability index Cpk(overall).
|
|
538
|
+
* @customfunction
|
|
539
|
+
* @param data The data to evaluate.
|
|
540
|
+
* @param spec The specification to evaluate the capability against.
|
|
541
|
+
* @param target The target value of the process
|
|
542
|
+
*/
|
|
543
|
+
Cpm(data, spec, target) {
|
|
544
|
+
return Math.min(spec.USL - target, target - spec.LSL) / (3 * Math.sqrt(SumSquaredDeviation(data, target) / data.length));
|
|
545
|
+
},
|
|
546
|
+
/**
|
|
547
|
+
* Calculates the defective parts per million.
|
|
548
|
+
* @customfunction
|
|
549
|
+
* @param data The data to evaluate.
|
|
550
|
+
* @param spec The specification to evaluate against.
|
|
551
|
+
* @param confidenceInterval [OPTIONAL] The desired confidence level of the analysis. DEFAULT = 0.95 (95%)
|
|
552
|
+
*/
|
|
553
|
+
DPPM(data, spec, confidenceInterval = 0.95) {
|
|
554
|
+
let mean = Mean(data);
|
|
555
|
+
let std = StDev.S(data);
|
|
556
|
+
let a = 1 - confidenceInterval;
|
|
557
|
+
let Z_1_a2 = Distributions.Normal.inv(1 - a / 2);
|
|
558
|
+
let Z_lsl = (mean - spec.LSL) / std;
|
|
559
|
+
let Z_usl = (spec.USL - mean) / std;
|
|
560
|
+
let v = data.length - 1;
|
|
561
|
+
let UL = Z_lsl + Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_lsl, 2) / (2 * v));
|
|
562
|
+
let LL = Z_lsl - Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_lsl, 2) / (2 * v));
|
|
563
|
+
let UU = Z_usl + Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_usl, 2) / (2 * v));
|
|
564
|
+
let LU = Z_usl - Z_1_a2 * Math.sqrt(1 / data.length + Math.pow(Z_usl, 2) / (2 * v));
|
|
565
|
+
let PPM_L = (1 - Distributions.Normal.cdf((mean - spec.LSL) / std, 0, 1)) * 1e6;
|
|
566
|
+
let PPM_U = (1 - Distributions.Normal.cdf((spec.USL - mean) / std, 0, 1)) * 1e6;
|
|
567
|
+
let p_hat = 1 - Distributions.Normal.cdf((mean - spec.LSL) / std, 0, 1) + (1 - Distributions.Normal.cdf((mean - spec.USL) / std, 0, 1));
|
|
568
|
+
let ln_p = Math.log(p_hat / (1 - p_hat));
|
|
569
|
+
let part_p_u = 1 / (p_hat * (1 - p_hat)) * (1 / std) * (Distributions.Normal.pdf((spec.USL - mean) / std) - Distributions.Normal.pdf((spec.LSL - mean) / std));
|
|
570
|
+
let part_p_v = 0.5 * (1 / (p_hat * (1 - p_hat))) * ((spec.USL - mean) / Math.pow(std, 3) * Distributions.Normal.pdf((spec.USL - mean) / std) - (spec.LSL - mean) / Math.pow(std, 3) * Distributions.Normal.pdf((spec.LSL - mean) / std));
|
|
571
|
+
let V_hat = Math.pow(part_p_u, 2) * Math.pow(std, 2) / mean + Math.pow(part_p_v, 2) * 2 * Math.pow(std, 4) / v;
|
|
572
|
+
let returner = {
|
|
573
|
+
LSL: {
|
|
574
|
+
PPM: PPM_L,
|
|
575
|
+
LB: 1e6 * (1 - Distributions.Normal.cdf(UL, 0, 1)),
|
|
576
|
+
UB: 1e6 * (1 - Distributions.Normal.cdf(LL, 0, 1))
|
|
577
|
+
},
|
|
578
|
+
USL: {
|
|
579
|
+
PPM: PPM_U,
|
|
580
|
+
LB: 1e6 * (1 - Distributions.Normal.cdf(UU, 0, 1)),
|
|
581
|
+
UB: 1e6 * (1 - Distributions.Normal.cdf(LU, 0, 1))
|
|
582
|
+
},
|
|
583
|
+
Total: {
|
|
584
|
+
PPM: PPM_L + PPM_U,
|
|
585
|
+
LB: Math.exp(ln_p - Z_1_a2 * Math.sqrt(V_hat)) / (1 + Math.exp(ln_p - Z_1_a2 * Math.sqrt(V_hat))) * 1e6,
|
|
586
|
+
UB: Math.exp(ln_p + Z_1_a2 * Math.sqrt(V_hat)) / (1 + Math.exp(ln_p + Z_1_a2 * Math.sqrt(V_hat))) * 1e6
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
return returner;
|
|
590
|
+
},
|
|
591
|
+
/**
|
|
526
592
|
* Evaluates the capability index Pp(within).
|
|
527
593
|
* @customfunction
|
|
528
594
|
* @param data The data to evaluate.
|
|
@@ -739,9 +805,11 @@ function CreateCapabilityPlot(data, specification) {
|
|
|
739
805
|
];
|
|
740
806
|
AddInfoTable(ctx, overallInfo, 3 * chartSettings.width / 4, chartSettings.margins.top, chartSettings.width / 4, chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom, "Overall");
|
|
741
807
|
const mean = Mean(data);
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
AddLinePlot(ctx,
|
|
808
|
+
let plotMin = !isNaN(specification.LSL) ? specification.LSL : Math.max(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
809
|
+
let plotMax = !isNaN(specification.USL) ? specification.USL : Math.min(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
810
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Overall");
|
|
811
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top + 40 + (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Within");
|
|
812
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [specification.LSL, specification.USL], chartSettings.width / 4 + 25, chartSettings.margins.top + 80 + 2 * (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Specs");
|
|
745
813
|
return canvas;
|
|
746
814
|
}
|
|
747
815
|
var Beta = {
|
|
@@ -2261,7 +2329,6 @@ var GoodnessOfFit = {
|
|
|
2261
2329
|
if (ADStar <= 0.2) {
|
|
2262
2330
|
p = 1 - Math.exp(-13.436 + 101.14 * ADStar - 223.73 * Math.pow(ADStar, 2));
|
|
2263
2331
|
}
|
|
2264
|
-
console.log(p, p > 1 || p < 5e-3);
|
|
2265
2332
|
return p > 1 || p < 5e-3 ? "<0.005" : p;
|
|
2266
2333
|
},
|
|
2267
2334
|
/**
|
|
@@ -2485,11 +2552,10 @@ function Median(data) {
|
|
|
2485
2552
|
}
|
|
2486
2553
|
function MovingRange(data, w = 2) {
|
|
2487
2554
|
let movingRange = [];
|
|
2488
|
-
for (let i =
|
|
2489
|
-
let h = i - w + 1;
|
|
2555
|
+
for (let i = 0; i < data.length + 1 - w; i++) {
|
|
2490
2556
|
let values = [];
|
|
2491
2557
|
for (let j = 0; j < w; j++) {
|
|
2492
|
-
values.push(Number(data[
|
|
2558
|
+
values.push(Number(data[i + j]));
|
|
2493
2559
|
}
|
|
2494
2560
|
movingRange.push(CalculateRange(values));
|
|
2495
2561
|
}
|
package/index.ts
CHANGED
|
@@ -132,23 +132,23 @@ export class Specification{
|
|
|
132
132
|
tol_minus = Number(tol);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
if(!Number.isNaN(nominal) && !Number.isNaN(tol_plus) && !Number.isNaN(tol_minus)){
|
|
136
|
-
|
|
135
|
+
// if(!Number.isNaN(nominal) && !Number.isNaN(tol_plus) && !Number.isNaN(tol_minus)){
|
|
136
|
+
// USL = nominal + tol_plus;
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
// // Round USL
|
|
139
|
+
// let digits = String(tol_plus).split(".");
|
|
140
|
+
// digits[1] = digits[1] ?? "0";
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
// USL = Number(USL).toFixed(digits[1].length);
|
|
143
143
|
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
// LSL = nominal - tol_minus;
|
|
146
|
+
// // Round LSL
|
|
147
|
+
// digits = String(tol_minus).split(".");
|
|
148
|
+
// digits[1] = digits[1] ?? "0";
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
}
|
|
150
|
+
// LSL = Number(LSL).toFixed(digits[1].length);
|
|
151
|
+
// }
|
|
152
152
|
|
|
153
153
|
if (tol) {
|
|
154
154
|
return {
|
|
@@ -522,14 +522,35 @@ export function RoundTO(number: number, digits: number){
|
|
|
522
522
|
}
|
|
523
523
|
let str = number.toString();
|
|
524
524
|
let decimalIndex = str.indexOf('.');
|
|
525
|
+
let roundFinalDigit = Number(str.substring(decimalIndex + digits + 2,decimalIndex + digits + 3)) >= 5
|
|
526
|
+
|
|
525
527
|
let returner = Number(str.substring(0, decimalIndex + digits + 1));
|
|
526
|
-
|
|
528
|
+
if(roundFinalDigit){
|
|
529
|
+
returner = returner + Math.pow(10,-1*digits)
|
|
530
|
+
}
|
|
531
|
+
|
|
527
532
|
let i = 0;
|
|
528
533
|
while(returner === 0){
|
|
529
534
|
i++;
|
|
530
535
|
returner = Number(str.substring(0, decimalIndex + digits + 1 + i));
|
|
531
536
|
}
|
|
532
|
-
|
|
537
|
+
if(Math.abs(number) < .0001){
|
|
538
|
+
let f_i = 0;
|
|
539
|
+
let l_i = 0;
|
|
540
|
+
let d_i = 0;
|
|
541
|
+
let i = 0;
|
|
542
|
+
while(d_i <= digits){
|
|
543
|
+
if(str[i] != "0" && str[i] != "."){
|
|
544
|
+
d_i += 1;
|
|
545
|
+
if(f_i == 0){f_i = i};
|
|
546
|
+
}
|
|
547
|
+
i += 1
|
|
548
|
+
}
|
|
549
|
+
l_i = i;
|
|
550
|
+
|
|
551
|
+
return str[f_i] + "." + str.substring(f_i + 1, f_i + digits) + "e-" + (f_i - decimalIndex);
|
|
552
|
+
}
|
|
553
|
+
return Number(`${returner}`.substring(0, decimalIndex + digits + 1))
|
|
533
554
|
}
|
|
534
555
|
|
|
535
556
|
// End Classes
|
|
@@ -546,7 +567,6 @@ export const Capability = {
|
|
|
546
567
|
* @param subgroupSize The size of the subgroup to use for calculating within standard deviation
|
|
547
568
|
*/
|
|
548
569
|
Analysis(data: number[], spec: Specification, subgroupSize: number = 2){
|
|
549
|
-
console.log(spec)
|
|
550
570
|
return {
|
|
551
571
|
Cp: Capability.Cp(data, spec, subgroupSize),
|
|
552
572
|
Cpk: Capability.Cpk(data, spec, subgroupSize),
|
|
@@ -592,6 +612,64 @@ export const Capability = {
|
|
|
592
612
|
|
|
593
613
|
},
|
|
594
614
|
/**
|
|
615
|
+
* Evaluates the capability index Cpk(overall).
|
|
616
|
+
* @customfunction
|
|
617
|
+
* @param data The data to evaluate.
|
|
618
|
+
* @param spec The specification to evaluate the capability against.
|
|
619
|
+
* @param target The target value of the process
|
|
620
|
+
*/
|
|
621
|
+
Cpm(data: number[], spec: Specification, target: number){
|
|
622
|
+
return Math.min(spec.USL - target, target - spec.LSL)/(3*Math.sqrt(SumSquaredDeviation(data, target)/data.length))
|
|
623
|
+
},
|
|
624
|
+
/**
|
|
625
|
+
* Calculates the defective parts per million.
|
|
626
|
+
* @customfunction
|
|
627
|
+
* @param data The data to evaluate.
|
|
628
|
+
* @param spec The specification to evaluate against.
|
|
629
|
+
* @param confidenceInterval [OPTIONAL] The desired confidence level of the analysis. DEFAULT = 0.95 (95%)
|
|
630
|
+
*/
|
|
631
|
+
DPPM(data: number[], spec: Specification, confidenceInterval: number = 0.95){
|
|
632
|
+
let mean = Mean(data)
|
|
633
|
+
let std = StDev.S(data)
|
|
634
|
+
let a = 1 - confidenceInterval
|
|
635
|
+
let Z_1_a2 = Distributions.Normal.inv(1 - a/2);
|
|
636
|
+
let Z_lsl = (mean - spec.LSL)/std
|
|
637
|
+
let Z_usl = (spec.USL - mean)/std
|
|
638
|
+
let v = data.length - 1
|
|
639
|
+
let UL = Z_lsl + Z_1_a2 * Math.sqrt(1/data.length + Math.pow(Z_lsl, 2)/(2*v))
|
|
640
|
+
let LL = Z_lsl - Z_1_a2 * Math.sqrt(1/data.length + Math.pow(Z_lsl, 2)/(2*v))
|
|
641
|
+
let UU = Z_usl + Z_1_a2 * Math.sqrt(1/data.length + Math.pow(Z_usl, 2)/(2*v))
|
|
642
|
+
let LU = Z_usl - Z_1_a2 * Math.sqrt(1/data.length + Math.pow(Z_usl, 2)/(2*v))
|
|
643
|
+
let PPM_L = (1 - Distributions.Normal.cdf((mean - spec.LSL)/std, 0, 1)) * 1000000
|
|
644
|
+
let PPM_U = (1 - Distributions.Normal.cdf((spec.USL - mean)/std, 0, 1)) * 1000000
|
|
645
|
+
|
|
646
|
+
let p_hat = (1 - Distributions.Normal.cdf((mean - spec.LSL)/std, 0, 1)) + (1 - Distributions.Normal.cdf((mean - spec.USL)/std, 0, 1))
|
|
647
|
+
let ln_p = Math.log(p_hat/(1 - p_hat));
|
|
648
|
+
let part_p_u = (1/(p_hat * (1 - p_hat))) * (1/std) * (Distributions.Normal.pdf((spec.USL - mean)/std) - Distributions.Normal.pdf((spec.LSL - mean)/std))
|
|
649
|
+
let part_p_v = .5 * (1/(p_hat * (1 - p_hat))) * ( (spec.USL - mean)/Math.pow(std, 3) * Distributions.Normal.pdf((spec.USL - mean)/std) - (spec.LSL - mean)/Math.pow(std, 3) * Distributions.Normal.pdf((spec.LSL - mean)/std))
|
|
650
|
+
let V_hat = Math.pow(part_p_u,2) * Math.pow(std, 2)/mean + Math.pow(part_p_v, 2) * 2 * Math.pow(std, 4)/v
|
|
651
|
+
|
|
652
|
+
let returner = {
|
|
653
|
+
LSL: {
|
|
654
|
+
PPM: PPM_L,
|
|
655
|
+
LB: 1000000 * (1 - Distributions.Normal.cdf(UL, 0, 1)),
|
|
656
|
+
UB: 1000000 * (1 - Distributions.Normal.cdf(LL, 0, 1)),
|
|
657
|
+
},
|
|
658
|
+
USL: {
|
|
659
|
+
PPM: PPM_U,
|
|
660
|
+
LB: 1000000 * (1 - Distributions.Normal.cdf(UU, 0, 1)),
|
|
661
|
+
UB: 1000000 * (1 - Distributions.Normal.cdf(LU, 0, 1)),
|
|
662
|
+
},
|
|
663
|
+
Total: {
|
|
664
|
+
PPM: PPM_L + PPM_U,
|
|
665
|
+
LB: Math.exp(ln_p - Z_1_a2*Math.sqrt(V_hat))/(1 + Math.exp(ln_p - Z_1_a2*Math.sqrt(V_hat))) * 1000000,
|
|
666
|
+
UB: Math.exp(ln_p + Z_1_a2*Math.sqrt(V_hat))/(1 + Math.exp(ln_p + Z_1_a2*Math.sqrt(V_hat))) * 1000000
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return returner
|
|
671
|
+
},
|
|
672
|
+
/**
|
|
595
673
|
* Evaluates the capability index Pp(within).
|
|
596
674
|
* @customfunction
|
|
597
675
|
* @param data The data to evaluate.
|
|
@@ -855,13 +933,17 @@ export function CreateCapabilityPlot(data: number[], specification: Specificatio
|
|
|
855
933
|
AddInfoTable(ctx, overallInfo, 3*chartSettings.width/4, chartSettings.margins.top, chartSettings.width/4, chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom, "Overall");
|
|
856
934
|
|
|
857
935
|
const mean = Mean(data);
|
|
936
|
+
let plotMin = !isNaN(specification.LSL) ? specification.LSL : Math.max(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
937
|
+
let plotMax = !isNaN(specification.USL) ? specification.USL : Math.min(mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value, mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value);
|
|
938
|
+
|
|
858
939
|
// Add Overall Line Plot
|
|
859
|
-
AddLinePlot(ctx,
|
|
860
|
-
|
|
940
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * overallInfo[0].value, mean + 3 * overallInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Overall");
|
|
941
|
+
|
|
861
942
|
// Add Within Line Plot
|
|
862
|
-
AddLinePlot(ctx,
|
|
943
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [mean - 3 * withinInfo[0].value, mean + 3 * withinInfo[0].value], chartSettings.width / 4 + 25, chartSettings.margins.top + 40 + (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Within");
|
|
944
|
+
|
|
863
945
|
// Add Specs Line Plot
|
|
864
|
-
AddLinePlot(ctx,
|
|
946
|
+
AddLinePlot(ctx, plotMin, plotMax, mean, [specification.LSL, specification.USL], chartSettings.width / 4 + 25, chartSettings.margins.top + 80 + 2 * (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3, chartSettings.width / 2 - 50, (chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom) / 3 - 10, "Specs");
|
|
865
947
|
return canvas;
|
|
866
948
|
}
|
|
867
949
|
|
|
@@ -2427,7 +2509,6 @@ export const GoodnessOfFit = {
|
|
|
2427
2509
|
if (ADStar <= .2) {
|
|
2428
2510
|
p = 1 - Math.exp(-13.436 + 101.14 * ADStar - 223.73 * Math.pow(ADStar, 2))
|
|
2429
2511
|
}
|
|
2430
|
-
console.log(p, p > 1 || p < 0.005)
|
|
2431
2512
|
return p > 1 || p < 0.005 ? "<0.005" : p;
|
|
2432
2513
|
},
|
|
2433
2514
|
/**
|
|
@@ -2800,12 +2881,10 @@ export function Median(data: any[]){
|
|
|
2800
2881
|
export function MovingRange(data: any[], w: number = 2){
|
|
2801
2882
|
let movingRange: number[] = [];
|
|
2802
2883
|
|
|
2803
|
-
for(let i =
|
|
2804
|
-
let h = i - w + 1;
|
|
2805
|
-
|
|
2884
|
+
for(let i = 0; i < data.length + 1 - w; i++){
|
|
2806
2885
|
let values: number[] = [];
|
|
2807
2886
|
for(let j = 0; j < w; j++){
|
|
2808
|
-
values.push(Number(data[
|
|
2887
|
+
values.push(Number(data[i + j]));
|
|
2809
2888
|
}
|
|
2810
2889
|
|
|
2811
2890
|
movingRange.push(CalculateRange(values))
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Fixed rounding bug in ParseSpec()
|