Skip to content
Merged
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/check-in.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('okr check-in', () => {
.setCheckInConfidence(5)
.submit();

cy.contains('5%');
cy.contains('Aktuell: 5%');
cy.contains('!');
cy.contains('5/10');
cy.contains('Letztes Check-in (' + getCurrentDate() + ')');
Expand Down
14 changes: 14 additions & 0 deletions frontend/cypress/e2e/scoring.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ describe('okr scoring', () => {
70,
100,
100
],
[
0,
-30,
-70,
-100,
-70
],
[
0,
-30,
-70,
-100,
-29.9
]
].forEach(([
baseline,
Expand Down
33 changes: 24 additions & 9 deletions frontend/cypress/support/helper/scoringSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,41 +158,56 @@ function scoringValueFromPercentageOrdinal(percentage: number): ScoringValue {
}

function colorFromPercentageMetric(keyResult: CheckInValue) {
if (keyResult.lastCheckIn < keyResult.commitValue) {
const compare = createComparator(keyResult);

if (compare(keyResult.lastCheckIn, keyResult.commitValue)) {
return 'rgb(186, 56, 56)';
} else if (keyResult.lastCheckIn < keyResult.targetValue) {
} else if (compare(keyResult.lastCheckIn, keyResult.targetValue)) {
return 'rgb(255, 214, 0)';
} else if (keyResult.lastCheckIn < keyResult.stretchGoal) {
} else if (compare(keyResult.lastCheckIn, keyResult.stretchGoal)) {
return 'rgb(30, 138, 41)';
} else if (keyResult.lastCheckIn >= keyResult.stretchGoal) {
} else {
return 'rgba(0, 0, 0, 0)';
}
}

function scoringValueFromPercentageMetric(keyResult: CheckInValue, percentage: number): ScoringValue {
if (keyResult.lastCheckIn < keyResult.commitValue) {
function scoringValueFromPercentageMetric(keyResult: CheckInValue,
percentage: number): ScoringValue {
const compare = createComparator(keyResult);

if (compare(keyResult.lastCheckIn, keyResult.commitValue)) {
return {
failPercent: percentage * (100 / 30),
commitPercent: -1,
targetPercent: -1
};
} else if (keyResult.lastCheckIn < keyResult.targetValue) {
} else if (compare(keyResult.lastCheckIn, keyResult.targetValue)) {
return {
failPercent: 100,
commitPercent: (percentage - 30) * (100 / 40),
targetPercent: -1
};
} else if (keyResult.lastCheckIn < keyResult.stretchGoal) {
} else if (compare(keyResult.lastCheckIn, keyResult.stretchGoal)) {
return {
failPercent: 100,
commitPercent: 100,
targetPercent: (percentage - 70) * (100 / 30)
};
} else if (keyResult.lastCheckIn >= keyResult.stretchGoal) {
} else {
return {
failPercent: 0,
commitPercent: 0,
targetPercent: 0
};
}
}

function createComparator(keyResult: CheckInValue) {
const increasing = keyResult.baseline <= keyResult.stretchGoal;
return (a: number, b: number) => {
if (increasing) {
return a < b;
}
return a > b;
};
}
26 changes: 19 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,31 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
const keyResult = this.keyResult as KeyResultMetricMin;
const lastCheckIn = keyResult.lastCheckIn?.value!;

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

if (compare(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 (compare(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 (compare(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