#21 improved grouping algorithm
All checks were successful
Amarillo/amarillo-gitea/amarillo-enhancer/pipeline/head This commit looks good
All checks were successful
Amarillo/amarillo-gitea/amarillo-enhancer/pipeline/head This commit looks good
This commit is contained in:
parent
652780b702
commit
5cc0b1d520
|
|
@ -86,17 +86,21 @@ class GtfsExport:
|
|||
ungrouped_trips = dict(trips)
|
||||
route_groups = list()
|
||||
current_route_id = 1
|
||||
for trip_id, trip in trips.items():
|
||||
if len(ungrouped_trips) == 0: break
|
||||
|
||||
#find trips whose start and end stops are within a specified distance of the current trip
|
||||
group = {key: value for key, value in ungrouped_trips.items() if self.trips_are_close(trip, value)}
|
||||
while len(ungrouped_trips) > 0:
|
||||
trip_id, current_trip = ungrouped_trips.popitem()
|
||||
|
||||
route_groups.append(group)
|
||||
for key, grouped_trip in group.items():
|
||||
grouped_trip.route_id = str(current_route_id)
|
||||
ungrouped_trips.pop(key)
|
||||
current_group = {trip_id: current_trip}
|
||||
current_trip.route_id = current_route_id
|
||||
|
||||
for other_id, other_trip in list(ungrouped_trips.items()):
|
||||
# if an ungrouped trip is close to any of the grouped trips, add it to the route group
|
||||
if (any(self.trips_are_close(other_trip, grouped_trip) for grouped_trip in current_group.values())):
|
||||
current_group[other_id] = ungrouped_trips.pop(other_id)
|
||||
current_group[other_id].route_id = current_route_id
|
||||
|
||||
|
||||
route_groups.append(current_group)
|
||||
current_route_id += 1
|
||||
|
||||
return route_groups, trips
|
||||
|
|
@ -108,7 +112,8 @@ class GtfsExport:
|
|||
trip2_start = trip2.path.coordinates[0]
|
||||
trip2_end = trip2.path.coordinates[-1]
|
||||
|
||||
return self.within_range(trip1_start, trip2_start) and self.within_range(trip1_end, trip2_end)
|
||||
res = self.within_range(trip1_start, trip2_start) and self.within_range(trip1_end, trip2_end)
|
||||
return res
|
||||
|
||||
def within_range(self, stop1, stop2):
|
||||
MERGE_RANGE_M = 500
|
||||
|
|
|
|||
Loading…
Reference in a new issue