Skip to content

Commit a26bd5f

Browse files
committed
tc
1 parent 2a31393 commit a26bd5f

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

torchci/pages/tests/testInfo.tsx

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,57 @@ const FailuresTimeline = memo(
9090
stopTime: stopTime.utc().format("YYYY-MM-DDTHH:mm:ss.SSS"),
9191
}
9292
);
93-
data = (data || [])
94-
.sort((a, b) => dayjs(a.date).unix() - dayjs(b.date).unix())
95-
.map((d) => {
96-
d.date = dayjs(d.date).format("YYYY-MM-DD HH:mm");
97-
return d;
93+
94+
data = (data || []).map((d) => {
95+
d.date = dayjs(d.date).format("YYYY-MM-DD HH:mm");
96+
return d;
97+
});
98+
99+
function getAxisAndSeries(data: FailuresTimelineData[]) {
100+
// Get the axis and the series in a format that is accepted by the chart.
101+
// Also fill in missing dates with 0s
102+
103+
// Generate all dates of the granularity between the earliest and latest
104+
// dates found in the data
105+
const start = _.minBy(data, (d) => dayjs(d.date))?.date;
106+
const end = _.maxBy(data, (d) => dayjs(d.date))?.date;
107+
const allDates = [];
108+
let current = dayjs(start);
109+
while (current <= dayjs(end)) {
110+
allDates.push(current.format("YYYY-MM-DD HH:mm"));
111+
current = current.add(1, granularity as any);
112+
}
113+
114+
// Fill in missing dates with 0s
115+
const dataMap = _.keyBy(data, (d) =>
116+
dayjs(d.date).format("YYYY-MM-DD HH:mm")
117+
);
118+
data = allDates.map((date) => {
119+
return {
120+
date,
121+
count: dataMap[date]?.count ?? 0,
122+
shas: dataMap[date]?.shas ?? [],
123+
};
98124
});
99-
const xAxis = [
100-
{
101-
data: data.map((d) => d.date),
102-
scaleType: "band",
103-
},
104-
];
105-
const series = [
106-
{
107-
label: "Failures",
108-
stack: "total",
109-
data: data.map((d) => d.count),
110-
color: RED,
111-
},
112-
];
113125

126+
const xAxis = [
127+
{
128+
data: data.map((d) => d.date),
129+
scaleType: "band",
130+
},
131+
];
132+
const series = [
133+
{
134+
label: "Failures",
135+
stack: "total",
136+
data: data.map((d) => d.count),
137+
color: RED,
138+
},
139+
];
140+
return { xAxis, series };
141+
}
142+
143+
const { series, xAxis } = getAxisAndSeries(data);
114144
return (
115145
<Stack spacing={2}>
116146
<h2>Failures Timeline (Beta)</h2>

0 commit comments

Comments
 (0)