Analysis task page shows an empty results for an irrelevant top-level test
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / analysis-results.js
1
2 class AnalysisResults {
3     constructor()
4     {
5         this._metricToBuildMap = {};
6         this._metricIds = [];
7         this._lazilyComputedTopLevelTests = new LazilyEvaluatedFunction(this._computedTopLevelTests.bind(this));
8     }
9
10     findResult(buildId, metricId)
11     {
12         const map = this._metricToBuildMap[metricId];
13         if (!map)
14             return null;
15         return map[buildId];
16     }
17
18     topLevelTestsForTestGroup(testGroup)
19     {
20         return this._lazilyComputedTopLevelTests.evaluate(testGroup, ...this._metricIds);
21     }
22
23     _computedTopLevelTests(testGroup, ...metricIds)
24     {
25         const metrics = metricIds.map((metricId) => Metric.findById(metricId));
26         const tests = new Set(metrics.map((metric) => metric.test()));
27         const topLevelMetrics = metrics.filter((metric) => !tests.has(metric.test().parentTest()));
28
29         const topLevelTests = new Set;
30         for (const request of testGroup.buildRequests()) {
31             for (const metric of topLevelMetrics) {
32                 if (this.findResult(request.buildId(), metric.id()))
33                     topLevelTests.add(metric.test());
34             }
35         }
36         return topLevelTests;
37     }
38
39     containsTest(test)
40     {
41         console.assert(test instanceof Test);
42         for (const metric of test.metrics()) {
43             if (metric.id() in this._metricToBuildMap)
44                 return true;
45         }
46         return false;
47     }
48
49     _computeHighestTests(metricIds)
50     {
51         const testsInResults = new Set(metricIds.map((metricId) => Metric.findById(metricId).test()));
52         return [...testsInResults].filter((test) => !testsInResults.has(test.parentTest()));
53     }
54
55     add(measurement)
56     {
57         console.assert(measurement.configType == 'current');
58         const metricId = measurement.metricId;
59         if (!(metricId in this._metricToBuildMap)) {
60             this._metricToBuildMap[metricId] = {};
61             this._metricIds = Object.keys(this._metricToBuildMap);
62         }
63         const map = this._metricToBuildMap[metricId];
64         console.assert(!map[measurement.buildId]);
65         map[measurement.buildId] = measurement;
66     }
67
68     commitSetForRequest(buildRequest)
69     {
70         if (!this._metricIds.length)
71             return null;
72         const result = this.findResult(buildRequest.buildId(), this._metricIds[0]);
73         if (!result)
74             return null;
75         return result.commitSet();
76     }
77
78     viewForMetric(metric)
79     {
80         console.assert(metric instanceof Metric);
81         return new AnalysisResultsView(this, metric);
82     }
83
84     static fetch(taskId)
85     {
86         taskId = parseInt(taskId);
87         return RemoteAPI.getJSONWithStatus(`../api/measurement-set?analysisTask=${taskId}`).then(function (response) {
88
89             Instrumentation.startMeasuringTime('AnalysisResults', 'fetch');
90
91             const adaptor = new MeasurementAdaptor(response['formatMap']);
92             const results = new AnalysisResults;
93             for (const rawMeasurement of response['measurements'])
94                 results.add(adaptor.applyToAnalysisResults(rawMeasurement));
95
96             Instrumentation.endMeasuringTime('AnalysisResults', 'fetch');
97
98             return results;
99         });
100     }
101 }
102
103 class AnalysisResultsView {
104     constructor(analysisResults, metric)
105     {
106         console.assert(analysisResults instanceof AnalysisResults);
107         console.assert(metric instanceof Metric);
108         this._results = analysisResults;
109         this._metric = metric;
110     }
111
112     metric() { return this._metric; }
113
114     resultForRequest(buildRequest)
115     {
116         return this._results.findResult(buildRequest.buildId(), this._metric.id());
117     }
118 }