-
Notifications
You must be signed in to change notification settings - Fork 0
/
factor.html
43 lines (34 loc) · 1019 Bytes
/
factor.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Rolling Average Growth Factor</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="chart"></canvas>
</body>
<script src="util.js"></script>
<script>
chart.options.scales.yAxes[0].scaleLabel.labelString = 'Rolling average growth factor';
var days = 5;
function getGrowthFactor(data, day) {
const span = days;
let sum = 0, total = 0;
for (let x = day - span + 1; x <= day; x += 1) {
sum += data[x].confirmed;
total += data[x - 1].confirmed;
}
return sum / total;
}
start(data => {
let result = [];
for (const [i, e] of data.entries()) {
if (e.confirmed < 100 || i < days || !data[i - days].confirmed) continue;
result.push(getGrowthFactor(data, i));
}
return result;
});
</script>
</html>