diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-03-30 12:50:36 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-03-30 12:50:36 +0200 |
commit | d8c1ab32a1f020b52ab751b1d166c2878ad0e1c2 (patch) | |
tree | 073754c06d785be75fddf8f962172191fb2dfbb1 /bin | |
parent | 3304c699edfd956e869989f04b83bf3291fea882 (diff) |
populate-lut: decrease grid step size
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/populate-lut | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/bin/populate-lut b/bin/populate-lut index 1f70a35..f24f109 100755 --- a/bin/populate-lut +++ b/bin/populate-lut @@ -36,6 +36,8 @@ trips_by_shape_id = dict() name_to_eva = dict() eva_to_name = dict() +lut_grid_step = 100 + try: with open("data/iris-stations.json", "r") as f: for station in json.load(f): @@ -84,6 +86,27 @@ with open("data/nvbw/trips.txt", "r") as f: trips_by_shape_id[shape_id] = list() trips_by_shape_id[shape_id].append(trip_id) +print("Loading stop_times ...") +stops_by_tripid = dict() +with open("data/nvbw/stop_times.txt", "r") as f: + f.readline() + cr = csv.reader(f) + for row in cr: + ( + trip_id, + stop_id, + arrival_time, + departure_time, + stop_seq, + stop_headsign, + pickup_type, + dropoff_type, + dist, + ) = row + if trip_id not in stops_by_tripid: + stops_by_tripid[trip_id] = list() + stops_by_tripid[trip_id].append((stop_headsign, float(dist))) + print("Loading shapes ...") with open("data/nvbw/shapes.txt", "r") as f: f.readline() @@ -98,9 +121,9 @@ with open("data/nvbw/shapes.txt", "r") as f: lat = float(lat) lon = float(lon) dist = float(dist) - if dist > prev_dist and dist - prev_dist > 200: - # ensure shape entries are no more than 200m apart - for i in np.arange(200, dist - prev_dist, 200): + if dist > prev_dist and dist - prev_dist > lut_grid_step: + # ensure shape entries are no more than lut_grid_step meters apart + for i in np.arange(lut_grid_step, dist - prev_dist, lut_grid_step): ratio = i / (dist - prev_dist) assert 0 <= ratio <= 1 rel_lat = (prev_lat * ratio + lat * (1 - ratio)) / 2 @@ -139,27 +162,6 @@ def add_evas(lat, lon, evas): # Here be dragons. I don't recall what this code does. It shouldn't be too complicated, though. -print("Loading stop_times ...") -stops_by_tripid = dict() -with open("data/nvbw/stop_times.txt", "r") as f: - f.readline() - cr = csv.reader(f) - for row in cr: - ( - trip_id, - stop_id, - arrival_time, - departure_time, - stop_seq, - stop_headsign, - pickup_type, - dropoff_type, - dist, - ) = row - if trip_id not in stops_by_tripid: - stops_by_tripid[trip_id] = list() - stops_by_tripid[trip_id].append((stop_headsign, float(dist))) - num_shapes = len(shape.keys()) for shape_id in ProgressBar("Calculating neighoubrs", max=num_shapes).iter( @@ -180,6 +182,7 @@ for shape_id in ProgressBar("Calculating neighoubrs", max=num_shapes).iter( add_stops(lat, lon, (stop_name, stops[i + 1][0])) try: + class Polyline: def __init__(self, json_data): self.coordinates = json_data["polyline"] @@ -203,7 +206,7 @@ try: prev_lat = leg[-1][0] prev_lon = leg[-1][1] prev_dist = distance((prev_lat, prev_lon), (lat, lon)).m - for i in np.arange(200, prev_dist, 200): + for i in np.arange(lut_grid_step, prev_dist, lut_grid_step): ratio = i / prev_dist assert 0 <= ratio <= 1 rel_lat = (prev_lat * ratio + lat * (1 - ratio)) / 2 @@ -237,7 +240,7 @@ insert_groups = list() insert_group = list() for (lat, lon), stops in stops_by_latlon.items(): insert_group.append((lat, lon, json.dumps(list(stops)))) - if len(insert_group) >= 50: + if len(insert_group) >= 100: insert_groups.append(insert_group) insert_group = list() |