From 9e49ba78cc7b9a1c66436caa1aafe017747d10fb Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Wed, 13 Dec 2023 14:34:52 +0100 Subject: [PATCH] reverse distribution in report viewer --- report-viewer/src/model/Distribution.ts | 2 +- report-viewer/src/model/HundredValueDistribution.ts | 6 ++---- report-viewer/tests/unit/model/Distribution.test.ts | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/report-viewer/src/model/Distribution.ts b/report-viewer/src/model/Distribution.ts index 00da64d22..d4a67838c 100644 --- a/report-viewer/src/model/Distribution.ts +++ b/report-viewer/src/model/Distribution.ts @@ -6,7 +6,7 @@ export abstract class Distribution { } /** - * Returns the distribution summed at every tenth percentile + * Returns the distribution summed at every tenth percentile, the last percentile (90%-100%) should be at index 1 */ public abstract splitIntoTenBuckets(): number[] } diff --git a/report-viewer/src/model/HundredValueDistribution.ts b/report-viewer/src/model/HundredValueDistribution.ts index 91c2831d1..b3c37aafb 100644 --- a/report-viewer/src/model/HundredValueDistribution.ts +++ b/report-viewer/src/model/HundredValueDistribution.ts @@ -9,13 +9,11 @@ export class HundredValueDistribution extends Distribution { super(distribution) } - /** - * Returns the distribution summed at every tenth percentile - */ public splitIntoTenBuckets(): number[] { const tenValueArray = new Array(10).fill(0) + const reversedDistribution = this._distribution.reverse() for (let i = 99; i >= 0; i--) { - tenValueArray[Math.floor(i / 10)] += this._distribution[i] + tenValueArray[Math.floor(i / 10)] += reversedDistribution[i] } return tenValueArray } diff --git a/report-viewer/tests/unit/model/Distribution.test.ts b/report-viewer/tests/unit/model/Distribution.test.ts index f5b6fa301..6818c81c3 100644 --- a/report-viewer/tests/unit/model/Distribution.test.ts +++ b/report-viewer/tests/unit/model/Distribution.test.ts @@ -7,10 +7,10 @@ describe('Distribution', () => { it.each([ new TenValueDistribution([0, 0, 0, 0, 0, 0, 26, 13209, 58955, 5231]), new HundredValueDistribution([ + 0, 7, 15, 42, 109, 225, 470, 869, 1442, 2052, 3025, 4056, 5091, 6130, 7023, 7292, 7445, 7177, + 6343, 5373, 4309, 3163, 2244, 1544, 923, 493, 273, 168, 61, 31, 8, 12, 2, 1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 1, 0, 1, 2, 12, 8, 31, 61, 168, 273, 493, 923, 1544, 2244, 3163, 4309, 5373, 6343, 7177, - 7445, 7292, 7023, 6130, 5091, 4056, 3025, 2052, 1442, 869, 470, 225, 109, 42, 15, 7, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]) ])('get in 10 Buckets', (distribution: Distribution) => { expect(distribution.splitIntoTenBuckets()).toEqual([0, 0, 0, 0, 0, 0, 26, 13209, 58955, 5231])