Skip to content

Commit

Permalink
Calc 68%, option to show/hide
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Dec 21, 2023
1 parent 6784b6a commit 2a6e1e9
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 22 deletions.
30 changes: 30 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@
"lines": {
"displayName": "Line Settings",
"properties": {
"show_99": {
"displayName": "Show 99.8% Lines",
"type" : { "bool" : true }
},
"show_95": {
"displayName": "Show 95% Lines",
"type" : { "bool" : true }
},
"show_68": {
"displayName": "Show 68% Lines",
"type" : { "bool" : true }
},
"width_99": {
"displayName": "99.8% Line Width",
"type": { "numeric": true }
Expand All @@ -362,6 +374,10 @@
"displayName": "95% Line Width",
"type": { "numeric": true }
},
"width_68": {
"displayName": "68% Line Width",
"type": { "numeric": true }
},
"width_main": {
"displayName": "Main Line Width",
"type": { "numeric": true }
Expand Down Expand Up @@ -394,6 +410,16 @@
]
}
},
"type_68": {
"displayName": "68% Line Type",
"type": {
"enumeration" : [
{ "displayName" : "Solid", "value" : "10 0" },
{ "displayName" : "Dashed", "value" : "10 10" },
{ "displayName" : "Dotted", "value" : "2 5" }
]
}
},
"type_main": {
"displayName": "Main Line Type",
"type": {
Expand Down Expand Up @@ -432,6 +458,10 @@
"displayName": "95% Line Colour",
"type": { "fill": { "solid": { "color": true } } }
},
"colour_68":{
"displayName": "68% Line Colour",
"type": { "fill": { "solid": { "color": true } } }
},
"colour_main":{
"displayName": "Main Line Colour",
"type": { "fill": { "solid": { "color": true } } }
Expand Down
18 changes: 14 additions & 4 deletions src/Classes/viewModelClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type controlLimitsObject = {
targets: number[];
ll99?: number[];
ll95?: number[];
ll68?: number[];
ul68?: number[];
ul95?: number[];
ul99?: number[];
count?: number[];
Expand Down Expand Up @@ -133,7 +135,7 @@ export default class viewModelClass {
this.controlLimits = calcLimitsGrouped.reduce((all: controlLimitsObject, curr: controlLimitsObject) => {
const allInner: controlLimitsObject = all;
Object.entries(all).forEach((entry, idx) => {
if (this.inputSettings.settings.spc.chart_type !== "run" || !["ll99", "ll95", "ul95", "ul99"].includes(entry[0])) {
if (this.inputSettings.settings.spc.chart_type !== "run" || !["ll99", "ll95", "ll68", "ul68", "ul95", "ul99"].includes(entry[0])) {
allInner[entry[0]] = entry[1]?.concat(Object.entries(curr)[idx][1]);
}
})
Expand Down Expand Up @@ -190,7 +192,15 @@ export default class viewModelClass {
initialiseGroupedLines(): void {
let labels: string[] = ["targets", "values", "alt_targets"];

Check failure on line 193 in src/Classes/viewModelClass.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'labels' is never reassigned. Use 'const' instead
if (this.inputSettings.settings.spc.chart_type !== "run") {
labels = ["ll99", "ll95", "ul95", "ul99"].concat(labels);
if (this.inputSettings.settings.lines.show_99) {
labels.push("ll99", "ul99");
}
if (this.inputSettings.settings.lines.show_95) {
labels.push("ll95", "ul95");
}
if (this.inputSettings.settings.lines.show_68) {
labels.push("ll68", "ul68");
}
}

const formattedLines: lineData[] = new Array<lineData>();
Expand Down Expand Up @@ -221,7 +231,7 @@ export default class viewModelClass {
// Scale limits using provided multiplier
const multiplier: number = this.inputSettings.derivedSettings.multiplier;

["values", "targets", "ll99", "ll95", "ul95", "ul99"].forEach(limit => {
["values", "targets", "ll99", "ll95", "ll68", "ul68", "ul95", "ul99"].forEach(limit => {
this.controlLimits[limit] = multiply(this.controlLimits[limit], multiplier)
})

Expand All @@ -234,7 +244,7 @@ export default class viewModelClass {
upper: this.inputSettings.settings.spc.ul_truncate
};

["ll99", "ll95", "ul95", "ul99"].forEach(limit => {
["ll99", "ll95", "ll68", "ul68", "ul95", "ul99"].forEach(limit => {
this.controlLimits[limit] = truncate(this.controlLimits[limit], limits);
});
}
Expand Down
11 changes: 5 additions & 6 deletions src/Functions/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ export const a3 = broadcastUnary(
);

const b_helper = broadcastBinary(
(sampleSize: number, use95: boolean): number => {
const sigma: number = use95 ? 2 : 3;
(sampleSize: number, sigma: number): number => {
return (sigma * c5(sampleSize)) / c4(sampleSize);
}
)

export const b3 = broadcastBinary(
(sampleSize: number, use95: boolean): number => {
return 1 - b_helper(sampleSize, use95);
(sampleSize: number, sigma: number): number => {
return 1 - b_helper(sampleSize, sigma);
}
);

export const b4 = broadcastBinary(
(sampleSize: number, use95: boolean): number => {
return 1 + b_helper(sampleSize, use95);
(sampleSize: number, sigma: number): number => {
return 1 + b_helper(sampleSize, sigma);
}
);
2 changes: 2 additions & 0 deletions src/Functions/getAesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { defaultSettingsType } from "../Classes"
const lineNameMap: Record<string, string> = {
"ll99" : "99",
"ll95" : "95",
"ll68" : "68",
"ul68" : "68",
"ul95" : "95",
"ul99" : "99",
"targets" : "target",
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function cLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(cl, args.keys.length),
ll99: rep(truncate(cl - 3 * sigma, { lower: 0 }), args.keys.length),
ll95: rep(truncate(cl - 2 * sigma, { lower: 0 }), args.keys.length),
ll68: rep(truncate(cl - 1 * sigma, { lower: 0 }), args.keys.length),
ul68: rep(cl + 1*sigma, args.keys.length),
ul95: rep(cl + 2*sigma, args.keys.length),
ul99: rep(cl + 3*sigma, args.keys.length),
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default function gLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(median(args.numerators), args.keys.length),
ll99: rep(0, args.keys.length),
ll95: rep(0, args.keys.length),
ll68: rep(0, args.keys.length),
ul68: rep(cl + 1*sigma, args.keys.length),
ul95: rep(cl + 2*sigma, args.keys.length),
ul99: rep(cl + 3*sigma, args.keys.length)
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/i.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function iLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(cl, args.keys.length),
ll99: rep(cl - 3 * sigma, args.keys.length),
ll95: rep(cl - 2 * sigma, args.keys.length),
ll68: rep(cl - 1 * sigma, args.keys.length),
ul68: rep(cl + 1 * sigma, args.keys.length),
ul95: rep(cl + 2 * sigma, args.keys.length),
ul99: rep(cl + 3 * sigma, args.keys.length)
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/mr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function mrLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(cl, args.keys.length - 1),
ll99: rep(0, args.keys.length - 1),
ll95: rep(0, args.keys.length - 1),
ll68: rep(0, args.keys.length - 1),
ul68: rep((3.267 / 3) * 1 * cl, args.keys.length - 1),
ul95: rep((3.267 / 3) * 2 * cl, args.keys.length - 1),
ul99: rep(3.267 * cl, args.keys.length - 1)
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default function pLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(cl, args.keys.length),
ll99: truncate(subtract(cl, multiply(3, sigma)), {lower: 0}),
ll95: truncate(subtract(cl, multiply(2, sigma)), {lower: 0}),
ll68: truncate(subtract(cl, multiply(1, sigma)), {lower: 0}),
ul68: truncate(add(cl, multiply(1, sigma)), {upper: 1}),
ul95: truncate(add(cl, multiply(2, sigma)), {upper: 1}),
ul99: truncate(add(cl, multiply(3, sigma)), {upper: 1})
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/pprime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default function pprimeLimits(args: controlLimitsArgs): controlLimitsObje
targets: rep(cl, args.keys.length),
ll99: truncate(subtract(cl, multiply(3, sigma)), {lower: 0}),
ll95: truncate(subtract(cl, multiply(2, sigma)), {lower: 0}),
ll68: truncate(subtract(cl, multiply(1, sigma)), {lower: 0}),
ul68: truncate(add(cl, multiply(1, sigma)), {upper: 1}),
ul95: truncate(add(cl, multiply(2, sigma)), {upper: 1}),
ul99: truncate(add(cl, multiply(3, sigma)), {upper: 1})
};
Expand Down
16 changes: 6 additions & 10 deletions src/Limit Calculations/s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ export default function sLimits(args: controlLimitsArgs): controlLimitsObject {
// Calculate weighted SD
const cl: number = sqrt(sum(multiply(Nm1,pow(group_sd,2))) / sum(Nm1));

// Sample-size dependent constant
const B3: number[] = b3(count_per_group, false);
const B395: number[] = b3(count_per_group, true);
const B4: number[] = b4(count_per_group, false);
const B495: number[] = b4(count_per_group, true);

return {
keys: args.keys,
values: group_sd,
targets: rep(cl, args.keys.length),
ll99: multiply(cl, B3),
ll95: multiply(cl, B395),
ul95: multiply(cl, B495),
ul99: multiply(cl, B4)
ll99: multiply(cl, b3(count_per_group, 3)),
ll95: multiply(cl, b3(count_per_group, 2)),
ll68: multiply(cl, b3(count_per_group, 1)),
ul68: multiply(cl, b4(count_per_group, 1)),
ul95: multiply(cl, b4(count_per_group, 2)),
ul99: multiply(cl, b4(count_per_group, 3))
};
}
2 changes: 2 additions & 0 deletions src/Limit Calculations/t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default function tLimits(args: controlLimitsArgs): controlLimitsObject {
limits.values = pow(limits.values, 3.6);
limits.ll99 = truncate(pow(limits.ll99, 3.6), {lower: 0});
limits.ll95 = truncate(pow(limits.ll95, 3.6), {lower: 0});
limits.ll68 = truncate(pow(limits.ll68, 3.6), {lower: 0});
limits.ul68 = pow(limits.ul68, 3.6);
limits.ul95 = pow(limits.ul95, 3.6);
limits.ul99 = pow(limits.ul99, 3.6);

Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/u.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default function uLimits(args: controlLimitsArgs): controlLimitsObject {
targets: rep(cl, args.keys.length),
ll99: truncate(subtract(cl, multiply(3, sigma)), {lower: 0}),
ll95: truncate(subtract(cl, multiply(2, sigma)), {lower: 0}),
ll68: truncate(subtract(cl, multiply(1, sigma)), {lower: 0}),
ul68: add(cl, multiply(1, sigma)),
ul95: add(cl, multiply(2, sigma)),
ul99: add(cl, multiply(3, sigma))
}
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/uprime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default function uprimeLimits(args: controlLimitsArgs): controlLimitsObje
targets: rep(cl, args.keys.length),
ll99: truncate(subtract(cl, multiply(3,sigma)), {lower: 0}),
ll95: truncate(subtract(cl, multiply(2,sigma)), {lower: 0}),
ll68: truncate(subtract(cl, multiply(1,sigma)), {lower: 0}),
ul68: add(cl, multiply(1,sigma)),
ul95: add(cl, multiply(2,sigma)),
ul99: add(cl, multiply(3,sigma))
};
Expand Down
2 changes: 2 additions & 0 deletions src/Limit Calculations/xbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function xbarLimits(args: controlLimitsArgs): controlLimitsObject
targets: rep(cl, args.keys.length),
ll99: subtract(cl, multiply(A3, sd)),
ll95: subtract(cl, multiply(multiply(divide(A3, 3), 2), sd)),
ll68: subtract(cl, multiply(divide(A3, 3), sd)),
ul68: add(cl, multiply(divide(A3, 3), sd)),
ul95: add(cl, multiply(multiply(divide(A3, 3), 2), sd)),
ul99: add(cl, multiply(A3, sd)),
count: count_per_group
Expand Down
11 changes: 9 additions & 2 deletions src/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ const defaultSettings = {
opacity_unselected: 0.2
},
lines: {
show_99: true,
show_95: true,
show_68: false,
width_99: 2,
width_95: 2,
width_68: 2,
width_main: 1,
width_target: 1.5,
width_alt_target: 1.5,
type_99: "10 10",
type_95: "2 5",
type_68: "2 5",
type_main: "10 0",
type_target: "10 0",
type_alt_target: "10 0",
colour_99: "#6495ED",
colour_95: "#6495ED",
colour_68: "#6495ED",
colour_main: "#000000",
colour_target: "#000000",
colour_alt_target: "#000000"
Expand Down Expand Up @@ -130,8 +136,9 @@ export const settingsPaneGroupings = {
lines: {
"Main": ["width_main", "type_main", "colour_main"],
"Target(s)": ["width_target", "type_target", "colour_target", "width_alt_target", "type_alt_target", "colour_alt_target"],
"95% Limits": ["width_95", "type_95", "colour_95"],
"99% Limits": ["width_99", "type_99", "colour_99"]
"68% Limits": ["show_68", "width_68", "type_68", "colour_68"],
"95% Limits": ["show_95", "width_95", "type_95", "colour_95"],
"99% Limits": ["show_99", "width_99", "type_99", "colour_99"]
},
x_axis: {
"Axis": ["xlimit_colour", "xlimit_l", "xlimit_u"],
Expand Down

0 comments on commit 2a6e1e9

Please sign in to comment.