-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
203 lines (180 loc) · 5.54 KB
/
Copy pathindex.html
File metadata and controls
203 lines (180 loc) · 5.54 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
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>恐竜博物館ダッシュボード</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>恐竜博物館ダッシュボード</h1>
<h2>60日先までの予約状況(人数、金額、平均単価)</h2>
<h4>※<span class=span_date></span>時点の事前予約数です。最終的な予約数や入館者数は異なります。</h4>
<div id=chart></div>
<script type="module">
import { CSV } from "https://js.sabae.cc/CSV.js";
import { Day } from "https://js.sabae.cc/DateTime.js";
//const capacity = 407;
const getFile = async (url) => {
const csv = await CSV.fetch(url);
const map = {
"n_people": "利用総人数",
"amount_fee": "利用合計",
"date_visit": "利用開始日",
};
console.log(csv[0]);
for (let i = 0; i < csv[0].length; i++) {
csv[0][i] = map[csv[0][i]];
}
return CSV.toJSON(csv);
};
const makeColumns = (data, startday, colnames) => {
const dates = [];
//const startday = new Day();
const endday = startday.dayAfter(60);
for (let d = startday; !d.equals(endday); d = d.dayAfter(1)) {
dates.push(d.toStringYMD());
}
dates.unshift("x");
const cols = [];
cols.push(dates);
for (let j = 0; j < colnames.length; j++) {
const colname = colnames[j];
const nrsv = [];
nrsv.push(colname);
for (const d of data) {
nrsv.push(parseInt(d[colname]));
}
cols.push(nrsv);
}
return cols;
};
const NAME_FEE = "利用合計";
const NAME_AVE = "客平均単価";
const showChart = (bindto, columns) => {
const axes = {};
for (const n of [NAME_FEE]) {
axes[n] = "y2";
}
const chart = c3.generate({
bindto: '#chart',
data: {
x: 'x',
xFormat: '%Y%m%d', // 'xFormat' can be used as custom format of 'x'
columns,
axes,
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
},
y: {
min: 0,
},
y2: {
show: true,
min: 0,
},
},
tooltip: {
format: {
value: (value) => d3.format(",")(value),
}
},
});
};
// データが有効なファイル名をここで決定する
let dinosaurDataUrl = "./latest_dino_sum.csv";
let baseDate = new Day();
const thresholdPeople = 0
while (true) {
const dinosaurData = await getFile(dinosaurDataUrl);
const totalPeople = dinosaurData.reduce((sum, d) => {
return sum + parseInt(d.利用総人数);
}, 0);
if (totalPeople > thresholdPeople) {
break;
}
baseDate = baseDate.prevDay();
dinosaurDataUrl = "./data/" + baseDate.toString() + ".csv";
}
const show = async () => {
const colnames = ["利用総人数", NAME_FEE];
const data = await getFile(dinosaurDataUrl);
console.log(data);
const startday = new Day(data[0].利用開始日);
const columns = makeColumns(data, startday, colnames);
console.log("columns", columns);
const adr2 = [NAME_AVE];
for (let i = 1; i < columns[0].length; i++) {
// columns[0] // date
const people = columns[1]; // 人数
const amount = columns[2]; // 利用合計
adr2[i] = (parseInt(amount[i]) / parseInt(people[i])).toFixed(0);
}
columns.push(adr2);
showChart("chart", columns);
const span_date = new Day(columns[0][1]).toString();
for (let i = 0; i < document.getElementsByClassName("span_date").length; i++ ) {
document.getElementsByClassName("span_date")[i].textContent = span_date;
}
};
show();
</script>
<div class=caption>
福井県立恐竜博物館の予約状況オープンデータです。<br>
「<a href=latest_dino_sum.csv>CSVオープンデータ ダウンロード</a>」(<span class=span_date></span>現在)<br>
(関連リンク、<a href=https://code4fukui.github.io/fukui-kanko-advice/area/19.html>福井県AI観光アドバイス - 勝山市 / スーベニアショップ ラプトル エリア</a>、
<a href=https://code4fukui.github.io/fukui-kanko-stat/>福井県観光アンケートオープンデータ活用アプリ</a>)<br>
<br>
<a id="dinosaur-fukui"></a>
<h2>福井で発見された恐竜オープンデータ</h2>
<script type="module" src="https://code4sabae.github.io/js/csv-viewer.js"></script>
<csv-viewer src=./dinosaur-fukui.csv></csv-viewer>
<style>
csv-viewer {
word-break: break-all;
}
csv-viewer td:nth-child(2) {
white-space: nowrap;
}
csv-viewer td, th {
border: 1px solid black;
padding: 0 .5em;
}
csv-viewer table {
margin: .5em 0;
border-collapse: collapse;
}
</style>
<!--
<a href=./dinosaur-fukui.html>福井で発見された恐竜オープンデータ</a><br>
-->
</div>
<style>
body {
text-align: center;
}
#chart {
height: 50vh;
}
.caption {
margin: 1em;
}
a {
color: gray !important;
}
h2 {
margin-top: 0;
margin-bottom: 0;
}
h4 {
margin-top: 0;
margin-bottom: 0;
color: #AAA;
}
</style>
<hr>
データ出典: <a href=https://www.dinosaur.pref.fukui.jp/>FPDM: 福井県立恐竜博物館</a>(協力:<a href=https://www.fuku-e.com/feature/detail_266.html>福井県観光データ分析システム「FTAS」</a> by <a href=https://www.fuku-e.com/>福井県観光連盟</a>)<br>
データ収集&アプリ: <a href=https://github.com/code4fukui/dinosaur-opendata/>オープンソース on GitHub</a> by <a href=https://code4fukui.github.io/>Code for FUKUI</a><br>
</body></html>