Skip to content

Commit

Permalink
reverse distribution in report viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Dec 13, 2023
1 parent 2fce557 commit 9e49ba7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion report-viewer/src/model/Distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}
6 changes: 2 additions & 4 deletions report-viewer/src/model/HundredValueDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(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
}
Expand Down
6 changes: 3 additions & 3 deletions report-viewer/tests/unit/model/Distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 9e49ba7

Please sign in to comment.