- Revision
- 283153
- Author
- [email protected]
- Date
- 2021-09-27 16:33:04 -0700 (Mon, 27 Sep 2021)
Log Message
Summary page should support calculating summary using weighted mean.
https://bugs.webkit.org/show_bug.cgi?id=230810
Reviewed by Ryosuke Niwa.
Add a way to specify weight for a platform or (plafform, metric) which will be used while calculating a summary.
* public/shared/statistics.js: Added 'weightedMean' function.
(Statistics.new.this.weightedMean):
* public/v3/pages/summary-page.js: Added support for specifying a weight for platform or (platform, metric).
(SummaryPage):
(SummaryPage.prototype._createConfigurationGroup):
(SummaryPageConfigurationGroup):
* unit-tests/statistics-tests.js: Added unit tests.
Modified Paths
Diff
Modified: trunk/Websites/perf.webkit.org/ChangeLog (283152 => 283153)
--- trunk/Websites/perf.webkit.org/ChangeLog 2021-09-27 23:05:18 UTC (rev 283152)
+++ trunk/Websites/perf.webkit.org/ChangeLog 2021-09-27 23:33:04 UTC (rev 283153)
@@ -1,3 +1,20 @@
+2021-09-26 Dewei Zhu <[email protected]>
+
+ Summary page should support calculating summary using weighted mean.
+ https://bugs.webkit.org/show_bug.cgi?id=230810
+
+ Reviewed by Ryosuke Niwa.
+
+ Add a way to specify weight for a platform or (plafform, metric) which will be used while calculating a summary.
+
+ * public/shared/statistics.js: Added 'weightedMean' function.
+ (Statistics.new.this.weightedMean):
+ * public/v3/pages/summary-page.js: Added support for specifying a weight for platform or (platform, metric).
+ (SummaryPage):
+ (SummaryPage.prototype._createConfigurationGroup):
+ (SummaryPageConfigurationGroup):
+ * unit-tests/statistics-tests.js: Added unit tests.
+
2021-07-20 Dewei Zhu <[email protected]>
Use bigint for 'commit_order' field in 'commits' table to support larger range.
Modified: trunk/Websites/perf.webkit.org/public/shared/statistics.js (283152 => 283153)
--- trunk/Websites/perf.webkit.org/public/shared/statistics.js 2021-09-27 23:05:18 UTC (rev 283152)
+++ trunk/Websites/perf.webkit.org/public/shared/statistics.js 2021-09-27 23:33:04 UTC (rev 283153)
@@ -16,6 +16,16 @@
return this.sum(values) / values.length;
}
+ this.weightedMean = function (valuesWithWeights) {
+ let totalWeight = 0;
+ let sum = 0;
+ for (const entry of valuesWithWeights) {
+ totalWeight += entry.weight;
+ sum += entry.value * entry.weight;
+ }
+ return sum / totalWeight;
+ }
+
this.median = function (values) {
return values.sort(function (a, b) { return a - b; })[Math.floor(values.length / 2)];
}
Modified: trunk/Websites/perf.webkit.org/public/v3/pages/summary-page.js (283152 => 283153)
--- trunk/Websites/perf.webkit.org/public/v3/pages/summary-page.js 2021-09-27 23:05:18 UTC (rev 283152)
+++ trunk/Websites/perf.webkit.org/public/v3/pages/summary-page.js 2021-09-27 23:33:04 UTC (rev 283153)
@@ -14,6 +14,7 @@
this._renderQueue = [];
this._configGroups = [];
this._excludedConfigurations = summarySettings.excludedConfigurations;
+ this._weightedConfigurations = summarySettings.weightedConfigurations;
for (var metricGroup of summarySettings.metricGroups) {
var group = {name: metricGroup.name, rows: []};
@@ -59,7 +60,7 @@
{
var platforms = platformIdList.map(function (id) { return Platform.findById(id); }).filter(function (obj) { return !!obj; });
var metrics = metricIdList.map(function (id) { return Metric.findById(id); }).filter(function (obj) { return !!obj; });
- var configGroup = new SummaryPageConfigurationGroup(platforms, metrics, this._excludedConfigurations);
+ var configGroup = new SummaryPageConfigurationGroup(platforms, metrics, this._excludedConfigurations, this._weightedConfigurations);
this._configGroups.push(configGroup);
return configGroup;
}
@@ -247,7 +248,7 @@
}
class SummaryPageConfigurationGroup {
- constructor(platforms, metrics, excludedConfigurations)
+ constructor(platforms, metrics, excludedConfigurations, weightedConfigurations)
{
this._measurementSets = [];
this._configurationList = [];
@@ -258,6 +259,7 @@
this._platformsWithoutBaseline = new Set;
this._isFetching = false;
this._smallerIsBetter = metrics.length ? metrics[0].isSmallerBetter() : null;
+ this._weightedConfigurations = weightedConfigurations;
for (const platform of platforms) {
console.assert(platform instanceof Platform);
@@ -320,12 +322,13 @@
{
var ratios = [];
for (var set of this._measurementSets) {
- var ratio = this._setToRatio.get(set);
+ const ratio = this._setToRatio.get(set);
+ const weight = this._weightForMeasurementSet(set);
if (!isNaN(ratio))
- ratios.push(ratio);
+ ratios.push({value: ratio, weight});
}
- var averageRatio = Statistics.mean(ratios);
+ var averageRatio = Statistics.weightedMean(ratios);
if (isNaN(averageRatio))
return;
@@ -338,6 +341,22 @@
this._changeType = changeType;
}
+ _weightForMeasurementSet(measurementSet)
+ {
+ if (!this._weightedConfigurations)
+ return 1;
+ const platformId = measurementSet.platformId();
+ const weightForPlatform = this._weightedConfigurations[platformId];
+ if (!weightForPlatform)
+ return 1;
+ if (!isNaN(+weightForPlatform))
+ return +weightForPlatform;
+ const metricId = measurementSet.metricId();
+ if (typeof weightForPlatform != 'object' || isNaN(+weightForPlatform[metricId]))
+ return 1
+ return +weightForPlatform[metricId];
+ }
+
_fetchAndComputeRatio(set, timeRange)
{
var setToRatio = this._setToRatio;
Modified: trunk/Websites/perf.webkit.org/unit-tests/statistics-tests.js (283152 => 283153)
--- trunk/Websites/perf.webkit.org/unit-tests/statistics-tests.js 2021-09-27 23:05:18 UTC (rev 283152)
+++ trunk/Websites/perf.webkit.org/unit-tests/statistics-tests.js 2021-09-27 23:33:04 UTC (rev 283153)
@@ -62,6 +62,16 @@
});
});
+
+ describe('weightedMean',() => {
+ it('should return mean with weight', () => {
+ assert.equal(Statistics.weightedMean([{value: 1, weight: 1}, {value: 2, weight: 2},
+ {value: 3, weight: 3}, {value: 4, weight: 4}]), 3);
+ assert.equal(Statistics.weightedMean([{value: 1, weight: 1}, {value: 2, weight: 0},
+ {value: 3, weight: 0}, {value: 4, weight: 0}]), 1);
+ });
+ });
+
describe('squareSum', function () {
it('should find the square sum of values', function () {
assert.equal(Statistics.squareSum([1, 2, 3, 4]), 30);