Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found 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 | |
| 14 | tv.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> |