validity assertion fails after removing a child of an <optgroup> element
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / measurement-adaptor.js
1 'use strict';
2
3 class MeasurementAdaptor {
4     constructor(formatMap)
5     {
6         var nameMap = {};
7         formatMap.forEach(function (key, index) {
8             nameMap[key] = index;
9         });
10         this._idIndex = nameMap['id'];
11         this._commitTimeIndex = nameMap['commitTime'];
12         this._countIndex = nameMap['iterationCount'];
13         this._meanIndex = nameMap['mean'];
14         this._sumIndex = nameMap['sum'];
15         this._squareSumIndex = nameMap['squareSum'];
16         this._markedOutlierIndex = nameMap['markedOutlier'];
17         this._revisionsIndex = nameMap['revisions'];
18         this._buildIndex = nameMap['build'];
19         this._buildTimeIndex = nameMap['buildTime'];
20         this._buildNumberIndex = nameMap['buildNumber'];
21         this._builderIndex = nameMap['builder'];
22         this._metricIndex = nameMap['metric'];
23         this._configTypeIndex = nameMap['configType'];
24     }
25
26     extractId(row)
27     {
28         return row[this._idIndex];
29     }
30
31     isOutlier(row)
32     {
33         return row[this._markedOutlierIndex];
34     }
35
36     applyToAnalysisResults(row)
37     {
38         var adaptedRow = this.applyTo(row);
39         adaptedRow.metricId = row[this._metricIndex];
40         adaptedRow.configType = row[this._configTypeIndex];
41         return adaptedRow;
42     }
43
44     applyTo(row)
45     {
46         var id = row[this._idIndex];
47         var mean = row[this._meanIndex];
48         var sum = row[this._sumIndex];
49         var squareSum = row[this._squareSumIndex];
50         var revisionList = row[this._revisionsIndex];
51         var buildId = row[this._buildIndex];
52         var builderId = row[this._builderIndex];
53         var buildNumber = row[this._buildNumberIndex];
54         var buildTime = row[this._buildTimeIndex];
55         var self = this;
56         return {
57             id: id,
58             markedOutlier: row[this._markedOutlierIndex],
59             buildId: buildId,
60             metricId: null,
61             configType: null,
62             rootSet: function () { return MeasurementRootSet.ensureSingleton(id, revisionList); },
63             build: function () { return new Build(buildId, Builder.findById(builderId), buildNumber, buildTime); },
64             time: row[this._commitTimeIndex],
65             value: mean,
66             sum: sum,
67             squareSum: squareSum,
68             iterationCount: row[this._countIndex],
69             interval: MeasurementAdaptor.computeConfidenceInterval(row[this._countIndex], mean, sum, squareSum)
70         };
71     }
72
73     static aggregateAnalysisResults(results)
74     {
75         var totalSum = 0;
76         var totalSquareSum = 0;
77         var totalIterationCount = 0;
78         var means = [];
79         for (var result of results) {
80             means.push(result.value);
81             totalSum += result.sum;
82             totalSquareSum += result.squareSum;
83             totalIterationCount += result.iterationCount;
84         }
85         var mean = totalSum / totalIterationCount;
86         var interval;
87         try {
88             interval = this.computeConfidenceInterval(totalIterationCount, mean, totalSum, totalSquareSum)
89         } catch (error) {
90             interval = this.computeConfidenceInterval(results.length, mean, Statistics.sum(means), Statistics.squareSum(means));
91         }
92         return { value: mean, interval: interval };
93     }
94
95     static computeConfidenceInterval(iterationCount, mean, sum, squareSum)
96     {
97         var delta = Statistics.confidenceIntervalDelta(0.95, iterationCount, sum, squareSum);
98         return isNaN(delta) ? null : [mean - delta, mean + delta];
99     }
100 }
101
102 if (typeof module != 'undefined')
103     module.exports.MeasurementAdaptor = MeasurementAdaptor;