hasFirstBucketsEmpty.tsx 680 B

123456789101112131415161718192021222324252627
  1. import {SeriesApi} from 'sentry/types';
  2. import {defined} from 'sentry/utils';
  3. import {quantityField} from '.';
  4. // Returns true if the first X time buckets are 0 in the series api response
  5. export function hasFirstBucketsEmpty(
  6. stats: SeriesApi | undefined,
  7. numberOfLeadingEmptyBuckets = 3
  8. ) {
  9. if (!defined(stats)) {
  10. return false;
  11. }
  12. const numberOfEventsInTheFirstBuckets = stats.groups.reduce((acc, group) => {
  13. let groupAcc = 0;
  14. const series = group.series[quantityField];
  15. for (let i = 0; i < numberOfLeadingEmptyBuckets; i++) {
  16. groupAcc += series[i];
  17. }
  18. return acc + groupAcc;
  19. }, 0);
  20. return numberOfEventsInTheFirstBuckets === 0;
  21. }