getWeights.tsx 840 B

1234567891011121314151617181920
  1. import {ORDER} from 'sentry/views/insights/browser/webVitals/components/charts/performanceScoreChart';
  2. import type {WebVitals} from 'sentry/views/insights/browser/webVitals/types';
  3. import {PERFORMANCE_SCORE_WEIGHTS} from 'sentry/views/insights/browser/webVitals/utils/scoreThresholds';
  4. export function getWeights(webVitals: WebVitals[] = []): Record<WebVitals, number> {
  5. const totalWeight = ORDER.filter(webVital => webVitals.includes(webVital)).reduce(
  6. (acc, webVital) => acc + PERFORMANCE_SCORE_WEIGHTS[webVital],
  7. 0
  8. );
  9. return Object.keys(PERFORMANCE_SCORE_WEIGHTS).reduce(
  10. (acc, webVital) => {
  11. acc[webVital] =
  12. (webVitals.includes(webVital as WebVitals)
  13. ? PERFORMANCE_SCORE_WEIGHTS[webVital] * 100
  14. : 0) / totalWeight;
  15. return acc;
  16. },
  17. {} as Record<WebVitals, number>
  18. );
  19. }