This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
stats.js
78 lines (69 loc) · 1.59 KB
/
stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function computeAverageBitrate(switchHistory) {
const bitratesPlayed = {};
let totalDuration = 0;
let average = 0;
switchHistory.forEach(s => {
const { start, end, quality: { bitrate } } = s;
const durationPlayed = end - start;
const prevTotal = totalDuration;
totalDuration += durationPlayed;
average = ((average * (prevTotal / totalDuration) + (bitrate * (durationPlayed / totalDuration))));
});
return average;
}
module.exports = { computeAverageBitrate };
const data = {
"switchHistory": [
{
"start": 16.238865,
"end": 17.67047,
"quality": {
"mediaType": "video",
"bitrate": 1000000,
"width": 1280,
"height": 720,
"scanType": null,
"qualityIndex": 2
}
},
{
"start": 17.67047,
"end": 41.155665,
"quality": {
"mediaType": "video",
"bitrate": 200000,
"width": 640,
"height": 360,
"scanType": null,
"qualityIndex": 0
}
}
],
"stallDuration": 7306.010000029346,
"avgLatency": 1.0841599999999998,
"avgBufferLength": 0.49329600000000023
}
const testData = [
{
start: 0,
end: 10,
quality: {
bitrate: 100
}
},
{
start: 10,
end: 20,
quality: {
bitrate: 200
}
},
{
start: 20,
end: 30,
quality: {
bitrate: 100
}
},
]
// console.log(computeAverageBitrate(testData));