Public
Edited
Apr 4
Importers
1 star
Insert cell
Insert cell
viewof yyyy_mm = Inputs.text({
label: "Month",
type: "month",
min: "2018-01",
max: max_year_month,
value: max_year_month
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// read query param from URL and set month selection
c_m = {
const [Y, M] = max_year_month.split("-");
const ym = params.get("yyyy_mm");

let [y, m] = ym ? ym.split("-") : [Y, M];
m = m ? +m : +M;
y = y ? +y : +Y;
set(viewof yyyy_mm, "" + y + "-" + d3.format("02d")(m));
return [m, y];
}
Insert cell
Insert cell
Insert cell
Insert cell
response = await fetchp(file_url)
Insert cell
response.text()
Insert cell
// read from attached file if present, otherwise from relevant remote file on EUROCONTROL website.
// BUT read only from remote for the newest file if at least 3rd of the month.
rates = {
// candidate filename
// const fff = files[`ur-${mY[1]}-${d3.format("02d")(mY[0])}.txt`];
const fff = files[`ur-${yyyy_mm}.txt`];
// if file for selected month is in FileAttachments, pick it from there
if (fff) {
const values = await fff.tsv({ array: true, typed: false });
const rates = values.slice().map((d) => ({
airspace: d[0].trim(), // trim needed because of Jun 2021 file!!!!!!
start: parseDate(d[1]),
end: parseDate(d[2]),
unit_rate_global: +d[3] / 100.0,
euro_exchange_rate: +d[4],
currency: d[5],
name: d[6]
}));
return rates;
} else {
// check if the resource exists
const response = await fetch(cors_url);
if (response.status === 200) {
return d3.text("https://corsproxy.io/?" + file_url).then((source) => {
return d3.tsvParseRows(source, (d) => {
return {
airspace: d[0],
start: parseDate(d[1]),
end: parseDate(d[2]),
unit_rate_global: +d[3] / 100.0,
euro_exchange_rate: +d[4],
currency: d[5],
name: d[6]
};
});
});
} else {
// const today = new Date();
// const todayYear = +today.getUTCFullYear();
// const todayMonth = +today.getUTCMonth() + 1;
// const dayOfMonth = +today.getUTCDate();
// if (mY[0] == todayMonth && mY[1] == todayYear && dayOfMonth <= 2) {
// mY[0] = todayMonth - 2;
// pick last in file attachments

// DO NOT exceed current month
const last_file = Object.keys(files).at(-1).split(".")[0];
const ym = last_file.split("-");
// set(viewof mY, [+ym[2], +ym[1]]);
set(viewof yyyy_mm, last_file);

const values = await files[Object.keys(files).at(-1)].tsv({
array: true,
typed: false
});
const rates = values.slice().map((d) => ({
airspace: d[0].trim(), // trim needed because of Jun 2021 file!!!!!!
start: parseDate(d[1]),
end: parseDate(d[2]),
unit_rate_global: +d[3] / 100.0,
euro_exchange_rate: +d[4],
currency: d[5],
name: d[6]
}));
return rates;
}
// }
}
}
Insert cell
Insert cell
Insert cell
Insert cell
{
// d3
// .tsvParse(
const r = await fetchp(
"https://www.eurocontrol.int/sites/default/files/2025-04/ur-2025-04.txt"
).then((response) => response.text());
// )
// .slice()
// .map((d) => ({
// airspace: d[0], // trim needed because of Jun 2021 file!!!!!!
// start: parseDate(d[1]),
// end: parseDate(d[2]),
// unit_rate_global: +d[3] / 100.0,
// euro_exchange_rate: +d[4],
// currency: d[5],
// name: d[6]
// }))

const r1 = d3.tsvParseRows(r, (d) => {
return {
airspace: d[0].trim(),
start: parseDate(d[1]),
end: parseDate(d[2]),
unit_rate_global: +d[3] / 100.0,
euro_exchange_rate: +d[4],
currency: d[5].trim(),
name: d[6].trim()
};
});
return r1;
}
Insert cell
d3.tsv("https://www.eurocontrol.int/sites/default/files/2024-08/ur-2024-08.txt")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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