Departures are grouped by route_id, service_id and direction_id (if
present in trips) and counted within the time of day (at or after from
and before to) as in get_route_frequency(), which thus reports the new
headway (exactly, when the length of the time of day is a multiple of
headway). Departures after midnight are listed with times past
"24:00:00", so use a time of day such as "24:00:00"-"26:00:00" for them.
Times after midnight written as early morning times (e.g. "00:30:00"
instead of "24:30:00"), and end_times earlier than start_times in
frequencies, are first fixed with fix_overnight_times(), so the
returned GTFS has them fixed.
The function changes existing service, it does not create it: groups with
no departure within the time of day are not modified, and scheduled trips
that depart before from are not changed, even if they run within the time
of day. In each other group:
the trips that depart within the time of day are replaced by a single
template: among the trips of the stop pattern (see
get_stop_times_patterns()) with the most departures within the time of
day, the one that departs first. Its travel times apply to all the new
departures. The other trips that depart within the time of day are
removed (frequency-based ones instead lose their frequencies entries
within the time of day, see below);
a frequencies entry is added for the template, from from to to,
with headway_secs set to headway and exact_times = 0; the
transfers entries that refer to the template then apply to all of its
departures;
the existing frequencies entries of the group's trips are cut at from
and to, keeping their departures outside the time of day exactly as
before (as converted by frequencies_to_stop_times() with
strategy = "exact"). Trips left without any departure are removed from
trips, stop_times and transfers.
Groups whose trips within the time of day have no departure time in
stop_times can't have a template and are left unchanged, with a warning.
Removed trips may leave unused entries in other tables, such as shapes
and calendar, which remove_unused_ids() removes.
stop_times requires the stop_id and stop_sequence fields. Existing
_secs columns in frequencies (e.g. created with
convert_time_to_seconds()) are updated.