Calcs: Update diff percent to be a percent (#90533)

diff per unexpected results
This commit is contained in:
jackyin 2024-07-22 20:03:11 +08:00 committed by GitHub
parent d0eaf4e484
commit 5e21898294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -55,13 +55,14 @@ describe('Stats Calculators', () => {
it('should calculate basic stats', () => { it('should calculate basic stats', () => {
const stats = reduceField({ const stats = reduceField({
field: basicTable.fields[0], field: basicTable.fields[0],
reducers: [ReducerID.first, ReducerID.last, ReducerID.mean, ReducerID.count], reducers: [ReducerID.first, ReducerID.last, ReducerID.mean, ReducerID.count, ReducerID.diffperc],
}); });
expect(stats.first).toEqual(10); expect(stats.first).toEqual(10);
expect(stats.last).toEqual(20); expect(stats.last).toEqual(20);
expect(stats.mean).toEqual(15); expect(stats.mean).toEqual(15);
expect(stats.count).toEqual(2); expect(stats.count).toEqual(2);
expect(stats.diffperc).toEqual(100);
}); });
it('should handle undefined field data without crashing', () => { it('should handle undefined field data without crashing', () => {

View File

@ -573,7 +573,7 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
} }
if (isNumber(calcs.firstNotNull) && isNumber(calcs.diff)) { if (isNumber(calcs.firstNotNull) && isNumber(calcs.diff)) {
calcs.diffperc = calcs.diff / calcs.firstNotNull; calcs.diffperc = (calcs.diff / calcs.firstNotNull) * 100;
} }
return calcs; return calcs;
} }