qesuite 1.0.1 → 1.0.2

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/classes.ts ADDED
@@ -0,0 +1,240 @@
1
+ import { Mean } from ".";
2
+
3
+ // Specification Classes
4
+ export class QESpecification{
5
+ constructor(spec: any, USL: number = NaN, LSL: number = NaN, tolerance: number = NaN, tol_plus: number = NaN, tol_minus: number = NaN, units: string = ''){
6
+ if(Number.isNaN(Number(spec))){
7
+ let parsed = this.ParseSpec(spec);
8
+ this.nominal = parsed.nominal;
9
+ this.USL = parsed.USL;
10
+ this.LSL = parsed.LSL;
11
+ this.tolerance = parsed.tolerance ?? NaN;
12
+ this.tol_plus = parsed.tol_plus ?? NaN;
13
+ this.tol_minus = parsed.tol_minus ?? NaN;
14
+ this.units = parsed.units ?? '';
15
+ }else{
16
+ this.nominal = spec;
17
+ this.USL = USL;
18
+ this.LSL = LSL;
19
+ this.tolerance = tolerance;
20
+ this.tol_plus = tol_plus;
21
+ this.tol_minus = tol_minus;
22
+ this.units = units;
23
+ }
24
+
25
+ }
26
+
27
+ nominal: number;
28
+ USL: number;
29
+ LSL: number;
30
+ units: string;
31
+ tolerance: number;
32
+ tol_plus: number;
33
+ tol_minus: number;
34
+
35
+ // methods
36
+ ParseSpec(spec: string) {
37
+ // This function parses specs and returns an array of values, in this order:
38
+ // Nominal, USL, LSL, Units, Tolerance(if UT and LT differ then {UT, LT})
39
+ let string = spec;
40
+ let nominal;
41
+ let USL;
42
+ let LSL;
43
+ let tol_plus;
44
+ let tol_minus;
45
+ let tol;
46
+ let units;
47
+
48
+ if (string.indexOf("±") !== -1) {
49
+ nominal = Number(string.substring(0, string.indexOf("±")).replace("Ø", ""));
50
+ let after = this.SplitUnits(string.substring(string.indexOf("±") + 1));
51
+ tol = Number(after[0]);
52
+ units = after[1];
53
+ tol_plus = Number(tol);
54
+ tol_minus = Number(tol);
55
+ }
56
+ if (string.indexOf("+") !== -1) {
57
+ tol_plus = Number(this.SplitUnits(string.substring(string.indexOf("+") + 1))[0]);
58
+ nominal = Number(this.SplitUnits(string)[0]);
59
+ }
60
+ if (string.indexOf("-") !== -1) {
61
+ tol_minus = Number(this.SplitUnits(string.substring(string.indexOf("-") + 1))[0]);
62
+ nominal = Number(this.SplitUnits(string)[0]);
63
+ }
64
+ if (string.indexOf("+-") !== -1 || string.indexOf("+/-") !== -1) {
65
+ nominal = Number(string.substring(0, string.indexOf("+")));
66
+ let after = this.SplitUnits(string.substring(string.indexOf("-") + 1));
67
+ tol = Number(after[0]);
68
+ units = after[1];
69
+ tol_plus = Number(tol);
70
+ tol_minus = Number(tol);
71
+ }
72
+ if (string.indexOf("-+") !== -1 || string.indexOf("-/+") !== -1) {
73
+ nominal = Number(string.substring(0, string.indexOf("-")));
74
+ let after = this.SplitUnits(string.substring(string.indexOf("+") + 1));
75
+ tol = Number(after[0]);
76
+ units = after[1];
77
+ tol_plus = Number(tol);
78
+ tol_minus = Number(tol);
79
+ }
80
+
81
+ if(nominal && tol_plus && tol_minus){
82
+ USL = nominal + tol_plus;
83
+ // Round USL
84
+ let digits = String(tol_plus).split(".");
85
+
86
+ USL = Number(USL).toFixed(digits[1].length);
87
+
88
+
89
+ LSL = nominal - tol_minus;
90
+ // Round LSL
91
+ digits = String(tol_minus).split(".");
92
+
93
+ LSL = Number(LSL).toFixed(digits[1].length);
94
+ }
95
+
96
+ if (tol) {
97
+ return {
98
+ nominal: nominal ?? NaN,
99
+ USL: USL ?? NaN,
100
+ LSL: LSL ?? NaN,
101
+ units: units ?? '',
102
+ tolerance: tol ?? NaN
103
+ }
104
+ } else {
105
+ return {
106
+ nominal: nominal ?? NaN,
107
+ USL: USL ?? NaN,
108
+ LSL: LSL ?? NaN,
109
+ units: units,
110
+ tol_plus: tol_plus ?? NaN,
111
+ tol_minus: tol_minus ?? NaN
112
+ }
113
+ }
114
+ }
115
+ SplitUnits(string: string) {
116
+ let dim = "";
117
+ let units = "";
118
+ let isDim = true;
119
+ for (let i = 0; i < string.length; i++) {
120
+ if (!Number(string.substring(i, i + 1))) {
121
+ isDim = true;
122
+ if (string.substring(i, i + 1) === "." || string.substring(i, i + 1) === "0") {
123
+ isDim = true;
124
+ }
125
+ }
126
+ if (isDim) {
127
+ dim += string.substring(i, i + 1);
128
+ } else {
129
+ units += string.substring(i, i + 1);
130
+ }
131
+ }
132
+ return [dim, units]
133
+ }
134
+ }
135
+
136
+ // GRR Classes
137
+ export class GRR_Data{
138
+ constructor(operators: GRR_Operator[]){
139
+ this.operators = operators
140
+ }
141
+
142
+ operators: GRR_Operator[];
143
+
144
+ getPartsByIndex(index?: number){
145
+ let array: any[] = [];
146
+ this.operators.forEach(r => {
147
+ array = [...array, ...r.getPartsByIndex(index)]
148
+ })
149
+ return array;
150
+ }
151
+
152
+ getPartCount(){
153
+ let partCount = this.operators.map( r => {return r.getPartCount()});
154
+ return partCount.every(v => v === partCount[0]) ? partCount[0] : NaN;
155
+ }
156
+
157
+ getReplicationCount(){
158
+ let replicationCount = this.operators.map(o => {return o.replications.length})
159
+ return replicationCount.every(v => v === replicationCount[0]) ? replicationCount[0] : NaN;
160
+ }
161
+
162
+ getOperatorCount(){
163
+ return this.operators.length;
164
+ }
165
+
166
+ getOperatorMeans(){
167
+ return this.operators.map(o => {return o.getMean()})
168
+ }
169
+
170
+ getPartMeans(){
171
+ let N = this.getPartCount();
172
+ let partMeans: number[] = [];
173
+
174
+ let N_op = this.getOperatorCount();
175
+ let N_rep = this.getReplicationCount();
176
+
177
+ for(let i = 0; i < N; i++){
178
+ partMeans.push(Mean(this.getPartsByIndex(i)));
179
+ }
180
+ return partMeans;
181
+ }
182
+
183
+ getGrandMean(){
184
+ return Mean(this.getOperatorMeans());
185
+ }
186
+ }
187
+
188
+ export class GRR_Operator{
189
+ constructor(replications: GRR_Replication[], name?: string){
190
+ this.replications = replications;
191
+ this.name = name ?? '';
192
+ }
193
+ replications: GRR_Replication[];
194
+ name: string;
195
+
196
+ getPartsByIndex(index?: number){
197
+ let array: any[] = [];
198
+ this.replications.forEach(r => {
199
+ array = [...array, ...r.getPartsByIndex(index)]
200
+ })
201
+ return array;
202
+ }
203
+
204
+ getPartCount(){
205
+ let partCount = this.replications.map( r => {return r.getPartCount()});
206
+ return partCount.every(v => v === partCount[0]) ? partCount[0] : NaN;
207
+ }
208
+
209
+ getPartAverages(){
210
+ let partAverages: number[] = [];
211
+ let partCount = this.getPartCount();
212
+ for(let i = 0; i < partCount; i++){
213
+ let parts = this.getPartsByIndex(i);
214
+ partAverages.push(Mean(parts));
215
+ }
216
+ return partAverages;
217
+ }
218
+
219
+ getMean(){
220
+ return Mean(this.getPartAverages());
221
+ }
222
+ }
223
+
224
+ export class GRR_Replication{
225
+ constructor(parts: number[]){
226
+ this.parts = parts;
227
+ }
228
+ parts: number[];
229
+
230
+ getPartsByIndex(index?: number){
231
+ if(index === undefined){
232
+ return this.parts
233
+ }
234
+ return [this.parts[index]];
235
+ }
236
+
237
+ getPartCount(){
238
+ return this.parts.length
239
+ }
240
+ }