applyStaticWeightsToTimeseries.tsx 1011 B

1234567891011121314151617181920212223
  1. import type {
  2. UnweightedWebVitalsScoreBreakdown,
  3. WebVitalsScoreBreakdown,
  4. } from 'sentry/views/insights/browser/webVitals/queries/storedScoreQueries/useProjectWebVitalsScoresTimeseriesQuery';
  5. import {PERFORMANCE_SCORE_WEIGHTS} from 'sentry/views/insights/browser/webVitals/utils/scoreThresholds';
  6. // Returns a weighed score timeseries with each interval calculated from applying hardcoded weights to unweighted scores
  7. export function applyStaticWeightsToTimeseries(
  8. timeseriesData: WebVitalsScoreBreakdown & UnweightedWebVitalsScoreBreakdown
  9. ) {
  10. return {
  11. ...Object.keys(PERFORMANCE_SCORE_WEIGHTS).reduce((acc, webVital) => {
  12. acc[webVital] = timeseriesData[
  13. `unweighted${webVital.charAt(0).toUpperCase()}${webVital.slice(1)}`
  14. ].map(({name, value}) => ({
  15. name,
  16. value: value * PERFORMANCE_SCORE_WEIGHTS[webVital] * 0.01,
  17. }));
  18. return acc;
  19. }, {}),
  20. total: timeseriesData.total,
  21. } as WebVitalsScoreBreakdown & UnweightedWebVitalsScoreBreakdown;
  22. }