Trips are grouped by route_id, service_id, direction_id and
shape_id (the last two only if present in trips) and by their sequence
of stops, as identified by get_stop_times_patterns(). Each group is split
into one-hour slots of the clock, from HH:00:00 (included) to the next
HH:00:00 (excluded), by the earliest departure_time of each trip in
stop_times, regardless of stop_sequence (so times after midnight
written as "00:30:00" instead of "24:30:00" misplace the trip). Slots
after midnight are kept as such (e.g. "25:00:00" to "26:00:00").
In each slot with n trips, the trip with the earliest departure (ties
broken by trip_id) becomes the template and keeps its trip_id and its
trips and stop_times entries. A frequencies entry is added for it,
from the start to the end of the slot, with
headway_secs = ceiling(3600 / n) and exact_times = 0. The other trips
are removed from trips, stop_times and transfers; transfers entries
of the template now apply to all of its departures. Other tables that may
refer to trips, such as attributions and translations, are not changed.
Slots with a single trip are also converted. Only the trips in trip_id
are grouped and converted; other trips are never removed, even if they
share a group and a slot with converted ones. Trips already listed in
frequencies (with a warning, if listed in trip_id), trips not listed in
trips and trips without any departure_time are left unchanged.
Converting the result back with frequencies_to_stop_times() yields the
same number of trips in each slot with at most 60 trips (approximately the
same otherwise), evenly spaced from the start of the slot.
Existing _secs columns in stop_times and frequencies (e.g. created
with convert_time_to_seconds()) are used as-is and filled in for the new
frequencies entries.