Public
Edited
Feb 8, 2023
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stage_list = {
let stage = {};

// Iterate through every route and build a dictionary of stops
routes.forEach((r) =>
r.stops.forEach((s, idx) => {
if (!stage.hasOwnProperty(s.stop_name)) {
stage[s.stop_name] = {};
}

// Add to list of routes at this stop
if (idx == 0 || idx == r.stops.length - 1) {
(stage[s.stop_name].terminal_routes =
stage[s.stop_name].terminal_routes || []).push(r.id);
}
(stage[s.stop_name].routes = stage[s.stop_name].routes || []).push(r.id);

// Add coordinates from stage_mapping data
stage["latLng"] = {};
})
);

return stage;
}
Insert cell
timings = timings_data.split("\n").map((d) => {
let row = JSON.parse(d);
row["trips"] = 0;
row["time_table"] = {};
row.stop_timings.forEach((stop) => {
stop.timings.forEach((time) => {
row["trips"]++;

if (!row["time_table"].hasOwnProperty(parseTime(time).hours))
row["time_table"][parseTime(time).hours] = [];
row["time_table"][parseTime(time).hours].push(parseTime(time).minutes);
});
});
return row;
})
Insert cell
Insert cell
master_data = []
Insert cell
fetch(
"https://production.zophop.com/scheduler_v4/v4/CHENNAI/routedetails?route_id=YaDtnnOv&day=wednesday"
)
.then((response) => response.json())
.then((data) => {
master_data.push(data);
})
Insert cell
{
let route_data = {};
routes_data_live.slice(0, 2).forEach((route) =>
fetch(
"https://production.zophop.com/scheduler_v4/v4/CHENNAI/routedetails?route_id=YaDtnnOv&day=wednesday"
)
.then((response) => response.json())
.then((data) => {
master_data["a"] = data;
})
);
return route_data;
}
Insert cell
updateData()
Insert cell
async function updateData() {
// fetch the data from a URL
const response = await fetch("https://api.example.com/data");
const data = await response.json();

// update the value of the cell "data"
return data;
}
Insert cell
Insert cell
function parseTime(time) {
const [hours, minutes] = time.split(':').map(Number);
const ampm = hours >= 12 ? 'PM' : 'AM';
return { hours: (hours % 24) || 24, minutes, ampm };
}
Insert cell
function buildWktLinestring(latlngs) {
var wkt = "LINESTRING(";
latlngs.forEach(function (latlng, index) {
wkt += latlng[1] + " " + latlng[0];
if (index < latlngs.length - 1) {
wkt += ",";
}
});
wkt += ")";
return wkt;
}
Insert cell
Insert cell
Insert cell
timings_data = fetch(
"https://gist.githubusercontent.com/planemad/77020523bf75020109c2a9371ad18df6/raw/5c08407f88818e40570eb7f116460a3dbb3fcbae/mtc_route_timings.jsonl"
).then((response) => response.text())
Insert cell
routes_data_live = fetch(
"https://production.zophop.com/scheduler_v4/v4/CHENNAI/autocomplete/route?str=&station_type=bus&day=wednesday&agency=mtc"
).then((response) => response.json())
Insert cell
stop_data_live = fetch(
"https://production.zophop.com/scheduler_v4/v4/CHENNAI/autocomplete/stop?str=&station_type=bus&day=wednesday&agency=mtc"
).then((response) => response.json())
Insert cell
routes_detail_data_live = fetch(
"https://production.zophop.com/scheduler_v4/v4/CHENNAI/routedetails?route_id=YaDtnnOv&day=wednesday"
).then((response) => response.json())
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