-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
119 lines (118 loc) · 3.66 KB
/
index.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
<title>Data Visualization</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.min.js"></script>
<style>
body,
html,
#timeseriesPlot {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.loader {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
}
.loader-inner {
border: 5px solid #f3f3f3;
border-top: 5px solid #3498db;
border-radius: 50%;
width: 100px;
height: 100px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.loader-text {
position: absolute;
top: 130%;
left: 50%;
transform: translateX(-50%);
font-size: 20px;
color: #000;
}
</style>
</head>
<body>
<div class="loader" id="loader">
<div class="loader-inner"></div>
<div class="loader-text">Loading...</div>
</div>
<div id="timeseriesPlot"></div>
<script>
document.getElementById("timeseriesPlot").style.display = "none";
Papa.parse("https://thechesirecat.github.io/recTrack/output.csv", {
download: true,
header: true,
dynamicTyping: true,
complete: function (results) {
document.getElementById("loader").style.display = "none";
var data = results.data;
document.getElementById("timeseriesPlot").style.display = "block";
var dataByLocation = {};
var minDate = new Date("2023-07-19T18:50:00");
var maxDate = new Date(0);
data.forEach(function (row) {
row.updated = new Date(row.updated);
if (!(row.location_name in dataByLocation)) {
dataByLocation[row.location_name] = [];
}
dataByLocation[row.location_name].push(row);
if (row.updated > maxDate) {
maxDate = row.updated;
}
});
var traces = Object.keys(dataByLocation)
.map(function (location) {
var dates = dataByLocation[location].map((row) => row.updated);
var counts = dataByLocation[location].map(
(row) => row.last_count
);
var movingAvg = counts.map((_, idx, arr) => {
var window = arr.slice(Math.max(0, idx - 6), idx + 1);
return window.reduce((a, b) => a + b, 0) / window.length;
});
return [
// {
// x: dates,
// y: counts,
// type: "scatter",
// mode: "lines+markers",
// name: location + " - Raw",
// opacity: 0.5,
// },
{
x: dates,
y: movingAvg,
type: 'scatter',
mode: 'lines',
name: location + ' - 7 Day Avg',
opacity: 0.5,
}
];
})
.flat();
var layout = {
title: "Last Count Timeseries by Location",
xaxis: { range: [minDate, maxDate], type: "date" },
yaxis: { type: "linear", autorange: true },
};
Plotly.newPlot("timeseriesPlot", traces, layout);
},
});
</script>
</body>
</html>