blob: 59c6bae965343e586e94d408e01acca633a275d6 [file] [log] [blame]
Chris Craik44c28202015-05-12 17:25:16 -07001<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/base/base.html">
9<link rel="import" href="/base/statistics.html">
10<link rel="import" href="/base/iteration_helpers.html">
11<script>
12'use strict';
13
14tv.exportTo('tv.e.audits', function() {
15
16 function RAILScore() {
17 };
18
19 RAILScore.compute = function(rirs) {
20 if (rirs.length === 0)
21 throw new Error('Impossible');
22
23 var railScoresByTypeName = {};
24 rirs.forEach(function(ir) {
25 if (railScoresByTypeName[ir.railTypeName] === undefined)
26 railScoresByTypeName[ir.railTypeName] = [];
27 railScoresByTypeName[ir.railTypeName].push(ir);
28 });
29
30 var result = {};
31
32 var overallRailScores = [];
33 tv.b.iterItems(railScoresByTypeName, function(railTypeName, irs) {
34 var minRailScoreForType = tv.b.Statistics.sum(irs, function(ir) {
35 return ir.railScore;
36 });
37 result['sum(' + railTypeName + ')'] = minRailScoreForType;
38 overallRailScores.push(minRailScoreForType);
39 });
40
41 result.score = tv.b.Statistics.sum(overallRailScores);
42 return result;
43 }
44
45 return {
46 RAILScore: RAILScore
47 };
48});
49</script>