-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
273 lines (245 loc) · 7.27 KB
/
index.html
File metadata and controls
273 lines (245 loc) · 7.27 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>人流データ - FTASオープンデータ</title>
<script src="https://cdn.jsdelivr.net/npm/d3@5.16.0/dist/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/c3@0.7.20/c3.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/c3@0.7.20/c3.min.css" rel="stylesheet">
</head><body>
<h1>人流データ - FTASオープンデータ</h1>
<select id=selarea></select><select id=sellocation></select>
表示期間 <input type=date id=dtstart> - <input type=date id=dtend> <button id=btndl>CSVダウンロード</button>
<div id=chart1></div>
<div id=chart></div>
<hr>
<a href=https://github.com/code4fukui/jinryu/>src on GitHub</a><br>
<script type="module">
import { ArrayUtil } from "https://js.sabae.cc/ArrayUtil.js";
import { fetchDataJinryu } from "./fetchDataJinryu.js";
import { Day } from "https://js.sabae.cc/DateTime.js";
import { CSV } from "https://js.sabae.cc/CSV.js";
import { downloadFile } from "https://js.sabae.cc/downloadFile.js";
const localStorageKey = "searchInfo";
const saveSearchInfo = () => {
localStorage.setItem(localStorageKey, JSON.stringify({
area: selarea.value,
location: sellocation.value,
startDate: dtstart.value,
endDate: dtend.value
}));
};
const param = new URL(location.href).searchParams;
//const seliccid = param.get("iccid") || "8981040000001207740";
const setLocationOptions = () => {
const area = selarea.value;
sellocation.innerHTML = "";
for (const p of place) {
if (p.area != area) continue;
const opt = document.createElement("option");
opt.textContent = p.location;
opt.value = p.iccid;
sellocation.appendChild(opt);
}
};
selarea.oninput = () => {
setLocationOptions();
saveSearchInfo();
};
const place = await CSV.fetchJSON("https://push.sabae.cc/1005.csv");
const areas = ArrayUtil.toUnique(place.map(p => p.area));
for (const area of areas) {
const opt = document.createElement("option");
opt.textContent = area;
selarea.appendChild(opt);
}
const fetchData = async (iccid) => {
const data = await fetchDataJinryu(iccid);
console.log(data);
/*
const res = {};
const dates = ArrayUtil.toUnique(data.map(d => d.dt.substring(0, "2023-06-19".length)));
for (const date of dates) {
const datad = data.filter(d => d.dt.startsWith(date) && d.iccid == seliccid).map(d => ({ t: d.dt.substring("2023-06-19T".length, "2023-06-19T00:00:00".length), n: d.data }));
res[date] = datad;
}
return res;
*/
return data;
};
const showChartByDay = (bindto, data) => {
const dt = ArrayUtil.toUnique(data.map(d => d.dt.substring(0, 10)));
//console.log(dt);
const cnt = [];
for (const day of dt) {
const f = data.filter(d => d.dt.startsWith(day));
const n = f.reduce((pre, cur) => pre + parseInt(cur.data), 0);
cnt.push(n);
}
//console.log(dt, cnt);
const chart = c3.generate({
bindto,
data: {
x: 'x',
columns: [
['x', ...dt],
['count', ...cnt],
]
},
axis: {
x: {
type: "timeseries",
tick: {
//format: '%Y-%m-%dT%H:%M:%S+09:00'
format: '%Y-%m-%d', //+09:00'
//format: '%Y-%m-%d %H' // %H:%M:%S', //+09:00'
rotate: 50,
}
}
},
zoom: {
enabled: true,
}
});
/*
const chart = c3.generate({
data: {
columns: [
//['hour', ...dt],
...cnt,
]
},
});
*/
};
const makeDataByDay = (data, iccid) => {
const res = {};
const dates = ArrayUtil.toUnique(data.map(d => d.dt.substring(0, "2023-06-19".length)));
for (const date of dates) {
const datad = data.filter(d => d.dt.startsWith(date)).map(d => ({ t: d.dt.substring("2023-06-19T".length, "2023-06-19T00:00:00".length), n: d.data }));
res[date] = datad;
}
return res;
};
const makeData = (data) => {
const sdt = new Day(dtstart.value);
const edt = new Day(dtend.value);
const data2 = data.filter(d => new Day(d.dt.substring(0, 10)).includes(sdt, edt));
return data2;
};
const show = async (iccid) => {
console.log("show", iccid);
//return;
//
const data = await fetchData(iccid);
if (!dtstart.value) {
dtstart.value = data[0].dt.substring(0, 10);
}
if (!dtend.value) {
dtend.value = data[data.length - 1].dt.substring(0, 10);
}
const data2 = makeData(data);
showChartByDay("#chart1", data2);
const dataday2 = makeDataByDay(data2);
showChart("#chart", dataday2);
dtstart.oninput = dtend.oninput = () => {
saveSearchInfo();
const data2 = makeData(data);
showChartByDay("#chart1", data2);
const dataday2 = makeDataByDay(data2);
showChart("#chart", dataday2);
};
//
btndl.onclick = () => {
const sdt = new Day(dtstart.value);
const edt = new Day(dtend.value);
const data2 = data.filter(d => new Day(d.dt.substring(0, 10)).includes(sdt, edt));
/*
const dataday = makeDataByDay(data2);
console.log("DATADAY", dataday);
const list = [];
list.push(["datetime", "count"]);
for (let i = 0; i < cnt.length; i++) {
const date = cnt[i][0];
for (let j = 0; j < dt.length; j++) {
const n = cnt[i][j + 1];
if (!isNaN(n)) {
list.push([date + " " + dt[j] + ":00", n]);
}
}
}
console.log("LIST", list);
const csv = CSV.encode(list);
console.log(csv);
downloadFile("jinryudata.csv", csv);
*/
downloadFile("jinryudata.csv", CSV.stringify(data2));
};
};
const showChart = (bindto, data) => {
console.log("SHOWCHART",data)
const dt = [];
for (let i = 0; i < 24; i++) {
const h = i < 10 ? "0" + i : "" + i;
dt.push(h);
}
const days = Object.keys(data);
const cnt = [];
for (const day of days) {
const data1 = [];
data1.push(day);
const data0 = data[day];
for (const h of dt) {
const f = data0.filter(d => d.t.startsWith(h));
if (f.length) {
const dd = f.reduce((prev, d) => prev + parseInt(d.n), 0);
data1.push(dd);
} else {
data1.push(NaN);
}
}
cnt.push(data1);
}
const chart = c3.generate({
bindto,
data: {
columns: [
//['hour', ...dt],
...cnt,
]
},
});
};
const redraw = async () => {
const iccid = sellocation.value;
show(iccid);
};
selarea.addEventListener("input", () => {
redraw();
});
sellocation.oninput = () => {
saveSearchInfo();
redraw();
};
const storage = localStorage.getItem(localStorageKey);
if (storage) {
const searchInfo = JSON.parse(storage);
const areaOptions = [...selarea.options];
const areaIndex = areaOptions.findIndex(o => {
return o.value == searchInfo.area;
});
selarea.options[areaIndex].selected = true;
// locationのoptionsを作成しないとlocationが選択できないため事前に作成する
setLocationOptions();
const locationOptions = [...sellocation.options];
const locationIndex = locationOptions.findIndex(o => {
return o.value == searchInfo.location;
});
sellocation.options[locationIndex].selected = true;
dtstart.value = searchInfo.startDate;
dtend.value = searchInfo.endDate;
} else {
setLocationOptions();
}
setInterval(redraw, 5 * 60 * 1000);
await redraw();
</script>
<script type="module" src="https://js.sabae.cc/QRCode.js"></script>
<qr-code></qr-code>