Fix a bug from r226303 that latest build time is not correctly calculated.
[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 tooltipContainer = this.content('tooltip-container');
23         tooltipContainer.addEventListener('mouseenter', () => {
24             this._hoveringTooltip = true;
25             this.enqueueToRender();
26         });
27         tooltipContainer.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 lastBuildLink = null;
93                     let builder = null;
94                     const lastPoint = currentTimeSeries.lastPoint();
95                     if (lastPoint) {
96                         timeForLatestBuild = lastPoint.build().buildTime().getTime();
97                         const view = currentTimeSeries.viewBetweenPoints(currentTimeSeries.firstPoint(), lastPoint);
98                         for (const point of view) {
99                             const build = point.build();
100                             if (!build)
101                                 continue;
102                             if (build.buildTime().getTime() >= timeForLatestBuild) {
103                                 timeForLatestBuild = build.buildTime().getTime();
104                                 lastBuildLink = build.url();
105                                 builder = build.builder();
106                             }
107                         }
108                     }
109
110                     lastDataPointByMetric.set(metric, {time: timeForLatestBuild, hasCurrentDataPoint: !!lastPoint,
111                         lastBuildLink, builder});
112                     this.enqueueToRender();
113                 });
114             }
115         }
116     }
117
118     render()
119     {
120         super.render();
121
122         this._renderTableLazily.evaluate(this._platforms, this._metrics);
123
124         let buildSummaryForCurrentlyHighlightedIndicator = null;
125         let buildLinkForCurrentlyHighlightedIndicator = null;
126         const builderForCurrentlyHighlightedIndicator = this._currentlyHighlightedIndicator ? this._builderByIndicator.get(this._currentlyHighlightedIndicator) : null;
127         for (const [platform, lastDataPointByMetric] of this._lastDataPointByConfiguration.entries()) {
128             for (const [metric, lastDataPoint] of lastDataPointByMetric.entries()) {
129                 const timeDuration = this._measurementSetFetchTime - lastDataPoint.time;
130                 const timeDurationSummaryPrefix = lastDataPoint.hasCurrentDataPoint ? '' : 'More than ';
131                 const timeDurationSummary = BuildRequest.formatTimeInterval(timeDuration);
132                 const summary = `${timeDurationSummaryPrefix}${timeDurationSummary} since latest data point.`;
133                 const url = this._router.url('charts', ChartsPage.createStateForDashboardItem(platform.id(), metric.id(),
134                     this._measurementSetFetchTime - this._timeDuration));
135
136                 const indicator = this._indicatorByConfiguration.get(platform).get(metric);
137                 if (this._currentlyHighlightedIndicator && this._currentlyHighlightedIndicator === indicator) {
138                     buildSummaryForCurrentlyHighlightedIndicator = summary;
139                     buildLinkForCurrentlyHighlightedIndicator = lastDataPoint.lastBuildLink;
140                 }
141                 this._builderByIndicator.set(indicator, lastDataPoint.builder);
142                 indicator.update(timeDuration, this._testAgeTolerance, url, builderForCurrentlyHighlightedIndicator && builderForCurrentlyHighlightedIndicator === lastDataPoint.builder);
143             }
144         }
145         this._renderTooltipLazily.evaluate(this._currentlyHighlightedIndicator, this._hoveringTooltip, buildSummaryForCurrentlyHighlightedIndicator, buildLinkForCurrentlyHighlightedIndicator);
146     }
147
148     _renderTooltip(indicator, hoveringTooltip, buildSummary, buildLink)
149     {
150         if (!indicator || !buildSummary) {
151             this.content('tooltip-container').style.display = hoveringTooltip ? null : 'none';
152             return;
153         }
154         const element = ComponentBase.createElement;
155
156         const rect = indicator.element().getBoundingClientRect();
157         const tooltipContainer = this.content('tooltip-container');
158         tooltipContainer.style.display = null;
159
160         const tooltipContainerComputedStyle = getComputedStyle(tooltipContainer);
161         const containerMarginTop = parseFloat(tooltipContainerComputedStyle.paddingTop);
162         const containerMarginLeft = parseFloat(tooltipContainerComputedStyle.marginLeft);
163
164         tooltipContainer.style.position = 'absolute';
165         tooltipContainer.style.top = rect.top - (tooltipContainer.offsetHeight + containerMarginTop)  + 'px';
166         tooltipContainer.style.left = rect.left + rect.width / 2 - tooltipContainer.offsetWidth / 2 + containerMarginLeft + 'px';
167
168         this.renderReplace(tooltipContainer, [element('p', buildSummary), buildLink ? element('a', {href: buildLink}, 'Latest Build') : []]);
169     }
170
171     _renderTable(platforms, metrics)
172     {
173         const element = ComponentBase.createElement;
174         const tableBodyElement = [];
175         const tableHeadElements = [element('th',  {class: 'table-corner row-head'}, 'Platform \\ Test')];
176
177         for (const metric of metrics)
178             tableHeadElements.push(element('th', {class: 'diagonal-head'}, element('div', metric.test().fullName())));
179
180         this._indicatorByConfiguration = new Map;
181         for (const platform of platforms) {
182             const indicatorByMetric = new Map;
183             this._indicatorByConfiguration.set(platform, indicatorByMetric);
184             tableBodyElement.push(element('tr',
185                 [element('th', {class: 'row-head'}, platform.label()), ...metrics.map((metric) => this._constructTableCell(platform, metric, indicatorByMetric))]));
186         }
187
188         this.renderReplace(this.content('test-health'), [element('thead', tableHeadElements), element('tbody', tableBodyElement)]);
189     }
190
191     _isValidPlatformMetricCombination(platform, metric)
192     {
193         return !(this._excludedConfigurations && this._excludedConfigurations[platform.id()]
194             && this._excludedConfigurations[platform.id()].some((metricId) => metricId == metric.id()))
195             && platform.hasMetric(metric);
196     }
197
198     _constructTableCell(platform, metric, indicatorByMetric)
199     {
200         const element = ComponentBase.createElement;
201
202         if (!this._isValidPlatformMetricCombination(platform, metric))
203             return element('td', {class: 'blank-cell'}, element('div'));
204
205         const indicator = new FreshnessIndicator;
206         indicator.listenToAction('select', (originator) => {
207             this._currentlyHighlightedIndicator = originator;
208             this.enqueueToRender();
209         });
210         indicator.listenToAction('unselect', () => {
211             this._currentlyHighlightedIndicator = null;
212             this.enqueueToRender();
213         });
214         indicatorByMetric.set(metric, indicator);
215         return element('td', {class: 'status-cell'}, indicator);
216     }
217
218     static htmlTemplate()
219     {
220         return `<section class="page-with-heading"><div id="tooltip-container"></div><table id="test-health"></table></section>`;
221     }
222
223     static cssTemplate()
224     {
225         return `
226             .page-with-heading {
227                 display: flex;
228                 justify-content: center;
229             }
230             #test-health {
231                 font-size: 1rem;
232             }
233             #test-health thead {
234                 display: block;
235                 align: right;
236             }
237             #test-health th.table-corner {
238                 text-align: right;
239                 vertical-align: bottom;
240             }
241             #test-health .row-head {
242                 min-width: 15.5rem;
243             }
244             #test-health th {
245                 text-align: left;
246                 border-bottom: 0.1rem solid #ccc;
247                 font-weight: normal;
248             }
249             #test-health th.diagonal-head {
250                 white-space: nowrap;
251                 height: 16rem;
252                 border-bottom: 0rem;
253             }
254             #test-health th.diagonal-head > div {
255                 transform: translate(1rem, 7rem) rotate(315deg);
256                 width: 2rem;
257                 border: 0rem;
258             }
259             #test-health tbody {
260                 display: block;
261                 overflow: auto;
262                 height: calc(100vh - 24rem);
263             }
264             #test-health td.status-cell {
265                 margin: 0;
266                 padding: 0;
267                 max-width: 2.2rem;
268                 max-height: 2.2rem;
269                 min-width: 2.2rem;
270                 min-height: 2.2rem;
271             }
272             #test-health td.blank-cell {
273                 margin: 0;
274                 padding: 0;
275                 max-width: 2.2rem;
276                 max-height: 2.2rem;
277                 min-width: 2.2rem;
278                 min-height: 2.2rem;
279             }
280             #test-health td.blank-cell > div  {
281                 background-color: #F9F9F9;
282                 height: 1.6rem;
283                 width: 1.6rem;
284                 margin: 0.1rem;
285                 padding: 0;
286                 position: relative;
287                 overflow: hidden;
288             }
289             #test-health td.blank-cell > div::before {
290                 content: "";
291                 position: absolute;
292                 top: -1px;
293                 left: -1px;
294                 display: block;
295                 width: 0px;
296                 height: 0px;
297                 border-right: calc(1.6rem + 1px) solid #ddd;
298                 border-top: calc(1.6rem + 1px) solid transparent;
299             }
300             #test-health td.blank-cell > div::after {
301                 content: "";
302                 display: block;
303                 position: absolute;
304                 top: 1px;
305                 left: 1px;
306                 width: 0px;
307                 height: 0px;
308                 border-right: calc(1.6rem - 1px) solid #F9F9F9;
309                 border-top: calc(1.6rem - 1px) solid transparent;
310             }
311             #tooltip-container {
312                 width: 22rem;
313                 height: 2rem;
314                 background-color: #34495E;
315                 opacity: 0.9;
316                 margin: 0.3rem;
317                 padding: 0.3rem;
318                 border-radius: 0.4rem;
319                 z-index: 1;
320                 text-align: center;
321             }
322             #tooltip-container::after {
323                 content: " ";
324                 position: absolute;
325                 top: 100%;
326                 left: 50%;
327                 margin-left: -1rem;
328                 border-width: 0.2rem;
329                 border-style: solid;
330                 border-color: #34495E transparent transparent transparent;
331             }
332             #tooltip-container p {
333                 color: white;
334                 margin: 0;
335             }
336             #tooltip-container a {
337                 color: #B03A2E;
338                 font-weight: bold;
339             }
340         `;
341     }
342
343     routeName() { return 'test-freshness'; }
344 }