Skip to content

Commit a30e2a8

Browse files
authored
revised logic for progress summary (#2876)
1 parent 38a19d0 commit a30e2a8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/components/progress-summary/progress-summary.extractor.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2+
import { Nil } from '@seedcompany/common';
23
import { clamp, round } from 'lodash';
34
import { CalendarDate, fiscalQuarter, fiscalYear } from '../../common';
45
import { Column, Row } from '../../common/xlsx.util';
@@ -38,16 +39,19 @@ const summaryFrom = (
3839
): Progress | null => {
3940
let planned = fiscalYear.cell(plannedColumn).asNumber;
4041
let actual = fiscalYear.cell(actualColumn).asNumber;
41-
if (!planned || !actual) {
42+
if (!planned && !actual) {
4243
return null;
4344
}
44-
if (round(planned, 4) > 1) {
45-
// The PnP has the macro option to do calculations as percents or verse equivalents.
46-
// We need to standardize as percents here.
47-
planned /= fiscalYear.sheet.totalVerseEquivalents;
48-
actual /= fiscalYear.sheet.totalVerseEquivalents;
49-
}
50-
planned = clamp(planned, 0, 1);
51-
actual = clamp(actual, 0, 1);
45+
const normalize = (val: number | Nil) => {
46+
if (!val) return 0;
47+
if (round(val, 4) > 1) {
48+
// The PnP has the macro option to do calculations as percents or verse equivalents.
49+
// We need to standardize as percents here.
50+
val /= fiscalYear.sheet.totalVerseEquivalents;
51+
}
52+
return clamp(val, 0, 1);
53+
};
54+
planned = normalize(planned);
55+
actual = normalize(actual);
5256
return { planned, actual };
5357
};

0 commit comments

Comments
 (0)