Public
Edited
Jan 11, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gares_gpe.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
GPE_GARE_LOCALISATION.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
TempsParcoursIntergares.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
frequencesPrevisionelles
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
order_lu_14 = line_14_order.reduce((acc, cur) => {
acc[cur.stop_id] = cur.order;
return acc;
}, {})
Insert cell
db
select s.parent_station as stop_id, s.stop_name, t.stop_sequence::int as order from stop_times_14 t, stops s where t.trip_id = 'IDFM:RATP:100335-C01384-385_5078254_2474602' and t.stop_id = s.stop_id order by t.stop_sequence::int
Insert cell
Insert cell
Insert cell
new_stops_order
Type Table, then Shift-Enter. Ctrl-space for more options.

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
trips_times = {
const routes_data = Object.entries(new_route_headsigns)
// .filter((d) => d[0] === "GPE:14")
.map(([route_id, directions]) => {
const rush = frequencesPrevisionelles.find(
(f) => f.route_id === route_id
);

const standard_frequency = (60 / average_frequency.normal) * 60;

return [
generateTripTime(
route_id,
0,
true,
1,
standard_frequency,
rush.fréquence_s
),
// inbound rh-1
generateTripTime(
route_id,
1,
true,
1,
standard_frequency,
rush.fréquence_s
),
// outbound rh-2
generateTripTime(
route_id,
0,
true,
2,
standard_frequency,
rush.fréquence_s
),
// inbound rh-2
generateTripTime(
route_id,
1,
true,
2,
standard_frequency,
rush.fréquence_s
),
// outbound sh-2
generateTripTime(
route_id,
0,
false,
2,
standard_frequency,
rush.fréquence_s
),
// inbound sh-2
generateTripTime(
route_id,
1,
false,
2,
standard_frequency,
rush.fréquence_s
),
// outbound sh-1
generateTripTime(
route_id,
0,
false,
1,
standard_frequency,
rush.fréquence_s
),
// inbound sh-1
generateTripTime(
route_id,
1,
false,
1,
standard_frequency,
rush.fréquence_s
)
];
})
.flat();

return routes_data.reduce(
(acc, cur) => {
acc.trips = [...acc.trips, ...cur.trips];
acc.stop_times = [...acc.stop_times, ...cur.stop_times].flat();
return acc;
},
{ trips: [], stop_times: [] }
);
}
Insert cell
generateTripTime = (
route,
direction,
rush,
stop_hour,
standard_frequency,
rush_hour_frequency
) => {
const service_id = `GPE:${rush ? "rh" : "sh"}-${stop_hour}`;
const trip_headsign = new_route_headsigns[route][direction];
const trips = [];
const stop_times = [];
const { stops, trip_duration } = new_routes_stop_sequences[route][direction];

const morning_breakpoint = (stop_hour + 0.25) * 60 * 60 + 24 * 60 * 60; // 24h + stop hour
const morning_rush_start = 7 * 60 * 60;
const morning_rush_end = 10 * 60 * 60;
const evening_rush_start = 16 * 60 * 60;
const evening_rush_end = 20 * 60 * 60;
// set time to service start time of 5h30
let time_s = 5.5 * 60 * 60;

while (time_s < morning_breakpoint) {
if (!rush) {
// standard trip frequency
// build trip
const trip = buildTrip(
route,
service_id,
trip_headsign,
direction,
time_s
);
trips.push(trip);
// build trip stops
const times = buildStopTimes(
trip.trip_id,
route,
direction,
time_s,
standard_frequency
);
stop_times.push(times);
// jump to next trip
time_s = time_s + standard_frequency;
} else {
// rush hour sucseptible
if (
(time_s > morning_rush_start && time_s < morning_rush_end) ||
(time_s > evening_rush_start && time_s < evening_rush_end)
) {
// build trip
const trip = buildTrip(
route,
service_id,
trip_headsign,
direction,
time_s
);
trips.push(trip);
// build trip stops
const times = buildStopTimes(
trip.trip_id,
route,
direction,
time_s,
rush_hour_frequency
);
stop_times.push(times);
// jump to next trip
time_s = time_s + rush_hour_frequency;
} else {
// build trip
const trip = buildTrip(
route,
service_id,
trip_headsign,
direction,
time_s
);
trips.push(trip);
// build trip stops
const times = buildStopTimes(
trip.trip_id,
route,
direction,
time_s,
standard_frequency
);
stop_times.push(times);
// jump to next trip
time_s = time_s + standard_frequency;
}
}
}
return { trips, stop_times };
}
Insert cell
buildTrip = (route_id, service_id, trip_headsign, direction_id, trip_tag) => {
return {
route_id,
service_id,
trip_id: `${route_id}:${service_id.replace(
"GPE:",
""
)}:${direction_id}-${trip_tag}`,
trip_headsign,
trip_short_name: "",
direction_id,
block_id: "",
shape_id: "",
wheelchair_accessible: 1,
bikes_allowed: 0
};
}
Insert cell
buildStopTimes = (trip_id, route_id, direction, start_time, frequency) => {
const stops = new_routes_stop_sequences[route_id][direction].stops;
let stop_times = [];
let arrival = +start_time;
stops.forEach((stop) => {
const time = formatSeconds(arrival);
stop_times.push({
trip_id,
arrival_time: time,
departure_time: time,
stop_id: stop.stop_id,
stop_sequence: stop.order - 1,
stop_headsign: "",
pickup_type: 0,
drop_off_type: 0,
continuous_pickup: 1,
continuous_drop_off: 1,
timepoint: 0
});
arrival = arrival + stop.ttn;
});
return stop_times;
}
Insert cell
Insert cell
Insert cell
{
map.getSource("points").setData(
turf.featureCollection(
new_stops.map((d) => {
return turf.point([+d.stop_lon, +d.stop_lat], d);
})
)
);
return md`add stops to map...`;
}
Insert cell
Insert cell
db
select * from stops where stop_id in (
select parent_station from stops where stop_id in (select stop_id from stop_times_14)
)
Insert cell
Insert cell
Insert cell
db = DuckDBClient.of({
routes: await FileAttachment("routes.txt").csv(),
stops: await FileAttachment("stops.txt").csv(),
trips: await FileAttachment("trips.txt").csv(),
agency: await FileAttachment("agency.txt").csv(),
calendar: await FileAttachment("calendar.txt").csv(),
calendar_dates: await FileAttachment("calendar_dates.txt").csv(),
transfers: await FileAttachment("transfers.txt").csv(),
stop_extensions: await FileAttachment("stop_extensions.txt").csv(),
stop_times_14: await FileAttachment("stop_times_14.csv").csv()
})
Insert cell
stops = FileAttachment("stops.txt").csv()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatSeconds = (seconds) => {
const midnight = 24 * 60 * 60;
let [HH, MM, SS] = new Date(seconds * 1000)
.toISOString()
.slice(11, 19)
.split(":");
if (seconds >= midnight) {
HH = parseInt(HH) + 24;
}
return [HH, MM, SS].join(":");
}
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