source: trip-planner-front/node_modules/hdr-histogram-percentiles-obj/index.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1'use strict'
2
3const percentiles = module.exports.percentiles = [
4 0.001,
5 0.01,
6 0.1,
7 1,
8 2.5,
9 10,
10 25,
11 50,
12 75,
13 90,
14 97.5,
15 99,
16 99.9,
17 99.99,
18 99.999
19]
20
21module.exports.histAsObj = function (hist, total) {
22 const mean = Math.ceil(getMean(hist) * 100) / 100
23 const result = {
24 average: mean, // added for backward compat with wrk
25 mean: mean,
26 stddev: Math.ceil(getStdDeviation(hist) * 100) / 100,
27 min: getMin(hist),
28 max: getMax(hist)
29 }
30
31 if (typeof total === 'number') {
32 result.total = total
33 }
34
35 return result
36}
37
38module.exports.addPercentiles = function (hist, result) {
39 percentiles.forEach(function (perc) {
40 const key = ('p' + perc).replace('.', '_')
41 if (typeof hist.percentile === 'function') {
42 result[key] = hist.percentile(perc)
43 } else if (typeof hist.getValueAtPercentile === 'function') {
44 result[key] = hist.getValueAtPercentile(perc)
45 }
46 })
47
48 return result
49}
50
51function getMean (hist) {
52 if (typeof hist.mean === 'function') {
53 return hist.mean()
54 }
55 if (typeof hist.getMean === 'function') {
56 return hist.getMean()
57 }
58 return hist.mean
59}
60
61function getMin (hist) {
62 if (typeof hist.min === 'function') {
63 return hist.min()
64 }
65 return hist.minNonZeroValue
66}
67
68function getMax (hist) {
69 if (typeof hist.max === 'function') {
70 return hist.max()
71 }
72 return hist.maxValue
73}
74
75function getStdDeviation (hist) {
76 if (typeof hist.stddev === 'function') {
77 return hist.stddev()
78 }
79 if (typeof hist.getStdDeviation === 'function') {
80 return hist.getStdDeviation()
81 }
82 return hist.stdDeviation
83}
Note: See TracBrowser for help on using the repository browser.