Skip to content

Commit

Permalink
feat: playground result count buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Oct 28, 2024
1 parent cb6b776 commit 03a56be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
import { capitalizeFirst } from 'utils/capitalizeFirst';
import { AdvancedPlaygroundEnvironmentDiffCell } from './AdvancedPlaygroundEnvironmentCell/AdvancedPlaygroundEnvironmentDiffCell';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { countCombinations } from './combinationCounter';
import { countCombinations, getBucket } from './combinationCounter';

const defaultSort: SortingRule<string> = { id: 'name' };
const { value, setValue } = createLocalStorage(
Expand All @@ -54,7 +54,7 @@ export const AdvancedPlaygroundResultsTable = ({
trackEvent('playground', {
props: {
eventType: 'number-of-combinations',
count: countCombinations(features),
count: getBucket(countCombinations(features)),
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countCombinations } from './combinationCounter';
import { countCombinations, getBucket } from './combinationCounter';
import type {
AdvancedPlaygroundEnvironmentFeatureSchema,
AdvancedPlaygroundFeatureSchema,
Expand Down Expand Up @@ -95,3 +95,11 @@ it('counts the correct number of combinations', () => {
});
assertCount(5, ['development'], { x: ['1', '2'] });
});

it('assigns bucket', () => {
expect(getBucket(0)).toBe('0-100');
expect(getBucket(100)).toBe('100-1000');
expect(getBucket(1000)).toBe('1000-10000');
expect(getBucket(10000)).toBe('10000-20000');
expect(getBucket(20000)).toBe('20000+');
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ export const countCombinations = (
).length,
0,
);

export const getBucket = (value: number): string => {
if (value < 0) {
return 'invalid bucket';
}
if (value >= 20000) {
return '20000+';
} else if (value >= 10000) {
return '10000-20000';
} else if (value >= 1000) {
return '1000-10000';
} else if (value >= 100) {
return '100-1000';
} else {
return '0-100';
}
};

0 comments on commit 03a56be

Please sign in to comment.