|
1 | 1 | import { Injectable } from '@nestjs/common';
|
| 2 | +import { Nil } from '@seedcompany/common'; |
2 | 3 | import { clamp, round } from 'lodash';
|
3 | 4 | import { CalendarDate, fiscalQuarter, fiscalYear } from '../../common';
|
4 | 5 | import { Column, Row } from '../../common/xlsx.util';
|
@@ -38,16 +39,19 @@ const summaryFrom = (
|
38 | 39 | ): Progress | null => {
|
39 | 40 | let planned = fiscalYear.cell(plannedColumn).asNumber;
|
40 | 41 | let actual = fiscalYear.cell(actualColumn).asNumber;
|
41 |
| - if (!planned || !actual) { |
| 42 | + if (!planned && !actual) { |
42 | 43 | return null;
|
43 | 44 | }
|
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); |
52 | 56 | return { planned, actual };
|
53 | 57 | };
|
0 commit comments