combineTableDataWithSparklineData.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Duration, Moment} 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. startTime?: Moment,
  10. endTime?: Moment
  11. ): DataRow[] {
  12. const aggregatesGroupedByQuery = {};
  13. aggregateData.forEach(({description, interval, count, p50, p95}) => {
  14. if (description in aggregatesGroupedByQuery) {
  15. aggregatesGroupedByQuery[description].push({name: interval, count, p50, p95});
  16. } else {
  17. aggregatesGroupedByQuery[description] = [{name: interval, count, p50, p95}];
  18. }
  19. });
  20. const combinedData = tableData.map(data => {
  21. const query = data.description;
  22. const throughputSeries: Series = {
  23. seriesName: 'throughput',
  24. data: aggregatesGroupedByQuery[query]?.map(({name, count}) => ({
  25. name,
  26. value: count,
  27. })),
  28. };
  29. const p50Series: Series = {
  30. seriesName: 'p50 Trend',
  31. data: aggregatesGroupedByQuery[query]?.map(({name, p50}) => ({
  32. name,
  33. value: p50,
  34. })),
  35. };
  36. const p95Series: Series = {
  37. seriesName: 'p95 Trend',
  38. data: aggregatesGroupedByQuery[query]?.map(({name, p95}) => ({
  39. name,
  40. value: p95,
  41. })),
  42. };
  43. const zeroFilledThroughput = zeroFillSeries(
  44. throughputSeries,
  45. momentInterval,
  46. startTime,
  47. endTime
  48. );
  49. const zeroFilledP50 = zeroFillSeries(p50Series, momentInterval, startTime, endTime);
  50. const zeroFilledP95 = zeroFillSeries(p95Series, momentInterval, startTime, endTime);
  51. return {
  52. ...data,
  53. throughput: zeroFilledThroughput,
  54. p50_trend: zeroFilledP50,
  55. p95_trend: zeroFilledP95,
  56. };
  57. });
  58. return combinedData;
  59. }