Skip to content
Merged
41 changes: 34 additions & 7 deletions frontend/src/app/shared/custom/scoring/scoring.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,46 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
const keyResult = this.keyResult as KeyResultMetricMin;
const lastCheckIn = keyResult.lastCheckIn?.value!;

if (lastCheckIn < keyResult.commitValue) {
if (keyResult.baseline === keyResult.stretchGoal) {
if (lastCheckIn >= keyResult.baseline) {
this.stretched = true;
this.failPercent = 100;
this.commitPercent = 100;
this.targetPercent = 100;
} else {
this.stretched = false;
this.failPercent = 0;
this.commitPercent = 0;
this.targetPercent = 0;
}
return;
}

// Decide comparison direction based on goal orientation
const increasing = keyResult.baseline < keyResult.stretchGoal;
const cmp = (a: number, b: number) => {
return increasing ? a < b : a > b;
};

if (cmp(lastCheckIn, keyResult.commitValue)) {
this.stretched = false;
this.failPercent = (lastCheckIn - keyResult.baseline) / (keyResult.commitValue - keyResult.baseline) * 100;
} else if (lastCheckIn < keyResult.targetValue) {
this.failPercent =
(lastCheckIn - keyResult.baseline) /
(keyResult.commitValue - keyResult.baseline) * 100;
} else if (cmp(lastCheckIn, keyResult.targetValue)) {
this.stretched = false;
this.failPercent = 100;
this.commitPercent = (lastCheckIn - keyResult.commitValue) / (keyResult.targetValue - keyResult.commitValue) * 100;
} else if (lastCheckIn < keyResult.stretchGoal) {
this.commitPercent =
(lastCheckIn - keyResult.commitValue) /
(keyResult.targetValue - keyResult.commitValue) * 100;
} else if (cmp(lastCheckIn, keyResult.stretchGoal)) {
this.stretched = false;
this.failPercent = 100;
this.commitPercent = 100;
this.targetPercent = (lastCheckIn - keyResult.targetValue) / (keyResult.stretchGoal - keyResult.targetValue) * 100;
} else if (lastCheckIn >= keyResult.stretchGoal) {
this.targetPercent =
(lastCheckIn - keyResult.targetValue) /
(keyResult.stretchGoal - keyResult.targetValue) * 100;
} else {
this.stretched = true;
}
}
Expand Down
Loading