-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (58 loc) · 1.97 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
<!doctype html>
<html lang=fr>
<meta charset=utf-8>
<meta name=viewport content="width=device-width">
<meta name=description content="Comparateur de prix des offres d'électricité en France">
<link rel=icon href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚡</text></svg>">
<style>
:root { color-scheme: dark; --accent: darkorange }
a { color: var(--accent); text-decoration: none }
a:hover, a:focus { text-shadow: 0 0 5px }
</style>
<title>watty.top</title>
<input id=file type=file accept=".zip" onchange="handleFiles(this.files)">
<script>
parse = (csv) => {
let day, data = {};
csv.split("\n").forEach((line) => {
const [a, b] = line.split(";");
if (a?.includes("/")) {
const [d, m, y] = a.split("/");
day = `${y}-${m}-${d}`;
data[day] = [];
} else if (a?.includes(":")) {
let [h, m] = a.split(":").map(Number);
if (m === 0 || m === 30) {
const p = h === 0 && m === 0 ? 47 : h * 2 + m / 30 - 1;
data[day][p] = b / 2;
}
}
});
console.log(data);
}
handleFiles = (files) => {
const reader = new FileReader();
reader.onload = ({ target }) => {
const { result } = target;
const td = new TextDecoder();
const view = new DataView(result);
let offset = 0;
while (offset < view.byteLength - 4) {
if (view.getUint32(offset, true) === 0x04034b50) {
const compressedSize = view.getUint32(offset + 18, true);
const nameLength = view.getUint16(offset + 26, true);
const extraLength = view.getUint16(offset + 28, true);
const name = td.decode(new Uint8Array(result, offset + 30, nameLength));
offset += 30 + nameLength + extraLength;
if (/^mes-puissances-atteintes-30min-\d+-\d+\.csv$/.test(name)) {
parse(td.decode(new Uint8Array(result, offset, compressedSize)));
break;
}
} else {
offset++;
}
}
};
reader.readAsArrayBuffer(files[0]);
}
</script>