-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
491 lines (444 loc) · 15.6 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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html><html lang="ja"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>あわら温泉エリア 宿泊予約状況(データ出典:福井県観光連盟)</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</head><body>
<h1>あわら温泉エリア 宿泊予約状況(データ出典:福井県観光連盟)</h1>
期間:<input type="date" id=fromDate min="2023-10-01" />~<input type="date" id=toDate min="2023-10-01" />
<ul class="nav nav-tabs" id="chartTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="chart-tab" data-bs-toggle="tab" data-bs-target="#chartContent" type="button" role="tab" aria-controls="chartContent" aria-selected="true">全合計</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="bar-chart-tab" data-bs-toggle="tab" data-bs-target="#barChartContent" type="button" role="tab" aria-controls="barChartContent" aria-selected="false">都道府県別(β)</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="booking-curve-tab" data-bs-toggle="tab" data-bs-target="#bookingCurveChartContent" type="button" role="tab" aria-controls="bookingCurveChartContent" aria-selected="false">ブッキングカーブ(β)</button>
</li>
</ul>
<div class="tab-content" id="chartTabContent">
<div id=chartContent class="tab-pane fade show active">
<div id="chart"></div>
</div>
<div id=barChartContent class="tab-pane fade show">
項目:<select id="barChartCategory" class="my-2">
<option selected>利用総人数</option>
<option>利用金額合計</option>
</select>
<div id="barChart"></div>
</div>
<div id=bookingCurveChartContent class="tab-pane fade show">
<div id="bookingCurve"></div>
</div>
</div>
<script type="module">
import { CSV } from "https://js.sabae.cc/CSV.js";
import { Day } from "https://js.sabae.cc/DateTime.js";
import { TimeZone } from "https://code4fukui.github.io/day-es/DateTime.js";
import { downloadFile } from "https://js.sabae.cc/downloadFile.js";
import { initC3 } from "https://code4fukui.github.io/c3-es/c3-es.js";
const c3 = initC3(window);
fromDate.setAttribute("value", new Day().toString());
toDate.setAttribute("value", new Day().dayAfter(89).toString());
const hotelData = CSV.toJSON(await CSV.fetch("./latest_hotel.csv"));
totalHotelCount.textContent = hotelData.length;
totalRoomCount.textContent = hotelData.reduce((sum, h) => {
return sum + parseInt(h.nrooms);
}, 0);
const prefectures = ["北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県",
"茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県",
"新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県",
"静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県",
"奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県",
"徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県",
"熊本県","大分県","宮崎県","鹿児島県","沖縄県"
];
const getChartFile = async (targetDate) => {
// const url = "./data/" + targetDate + ".csv";
const url = "./latest_rsv_sum.csv";
const csv = await CSV.fetch(url);
const map = {
"n_room": "室数",
"n_people": "利用総人数",
"n_stay": "平均泊数",
"amount_fee": "利用金額合計",
"n_reserve": "予約件数",
"date_visit": "利用開始日",
};
for (let i = 0; i < csv[0].length; i++) {
csv[0][i] = map[csv[0][i]];
}
return CSV.toJSON(csv);
};
const getBarChartFile = async (targetDate) => {
const url = "./latest_rsv_prefecture_sum.csv";
const csv = await CSV.fetch(url);
const map = {
"prefecture": "都道府県",
"n_room": "室数",
"n_people": "利用総人数",
"n_stay": "平均泊数",
"amount_fee": "利用金額合計",
"n_reserve": "予約件数",
"date_visit": "利用開始日",
};
for (let i = 0; i < csv[0].length; i++) {
csv[0][i] = map[csv[0][i]];
}
return CSV.toJSON(csv);
};
const getBookingCurveFile = async (targetDate) => {
const url = "./booking_curve.csv";
const csv = await CSV.fetch(url);
return CSV.toJSON(csv);
};
const makeChartColumns = (data, startday, endday, colnames) => {
const dates = [];
for (let d = startday; d.includes(startday, endday); d = d.dayAfter(1)) {
dates.push(d.toStringYMD());
}
dates.unshift("x");
const cols = [];
cols.push(dates);
const targetData = data.filter(d => {
const targetDate = new Day(d.利用開始日);
return targetDate.includes(startday, endday);
});
for (let j = 0; j < colnames.length; j++) {
const colname = colnames[j];
const nrsv = Array(dates.length - 1);
nrsv.fill(0);
for (const d of targetData) {
const targetDate = new Day(d.利用開始日);
const startMsec = new Date(startday.year, startday.month - 1, startday.day);
const targetMsec = new Date(targetDate.year, targetDate.month - 1, targetDate.day);
const diffDay = parseInt((targetMsec - startMsec) / 1000 / 60 / 60 / 24);
nrsv[diffDay] = parseInt(d[colname]);
}
nrsv.unshift(colname);
cols.push(nrsv);
}
// 平均泊数
for (let i = 1 ; i < cols[3].length ; i++) {
if (!targetData[i - 1] || parseInt(targetData[i - 1]["予約件数"]) == 0) {
continue;
}
cols[3][i] = (parseInt(cols[3][i]) / parseInt(targetData[i - 1]["予約件数"])).toFixed(2);
}
return cols;
};
const makeBarChartColumns = (data, startday, endday, colname) => {
const dates = [];
for (let d = startday; d.includes(startday, endday); d = d.dayAfter(1)) {
dates.push(d.toStringYMD());
}
dates.unshift("x");
const cols = [];
cols.push(dates);
const prefectureList = {};
for (const prefecture of prefectures) {
prefectureList[prefecture] = Array(dates.length - 1);
prefectureList[prefecture].fill(0);
}
const totalList = Array(dates.length - 1);
totalList.fill(0);
const targetData = data.filter(d => {
const targetDate = new Day(d.利用開始日);
return targetDate.includes(startday, endday);
});
for (const d of targetData) {
if (!prefectures.includes(d.都道府県)) {
continue;
}
const targetDate = new Day(d.利用開始日);
const startMsec = new Date(startday.year, startday.month - 1, startday.day);
const targetMsec = new Date(targetDate.year, targetDate.month - 1, targetDate.day);
const diffDay = parseInt((targetMsec - startMsec) / 1000 / 60 / 60 / 24);
prefectureList[d.都道府県][diffDay] = d[colname];
totalList[diffDay] += parseInt(d[colname]);
}
Object.keys(prefectureList).forEach((key) => {
prefectureList[key] = prefectureList[key].map((p, index) => {
return p / totalList[index] * 100;
});
const d = [key].concat(prefectureList[key]);
cols.push(d);
});
return cols;
};
const makeBookingCurveColumns = (data, startday, endday) => {
const xColumns = [];
for (let n = 0; n <= 90; n++) {
xColumns.push(n);
}
xColumns.unshift("x");
const columns = [];
columns.push(xColumns);
const targetData = data.filter(d => {
const targetDate = new Day(d.target_date);
return targetDate.includes(startday, endday);
});
for (const d of targetData) {
const yColumns = [];
for (let n = 0; n <= 90; n++) {
const y = parseInt(d["ago_" + n + "days"]);
yColumns.push(y);
}
yColumns.unshift(d.target_date);
columns.push(yColumns);
}
return columns;
};
const NAME_FEE = "利用金額合計";
const NAME_OCC = "客室稼働率 (OCC)";
const NAME_ADR = "客室平均単価 (ADR)";
const NAME_AVE = "客平均単価";
const NAME_REVPAR = "RevPAR (OCC x ADR)";
const showChart = (bindto, columns) => {
const axes = {};
for (const n of [NAME_FEE, NAME_AVE, NAME_ADR, NAME_REVPAR]) {
axes[n] = "y2";
}
const chart = c3.generate({
bindto: bindto,
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: {
padding: 0
},
y2: {
padding: 0,
show: true,
},
},
tooltip: {
format: {
value: (value) => d3.format(",")(value),
},
// nullを設定するとデータのカラム順に表示される
order: null
},
regions: [
{
axis: "x",
end: new Date(new Day().prevDay().toString()),
class: "regionX"
}
]
});
};
const showBarChart = (bindto, columns) => {
const chart = c3.generate({
bindto: bindto,
data: {
x: 'x',
xFormat: '%Y%m%d', // 'xFormat' can be used as custom format of 'x'
columns,
type: "bar",
groups: [prefectures],
order: [...prefectures].reverse()
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%Y-%m-%d'
}
},
y: {
max: 100
}
},
tooltip: {
format: {
value: (value, ratio, id, index) => {
return (Math.round(value * 100) / 100) + "%";
},
},
grouped: false
},
regions: [
{
axis: "x",
end: new Date(new Day().prevDay().toString()),
class: "regionX"
}
]
});
};
const showBookingCurve = (bindto, columns) => {
const chart = c3.generate({
bindto: bindto,
data: {
x: 'x',
columns
},
axis: {
x: {
type: 'indexes',
tick: {
count: 46,
format: function (x) {
return x + "日前";
}
},
max: 90
},
y: {
padding: 0,
min: 0
}
},
tooltip: {
// nullを設定するとデータのカラム順に表示される
order: null
}
});
};
const chartData = await getChartFile();
const barChartData = await getBarChartFile();
const bookingCurveData = await getBookingCurveFile();
const show = async (startDate, endDate) => {
if (!startDate || !endDate) {
return;
}
const colnames = ["利用総人数", "室数", "平均泊数", NAME_FEE];
const startday = new Day(startDate);
const endday = new Day(endDate);
const columns = makeChartColumns(chartData, startday, endday, colnames);
const occ = [NAME_OCC];
const adr = [NAME_ADR];
const adr2 = [NAME_AVE];
const revpar = [NAME_REVPAR];
for (let i = 1; i < columns[0].length; i++) {
// columns[0] // date
const people = columns[1]; // 人数
const room = columns[2]; // 室数
const amount = columns[4]; // 利用金額合計
if (room[i] == 0) {
occ[i] = "";
adr[i] = "";
adr2[i] = "";
revpar[i] = "";
} else {
const capacity = hotelData.filter(h => {
return new Date(h.create_file_begin_date) <= new Date(new Day(columns[0][i]).toString());
}).reduce((sum, h) => {
return sum + parseInt(h.nrooms);
}, 0);
occ[i] = (parseInt(room[i]) / capacity * 100).toFixed(1);
adr[i] = (parseInt(amount[i]) / parseInt(room[i])).toFixed(0);
adr2[i] = (parseInt(amount[i]) / parseInt(people[i])).toFixed(0);
revpar[i] = (parseInt(amount[i]) / capacity).toFixed(0);
}
}
columns.push(adr2);
columns.push(occ);
columns.push(adr);
columns.push(revpar);
showChart("#chart", columns);
const today = new Day(TimeZone.JST);
const spanDateElements = document.getElementsByClassName("span-date");
Array.from(spanDateElements).forEach(element => {
element.innerText = `${today.year}年${today.month}月${today.day}日`;
});
};
const loadBarChart = (startDate, endDate, category) => {
const startday = new Day(startDate);
const endday = new Day(endDate);
const barColumns = makeBarChartColumns(barChartData, startday, endday, category);
showBarChart("#barChart", barColumns);
};
const loadBookingCurve = (startDate, endDate) => {
const startday = new Day(startDate);
const endday = new Day(endDate);
const bookingCurveColumns = makeBookingCurveColumns(bookingCurveData, startday, endday);
showBookingCurve("#bookingCurve", bookingCurveColumns);
};
fromDate.onchange = () => {
show(fromDate.value, toDate.value);
loadBarChart(fromDate.value, toDate.value, barChartCategory.value);
loadBookingCurve(fromDate.value, toDate.value);
};
toDate.onchange = () => {
show(fromDate.value, toDate.value);
loadBarChart(fromDate.value, toDate.value, barChartCategory.value);
loadBookingCurve(fromDate.value, toDate.value);
};
barChartCategory.onchange = () => loadBarChart(fromDate.value, toDate.value, barChartCategory.value);
show(fromDate.value, toDate.value);
loadBarChart(fromDate.value, toDate.value, barChartCategory.value);
loadBookingCurve(fromDate.value, toDate.value);
// download csv
dl_csv.onclick = async (e) => {
e.preventDefault();
const fn = "latest_rsv_sum.csv";
const data = await CSV.fetchJSON(fn);
//const capacity = parseInt(totalRoomCount.textContent);
//console.log(hotelData);
data.forEach(i => {
const capacity = hotelData.reduce((pre, j) => {
if (new Day(i.date_visit).isBefore(new Day(j.create_file_begin_date))) {
return pre;
}
return pre + parseInt(j.nrooms);
}, 0);
// n_stay n_people n_room amount_fee n_reserve
i.n_capacity = capacity;
i.OCC = (i.n_room / capacity * 100).toFixed(2) + "%";
i.ADR = (i.amount_fee / i.n_room).toFixed(0);
i.RevPAR = (i.amount_fee / capacity).toFixed(0);
});
const bin = new TextEncoder().encode(CSV.stringify(data));
downloadFile("latest_rsv_sum.csv", bin);
};
</script>
<div class=caption>
福井県あわら温泉エリア、<span id="totalHotelCount"></span>のホテル(総客室数<span id="totalRoomCount"></span>)の予約状況を合算したオープンデータです。(部屋数は<span class="span-date"></span>時点です)<br>
「<a href=latest_rsv_sum.csv>CSVオープンデータ ダウンロード</a>(<a id=dl_csv href=#>OCC/ADR/RevPAR付きCSV</a>)」(<span class="span-date"></span>現在)<br>
<br>
客室稼働率 OCC = Occupancy Ratio = 予約客室数 / 総客室数<br>
客室平均単価 ADR = Average Daily Rate = 販売額 / 予約客室数<br>
RevPAR = Revenue Per Available Rooms = OCC x ADR<br>
</div>
<a href=https://code4fukui.github.io/fukui-kanko-advice/area/11.html>福井県AI観光アドバイス - あわら湯のまち エリア</a><br>
<br>
<a href=https://code4fukui.github.io/fukui-kanko-stat/>福井県観光アンケートオープンデータ活用アプリ</a><br>
<hr>
データ出典: <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/fukui-kanko-reservation/>オープンソース on GitHub</a> by <a href=https://code4fukui.github.io/>Code for FUKUI</a><br>
<style>
body {
text-align: center;
}
#chart {
height: 50vh;
}
#barChart {
height: 50vh;
}
#bookingCurve {
height: 50vh;
}
.caption {
margin: 1em;
}
a {
color: gray !important;
}
.c3-region.regionX {
fill: blue;
}
</style>
</body></html>