Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhauling null/invalid data handling - P1 #166

Merged
merged 5 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Classes/dataClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ export default class dataClass {
const valid_keys: { x: number, id: number, label: string }[] = new Array<{ x: number, id: number, label: string }>();

for (let i: number = 0; i < numerators.length; i++) {
if (checkValidInput(numerators[i],
denominators ? denominators[i] : null,
xbar_sds ? xbar_sds[i] : null, inputSettings.spc.chart_type)) {
const dateValid: boolean = keys[i] !== null;
const inputValid: boolean = checkValidInput(numerators[i],
denominators ? denominators[i] : null,
xbar_sds ? xbar_sds[i] : null,
inputSettings.spc.chart_type)
if (dateValid && inputValid) {
valid_ids.push(i);
valid_keys.push({ x: null, id: i, label: keys[i] })
}
Expand Down
17 changes: 14 additions & 3 deletions src/Classes/plotPropertiesClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class plotPropertiesClass {
? args.plotPoints.length > 1
: null;

const xLowerLimit: number = args.inputSettings.x_axis.xlimit_l;
let xLowerLimit: number = args.inputSettings.x_axis.xlimit_l;
let xUpperLimit: number = args.inputSettings.x_axis.xlimit_u;
let yLowerLimit: number = args.inputSettings.y_axis.ylimit_l;
let yUpperLimit: number = args.inputSettings.y_axis.ylimit_u;
Expand All @@ -83,13 +83,24 @@ export default class plotPropertiesClass {
const multiplier: number = args.inputSettings.spc.multiplier;

yUpperLimit = yUpperLimit !== null ? yUpperLimit :
args.inputSettings.spc.perc_labels
args.inputData.percentLabels
? truncate(upperLimitRaw, {upper: 1 * multiplier})
: upperLimitRaw;

yLowerLimit = yLowerLimit !== null ? yLowerLimit :
args.inputSettings.spc.perc_labels
args.inputData.percentLabels
? truncate(lowerLimitRaw, {lower: 0 * multiplier})
: lowerLimitRaw;

const keysToPlot: number[] = args.controlLimits.keys.map(d => d.x);

xLowerLimit = xLowerLimit !== null
? xLowerLimit
: d3.min(keysToPlot);

xUpperLimit = xUpperLimit !== null
? xUpperLimit
: d3.max(keysToPlot);
}

const xTickSize: number = args.inputSettings.x_axis.xlimit_tick_size;
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/viewModelClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class viewModelClass {
}
if (this.controlLimits.two_in_three[i] !== "none") {
aesthetics.colour = getAesthetic(this.controlLimits.two_in_three[i], "outliers",
"two_in_three_colour", this.inputSettings.settings) as string;
"twointhree_colour", this.inputSettings.settings) as string;
}
if (this.controlLimits.astpoint[i] !== "none") {
aesthetics.colour = getAesthetic(this.controlLimits.astpoint[i], "outliers",
Expand Down
8 changes: 4 additions & 4 deletions src/D3 Plotting Functions/drawXAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default function drawXAxis(selection: svgBaseType, visualObj: Visual, ref
xAxis.ticks(xAxisProperties.tick_count)
}
if (visualObj.viewModel.tickLabels) {
xAxis.tickFormat(d => {
return visualObj.viewModel.tickLabels.map(d => d.x).includes(<number>d)
? visualObj.viewModel.tickLabels[<number>d].label
: "";
xAxis.tickFormat(axisX => {
const targetKey = visualObj.viewModel.tickLabels.filter(d => d.x == <number>axisX);
return targetKey.length > 0 ? targetKey[0].label : "";

})
}
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/Functions/buildTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const integerParams: string[] = ["c", "p", "pp"];

export default function buildTooltip(index: number, controlLimits: controlLimitsClass,
inputData: dataClass, inputSettings: defaultSettingsType): VisualTooltipDataItem[] {

const chart_type: string = inputSettings.spc.chart_type;
const date: string = controlLimits.keys[index].label;
const value: number = controlLimits.values[index];
const numerator: number = controlLimits.numerators ? controlLimits.numerators[index] : null;
Expand All @@ -31,7 +31,6 @@ export default function buildTooltip(index: number, controlLimits: controlLimits
ll99: controlLimits.ll99 ? controlLimits.ll99[index] : null,
ul99: controlLimits.ll99 ? controlLimits.ul99[index] : null
};
const chart_type: string = inputSettings.spc.chart_type;
const prop_labels: boolean = inputData.percentLabels;
const astpoint: string = controlLimits.astpoint[index];
const trend: string = controlLimits.trend[index];
Expand Down
34 changes: 22 additions & 12 deletions src/Functions/checkValidInput.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
export default function checkValidInput(numerator: number, denominator: number, xbar_sd: number, data_type: string): boolean {
const denominatorConstraintRequired: string[] = ["p", "pprime", "u", "uprime"];
const denominatorRequired: string[] = ["p", "pprime", "u", "uprime", "xbar", "s"];
const denominatorConstraintForRunIChart: string[] = ["i", "run"];
let denominatorConstraintRequired: string[] = ["p", "pprime", "u", "uprime"];
let denominatorRequired: string[] = ["p", "pprime", "u", "uprime", "xbar", "s"];
const denominatorOptional: string[] = ["i", "run", "mr"];
const checkOptionalDenominator: boolean = denominatorOptional.includes(data_type) && !(denominator === null);
if (checkOptionalDenominator) {
denominatorConstraintRequired.push(data_type);
denominatorRequired.push(data_type);
}
const numeratorNonNegativeRequired: string[] = denominatorRequired.concat(["c"]);

const numeratorValid: boolean = numerator !== null && numerator !== undefined;
const denominatorValid: boolean = denominatorRequired.includes(data_type)
? denominator !== null && denominator !== undefined && denominator > 0
const denominatorValid: boolean
= denominatorRequired.includes(data_type)
? denominator !== null && denominator !== undefined && denominator >= 0
: true;
const proportionDenominatorValid: boolean = denominatorConstraintRequired.includes(data_type)
? (numerator <= denominator)
const numeratorNegativeValid: boolean
= numeratorNonNegativeRequired.includes(data_type)
? numerator >= 0
: true;
const runIChartDenominatorValid: boolean
= (denominatorConstraintForRunIChart.includes(data_type) && !(denominator === null))
? (denominator != 0)
const proportionDenominatorValid: boolean
= denominatorConstraintRequired.includes(data_type)
? (numerator <= denominator)
: true;
const xbarSDValid: boolean = data_type === "xbar" ? xbar_sd !== null && xbar_sd > 0 : true;
return numeratorValid && denominatorValid && proportionDenominatorValid && runIChartDenominatorValid && xbarSDValid;

const xbarSDValid: boolean = data_type === "xbar" ? xbar_sd !== null && xbar_sd >= 0 : true;
return numeratorValid && denominatorValid && proportionDenominatorValid && xbarSDValid && numeratorNegativeValid;
}

3 changes: 3 additions & 0 deletions src/Functions/dateToFormattedString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const localeDateMap: Record<string, string>= {

const dateToFormattedString = broadcastBinary(
(input_date: Date, date_settings: defaultSettingsType["dates"]): string => {
if (input_date === null) {
return null;
}
if (typeof input_date === "string") {
input_date = new Date(input_date)
}
Expand Down
5 changes: 4 additions & 1 deletion src/Functions/extractDataColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default function extractDataColumn<T extends TargetT>(inputView: DataView
// If a 'Date Hierarchy' type is passed then there will be multiple 'key" entries
if (columnRawTmp.length > 1) {
return columnRawTmp[columnRawTmp.length - 1].values.map((lastKeyValue: powerbi.PrimitiveValue, index) => {
if (lastKeyValue === null) {
return null
}
let concatKey: string = <string>lastKeyValue;
for (let i = (columnRawTmp.length - 2); i >= 0; i--) {
concatKey += " " + columnRawTmp[i].values[index];
Expand Down Expand Up @@ -57,6 +60,6 @@ export default function extractDataColumn<T extends TargetT>(inputView: DataView
return viewColumn.source.roles ? viewColumn.source.roles[name] : false;
})[0];

return (columnRaw ? columnRaw.values : null) as T;
return (columnRaw ? columnRaw.values.map(d => d === null ? null : Number(d)) : null) as T;
}
}
8 changes: 4 additions & 4 deletions src/Limit Calculations/mr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default function mrLimits(inputData: dataClass, inputSettings: defaultSet

return new controlLimitsClass({
inputSettings: inputSettings,
keys: inputData.keys,
values: consec_diff,
numerators: useRatio ? inputData.numerators : undefined,
denominators: useRatio ? inputData.denominators : undefined,
keys: inputData.keys.slice(1),
values: consec_diff.slice(1),
numerators: useRatio ? inputData.numerators.slice(1) : undefined,
denominators: useRatio ? inputData.denominators.slice(1) : undefined,
targets: cl,
ll99: 0,
ll95: 0,
Expand Down
Loading