combineTableDataWithSparklineData.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Duration, Moment} from 'moment';
  2. import {Series} from 'sentry/types/echarts';
  3. import {zeroFillSeries} from 'sentry/views/starfish/utils/zeroFillSeries';
  4. type DataRow = {
  5. count: number;
  6. description: string;
  7. domain: string;
  8. group_id: string;
  9. };
  10. export default function combineTableDataWithSparklineData(
  11. tableData: DataRow[],
  12. aggregateData,
  13. momentInterval: Duration,
  14. startTime?: Moment,
  15. endTime?: Moment
  16. ): DataRow[] {
  17. const aggregatesGroupedByQuery = {};
  18. aggregateData.forEach(({description, interval, count, p50, p95}) => {
  19. if (description in aggregatesGroupedByQuery) {
  20. aggregatesGroupedByQuery[description].push({name: interval, count, p50, p95});
  21. } else {
  22. aggregatesGroupedByQuery[description] = [{name: interval, count, p50, p95}];
  23. }
  24. });
  25. const combinedData = tableData.map(data => {
  26. const query = data.description;
  27. const throughputSeries: Series = {
  28. seriesName: 'throughput',
  29. data: aggregatesGroupedByQuery[query]?.map(({name, count}) => ({
  30. name,
  31. value: count,
  32. })),
  33. };
  34. const p50Series: Series = {
  35. seriesName: 'p50 Trend',
  36. data: aggregatesGroupedByQuery[query]?.map(({name, p50}) => ({
  37. name,
  38. value: p50,
  39. })),
  40. };
  41. const p95Series: Series = {
  42. seriesName: 'p95 Trend',
  43. data: aggregatesGroupedByQuery[query]?.map(({name, p95}) => ({
  44. name,
  45. value: p95,
  46. })),
  47. };
  48. const zeroFilledThroughput = zeroFillSeries(
  49. throughputSeries,
  50. momentInterval,
  51. startTime,
  52. endTime
  53. );
  54. const zeroFilledP50 = zeroFillSeries(p50Series, momentInterval, startTime, endTime);
  55. const zeroFilledP95 = zeroFillSeries(p95Series, momentInterval, startTime, endTime);
  56. return {
  57. ...data,
  58. throughput: zeroFilledThroughput,
  59. p50_trend: zeroFilledP50,
  60. p95_trend: zeroFilledP95,
  61. };
  62. });
  63. return combinedData;
  64. }