getWeights.tsx 1.1 KB

12345678910111213141516171819202122
  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. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  12. acc[webVital] =
  13. (webVitals.includes(webVital as WebVitals)
  14. ? // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  15. PERFORMANCE_SCORE_WEIGHTS[webVital] * 100
  16. : 0) / totalWeight;
  17. return acc;
  18. },
  19. {} as Record<WebVitals, number>
  20. );
  21. }