| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/extras/rail/rail_interaction_record.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.exportTo('tr.e.rail', function() { |
| function RAILScore(opt_irs) { |
| this.interactionRecords_ = []; |
| if (opt_irs) |
| this.interactionRecords_.push.apply(this.interactionRecords_, opt_irs); |
| }; |
| |
| RAILScore.prototype = { |
| get interactionRecords() { |
| return this.interactionRecords_; |
| }, |
| |
| get overallScore() { |
| if (!this.interactionRecords.length) |
| return undefined; |
| var overall = 0; |
| this.interactionRecords.forEach(function(ir) { |
| overall += Math.pow(ir.railScore, 2) / this.interactionRecords.length; |
| // TODO(benjhayden) Implement a better algorithm as discussed in the |
| // following document. |
| // https://docs.google.com/document/d/1d6cywyfR58uYBGJvq5eBebwKcVVvaaHxU1dJEj3LX3E |
| }.bind(this)); |
| return overall; |
| } |
| }; |
| |
| RAILScore.fromModel = function(model) { |
| var rirs = model.interaction_records.filter(function(ir) { |
| return ir instanceof tr.e.rail.RAILInteractionRecord; |
| }); |
| if (rirs.length === 0) |
| return undefined; |
| return new RAILScore(rirs); |
| }; |
| |
| return { |
| RAILScore: RAILScore |
| }; |
| }); |
| </script> |