combineTableDataWithSparklineData.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {Duration} from 'moment';
  2. import {Series} from 'sentry/types/echarts';
  3. import {DataRow} from 'sentry/views/starfish/modules/APIModule/endpointTable';
  4. import {zeroFillSeries} from 'sentry/views/starfish/utils/zeroFillSeries';
  5. export default function combineTableDataWithSparklineData(
  6. tableData: DataRow[],
  7. aggregateData,
  8. momentInterval: Duration
  9. ): DataRow[] {
  10. const aggregatesGroupedByQuery = {};
  11. aggregateData.forEach(({description, interval, count, p75}) => {
  12. if (description in aggregatesGroupedByQuery) {
  13. aggregatesGroupedByQuery[description].push({name: interval, count, p75});
  14. } else {
  15. aggregatesGroupedByQuery[description] = [{name: interval, count, p75}];
  16. }
  17. });
  18. const combinedData = tableData.map(data => {
  19. const query = data.description;
  20. const throughputSeries: Series = {
  21. seriesName: 'throughput',
  22. data: aggregatesGroupedByQuery[query]?.map(({name, count}) => ({
  23. name,
  24. value: count,
  25. })),
  26. };
  27. const p75Series: Series = {
  28. seriesName: 'p75 Trend',
  29. data: aggregatesGroupedByQuery[query]?.map(({name, p75}) => ({
  30. name,
  31. value: p75,
  32. })),
  33. };
  34. const zeroFilledThroughput = zeroFillSeries(throughputSeries, momentInterval);
  35. const zeroFilledP75 = zeroFillSeries(p75Series, momentInterval);
  36. return {...data, throughput: zeroFilledThroughput, p75_trend: zeroFilledP75};
  37. });
  38. return combinedData;
  39. }