Should not render latest build information if there is no data points for a config.
[WebKit.git] / Websites / perf.webkit.org / public / v3 / pages / test-freshness-page.js
1
2 class TestFreshnessPage extends PageWithHeading {
3     constructor(summaryPageConfiguration, testAgeToleranceInHours)
4     {
5         super('test-freshness', null);
6         this._testAgeTolerance = (testAgeToleranceInHours || 24) * 3600 * 1000;
7         this._timeDuration = this._testAgeTolerance * 2;
8         this._excludedConfigurations = {};
9         this._lastDataPointByConfiguration = null;
10         this._indicatorByConfiguration = null;
11         this._renderTableLazily = new LazilyEvaluatedFunction(this._renderTable.bind(this));
12         this._currentlyHighlightedIndicator = null;
13         this._hoveringTooltip = false;
14         this._builderByIndicator = null;
15         this._renderTooltipLazily = new LazilyEvaluatedFunction(this._renderTooltip.bind(this));
16
17         this._loadConfig(summaryPageConfiguration);
18     }
19
20     didConstructShadowTree()
21     {
22         const tooltipTable = this.content('tooltip-table');
23         tooltipTable.addEventListener('mouseenter', () => {
24             this._hoveringTooltip = true;
25             this.enqueueToRender();
26         });
27         tooltipTable.addEventListener('mouseleave', () => {
28             this._hoveringTooltip = false;
29             this.enqueueToRender();
30         });
31     }
32
33     name() { return 'Test-Freshness'; }
34
35     _loadConfig(summaryPageConfiguration)
36     {
37         const platformIdSet = new Set;
38         const metricIdSet = new Set;
39
40         for (const config of summaryPageConfiguration) {
41             for (const platformGroup of config.platformGroups) {
42                 for (const platformId of platformGroup.platforms)
43                     platformIdSet.add(platformId);
44             }
45
46             for (const metricGroup of config.metricGroups) {
47                 for (const subgroup of metricGroup.subgroups) {
48                     for (const metricId of subgroup.metrics)
49                         metricIdSet.add(metricId);
50                 }
51             }
52
53             const excludedConfigs = config.excludedConfigurations;
54             for (const platform in excludedConfigs) {
55                 if (platform in this._excludedConfigurations)
56                     this._excludedConfigurations[platform] = this._excludedConfigurations[platform].concat(excludedConfigs[platform]);
57                 else
58                     this._excludedConfigurations[platform] = excludedConfigs[platform];
59             }
60         }
61         this._platforms = [...platformIdSet].map((platformId) => Platform.findById(platformId));
62         this._metrics = [...metricIdSet].map((metricId) => Metric.findById(metricId));
63     }
64
65     open(state)
66     {
67         this._fetchTestResults();
68         super.open(state);
69     }
70
71     _fetchTestResults()
72     {
73         this._measurementSetFetchTime = Date.now();
74         this._lastDataPointByConfiguration = new Map;
75         this._builderByIndicator = new Map;
76
77         const startTime = this._measurementSetFetchTime - this._timeDuration;
78
79         for (const platform of this._platforms) {
80             const lastDataPointByMetric = new Map;
81             this._lastDataPointByConfiguration.set(platform, lastDataPointByMetric);
82
83             for (const metric of this._metrics) {
84                 if (!this._isValidPlatformMetricCombination(platform, metric, this._excludedConfigurations))
85                     continue;
86
87                 const measurementSet = MeasurementSet.findSet(platform.id(), metric.id(), platform.lastModified(metric));
88                 measurementSet.fetchBetween(startTime, this._measurementSetFetchTime).then(() => {
89                     const currentTimeSeries = measurementSet.fetchedTimeSeries('current', false, false);
90
91                     let timeForLatestBuild = startTime;
92                     let lastBuild = null;
93                     let builder = null;
94                     let commitSetOfLastPoint = null;
95                     const lastPoint = currentTimeSeries.lastPoint();
96                     if (lastPoint) {
97                         timeForLatestBuild = lastPoint.build().buildTime().getTime();
98                         const view = currentTimeSeries.viewBetweenPoints(currentTimeSeries.firstPoint(), lastPoint);
99                         for (const point of view) {
100                             const build = point.build();
101                             if (!build)
102                                 continue;
103                             if (build.buildTime().getTime() >= timeForLatestBuild) {
104                                 timeForLatestBuild = build.buildTime().getTime();
105                                 lastBuild = build;
106                                 builder = build.builder();
107                             }
108                         }
109                         commitSetOfLastPoint = lastPoint.commitSet();
110                     }
111
112                     lastDataPointByMetric.set(metric, {time: timeForLatestBuild, hasCurrentDataPoint: !!lastPoint,
113                         lastBuild, builder, commitSetOfLastPoint});
114                     this.enqueueToRender();
115                 });
116             }
117         }
118     }
119
120     render()
121     {
122         super.render();
123
124         this._renderTableLazily.evaluate(this._platforms, this._metrics);
125
126         let buildSummaryForCurrentlyHighlightedIndicator = null;
127         let buildForCurrentlyHighlightedIndicator = null;
128         let commitSetForCurrentHighlightedIndicator = null;
129         const builderForCurrentlyHighlightedIndicator = this._currentlyHighlightedIndicator ? this._builderByIndicator.get(this._currentlyHighlightedIndicator) : null;
130         for (const [platform, lastDataPointByMetric] of this._lastDataPointByConfiguration.entries()) {
131             for (const [metric, lastDataPoint] of lastDataPointByMetric.entries()) {
132                 const timeDuration = this._measurementSetFetchTime - lastDataPoint.time;
133                 const timeDurationSummaryPrefix = lastDataPoint.hasCurrentDataPoint ? '' : 'More than ';
134                 const timeDurationSummary = BuildRequest.formatTimeInterval(timeDuration);
135                 const summary = `${timeDurationSummaryPrefix}${timeDurationSummary} since latest data point.`;
136                 const url = this._router.url('charts', ChartsPage.createStateForDashboardItem(platform.id(), metric.id(),
137                     this._measurementSetFetchTime - this._timeDuration));
138
139                 const indicator = this._indicatorByConfiguration.get(platform).get(metric);
140                 if (this._currentlyHighlightedIndicator && this._currentlyHighlightedIndicator === indicator) {
141                     buildSummaryForCurrentlyHighlightedIndicator = summary;
142                     buildForCurrentlyHighlightedIndicator = lastDataPoint.lastBuild;
143                     commitSetForCurrentHighlightedIndicator = lastDataPoint.commitSetOfLastPoint;
144                 }
145                 this._builderByIndicator.set(indicator, lastDataPoint.builder);
146                 indicator.update(timeDuration, this._testAgeTolerance, url, builderForCurrentlyHighlightedIndicator && builderForCurrentlyHighlightedIndicator === lastDataPoint.builder);
147             }
148         }
149         this._renderTooltipLazily.evaluate(this._currentlyHighlightedIndicator, this._hoveringTooltip, buildSummaryForCurrentlyHighlightedIndicator, buildForCurrentlyHighlightedIndicator, commitSetForCurrentHighlightedIndicator);
150     }
151
152     _renderTooltip(indicator, hoveringTooltip, buildSummary, build, commitSet)
153     {
154         if (!indicator || !buildSummary) {
155             this.content('tooltip-table').style.display = hoveringTooltip ? null : 'none';
156             return;
157         }
158         const element = ComponentBase.createElement;
159         const link = ComponentBase.createLink;
160
161         const rect = indicator.element().getBoundingClientRect();
162         const tooltipTable = this.content('tooltip-table');
163         tooltipTable.style.display = null;
164
165         const tooltipContainerComputedStyle = getComputedStyle(tooltipTable);
166         const containerMarginTop = parseFloat(tooltipContainerComputedStyle.paddingTop);
167         const containerMarginLeft = parseFloat(tooltipContainerComputedStyle.marginLeft);
168
169         tooltipTable.style.position = 'absolute';
170         tooltipTable.style.top = rect.top - (tooltipTable.offsetHeight + containerMarginTop)  + 'px';
171         tooltipTable.style.left = rect.left + rect.width / 2 - tooltipTable.offsetWidth / 2 + containerMarginLeft + 'px';
172
173         let tableContent = [element('tr', element('td', {colspan: 2}, buildSummary))];
174
175         if (commitSet) {
176             if (commitSet.repositories().length)
177                 tableContent.push(element('tr', element('th', {colspan: 2}, 'Latest build information')));
178
179             tableContent.push(Repository.sortByNamePreferringOnesWithURL(commitSet.repositories()).map((repository) => {
180                 const commit = commitSet.commitForRepository(repository);
181                 return element('tr', [
182                     element('td', repository.name()),
183                     element('td', commit.url() ? link(commit.label(), commit.label(), commit.url(), true) : commit.label())
184                 ]);
185             }));
186         }
187
188         if (build) {
189             const url = build.url();
190             const buildNumber = build.buildNumber();
191             tableContent.push(element('tr', [
192                 element('td', 'Build'),
193                 element('td', {colspan: 2}, [
194                     url ? link(buildNumber, build.label(), url, true) : buildNumber
195                 ]),
196             ]));
197         }
198
199         this.renderReplace(tooltipTable,  tableContent);
200     }
201
202     _renderTable(platforms, metrics)
203     {
204         const element = ComponentBase.createElement;
205         const tableBodyElement = [];
206         const tableHeadElements = [element('th',  {class: 'table-corner row-head'}, 'Platform \\ Test')];
207
208         for (const metric of metrics)
209             tableHeadElements.push(element('th', {class: 'diagonal-head'}, element('div', metric.test().fullName())));
210
211         this._indicatorByConfiguration = new Map;
212         for (const platform of platforms) {
213             const indicatorByMetric = new Map;
214             this._indicatorByConfiguration.set(platform, indicatorByMetric);
215             tableBodyElement.push(element('tr',
216                 [element('th', {class: 'row-head'}, platform.label()), ...metrics.map((metric) => this._constructTableCell(platform, metric, indicatorByMetric))]));
217         }
218
219         this.renderReplace(this.content('test-health'), [element('thead', tableHeadElements), element('tbody', tableBodyElement)]);
220     }
221
222     _isValidPlatformMetricCombination(platform, metric)
223     {
224         return !(this._excludedConfigurations && this._excludedConfigurations[platform.id()]
225             && this._excludedConfigurations[platform.id()].some((metricId) => metricId == metric.id()))
226             && platform.hasMetric(metric);
227     }
228
229     _constructTableCell(platform, metric, indicatorByMetric)
230     {
231         const element = ComponentBase.createElement;
232
233         if (!this._isValidPlatformMetricCombination(platform, metric))
234             return element('td', {class: 'blank-cell'}, element('div'));
235
236         const indicator = new FreshnessIndicator;
237         indicator.listenToAction('select', (originator) => {
238             this._currentlyHighlightedIndicator = originator;
239             this.enqueueToRender();
240         });
241         indicator.listenToAction('unselect', () => {
242             this._currentlyHighlightedIndicator = null;
243             this.enqueueToRender();
244         });
245         indicatorByMetric.set(metric, indicator);
246         return element('td', {class: 'status-cell'}, indicator);
247     }
248
249     static htmlTemplate()
250     {
251         return `<section class="page-with-heading"><table id="tooltip-table"></table><table id="test-health"></table></section>`;
252     }
253
254     static cssTemplate()
255     {
256         return `
257             .page-with-heading {
258                 display: flex;
259                 justify-content: center;
260             }
261             #test-health {
262                 font-size: 1rem;
263             }
264             #test-health thead {
265                 display: block;
266                 align: right;
267             }
268             #test-health th.table-corner {
269                 text-align: right;
270                 vertical-align: bottom;
271             }
272             #test-health .row-head {
273                 min-width: 15.5rem;
274             }
275             #test-health th {
276                 text-align: left;
277                 border-bottom: 0.1rem solid #ccc;
278                 font-weight: normal;
279             }
280             #test-health th.diagonal-head {
281                 white-space: nowrap;
282                 height: 16rem;
283                 border-bottom: 0rem;
284             }
285             #test-health th.diagonal-head > div {
286                 transform: translate(1rem, 7rem) rotate(315deg);
287                 width: 2rem;
288                 border: 0rem;
289             }
290             #test-health tbody {
291                 display: block;
292                 overflow: auto;
293                 height: calc(100vh - 24rem);
294             }
295             #test-health td.status-cell {
296                 margin: 0;
297                 padding: 0;
298                 max-width: 2.2rem;
299                 max-height: 2.2rem;
300                 min-width: 2.2rem;
301                 min-height: 2.2rem;
302             }
303             #test-health td.blank-cell {
304                 margin: 0;
305                 padding: 0;
306                 max-width: 2.2rem;
307                 max-height: 2.2rem;
308                 min-width: 2.2rem;
309                 min-height: 2.2rem;
310             }
311             #test-health td.blank-cell > div  {
312                 background-color: #F9F9F9;
313                 height: 1.6rem;
314                 width: 1.6rem;
315                 margin: 0.1rem;
316                 padding: 0;
317                 position: relative;
318                 overflow: hidden;
319             }
320             #test-health td.blank-cell > div::before {
321                 content: "";
322                 position: absolute;
323                 top: -1px;
324                 left: -1px;
325                 display: block;
326                 width: 0px;
327                 height: 0px;
328                 border-right: calc(1.6rem + 1px) solid #ddd;
329                 border-top: calc(1.6rem + 1px) solid transparent;
330             }
331             #test-health td.blank-cell > div::after {
332                 content: "";
333                 display: block;
334                 position: absolute;
335                 top: 1px;
336                 left: 1px;
337                 width: 0px;
338                 height: 0px;
339                 border-right: calc(1.6rem - 1px) solid #F9F9F9;
340                 border-top: calc(1.6rem - 1px) solid transparent;
341             }
342             #tooltip-table {
343                 width: 22rem;
344                 background-color: #34495E;
345                 opacity: 0.9;
346                 margin: 0.3rem;
347                 padding: 0.3rem;
348                 border-radius: 0.4rem;
349                 z-index: 1;
350                 text-align: center;
351                 display: inline-table;
352                 color: white;
353             }
354             #tooltip-table td {
355                 overflow: hidden;
356                 max-width: 22rem;
357                 text-overflow: ellipsis;
358             }
359             #tooltip-table::after {
360                 content: " ";
361                 position: absolute;
362                 top: 100%;
363                 left: 50%;
364                 margin-left: -1rem;
365                 border-width: 0.2rem;
366                 border-style: solid;
367                 border-color: #34495E transparent transparent transparent;
368             }
369             #tooltip-table a {
370                 color: #B03A2E;
371                 font-weight: bold;
372             }
373         `;
374     }
375
376     routeName() { return 'test-freshness'; }
377 }