1<!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<link rel="import" href="/tracing/model/user_model/user_expectation.html">
8
9<script>
10'use strict';
11
12tr.exportTo('tr.metrics.sh', function() {
13  // Returns a weight for this score.
14  // score should be a number between 0 and 1 inclusive.
15  // This function is expected to be passed to tr.b.Statistics.weightedMean as
16  // its weightCallback.
17  function perceptualBlend(ir, index, score) {
18    // Lower scores are exponentially more important than higher scores
19    // due to the Peak-end rule.
20    // Other than that general rule, there is no specific reasoning behind this
21    // specific formula -- it is fairly arbitrary.
22    return Math.exp(1 - score);
23  }
24
25  function filterExpectationsByRange(irs, opt_range) {
26    var filteredExpectations = [];
27    irs.forEach(function(ir) {
28      if (!(ir instanceof tr.model.um.UserExpectation))
29        return;
30
31      if (!opt_range ||
32          opt_range.intersectsExplicitRangeExclusive(ir.start, ir.end))
33        filteredExpectations.push(ir);
34    });
35    return filteredExpectations;
36  }
37
38  return {
39    perceptualBlend: perceptualBlend,
40    filterExpectationsByRange: filterExpectationsByRange
41  };
42});
43</script>
44