Public
Edited
Mar 19, 2023
Insert cell
Insert cell
taqbin = FileAttachment("ta-q-bin.json").json()
//taqbin = FileAttachment("ta-q-bin-time.json").json()
Insert cell
tt_label = "所要日数"
Insert cell
taqbin_rtt = taqbin.filter((d) => d.size === tt_label)
Insert cell
// if length is 1 then then region is the prefecture
// if length is more than 1 then first item is region and rest are prefecture
region_dict = {
const dict = {};

for (const lane of taqbin_rtt) {
const loc = lane.area
.replaceAll("・", " ")
.replaceAll("(", " ")
.replaceAll(")", "")
.split(" ");

const spliceIndex = loc.length > 1 ? 1 : 0;
const region = loc[0];
const prefectures = loc.splice(spliceIndex);
const id = lane.area;

dict[id] = { region, prefectures };
}

return dict;
}
Insert cell
ken_list = {
const ken = [];

for (const [key, obj] of Object.entries(region_dict)) {
ken.push(...obj.prefectures);
}

return ken.map((d, i) => [i + 1, d]);
}
Insert cell
taqbin_matrix = {
const matrix = [];

const regionList = Object.keys(region_dict);
for (const row of taqbin_rtt) {
const from_ken = region_dict[row.area].prefectures;
for (const from_name of from_ken) {
const lane = { from: from_name };
for (const col of regionList) {
const to_ken = region_dict[col].prefectures;
const tt = row[col];
for (const to_name of to_ken) {
lane.to = to_name;
lane.tt = tt;
// lane[to_name] = tt;
matrix.push(lane);
}
}
// matrix.push(lane);
}
}

return matrix;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more