New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data feeds containing stops without any coordinates fail for the entire feed #4

Closed
amcewen opened this Issue Sep 8, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@amcewen

amcewen commented Sep 8, 2017

Running transitflow for the operator Cumfybus, i.e. python transitflow.py --name=cumfybus --operator=o-gcw0-cumfybus --recording, currently fails after downloading the data.

Digging into it, it seems to be because the origin_stops from the dataset includes a stop (s-gcw0vhqpk4-blackrodchurchst~redlionstopc) that isn't in the lats/lons, which causes python to throw an exception.

I've worked round it (because claiming the stop is in the mid-Atlantic, while hopefully quite obvious to see, doesn't seem the correct fix :-) with the following mod to transitflow.py:

 def generate_output(operator_onestop_id, origin_datetimes, destination_datetimes, durations, origin_stops, destination_stops, route_ids, lookup_stop_lats, lookup_stop_lons, lookup_vehicle_types):
     """This function generates the output table, to be saved later as a csv."""
-    origin_stop_lats = [lookup_stop_lats[i] for i in origin_stops]
-    origin_stop_lons = [lookup_stop_lons[i] for i in origin_stops]
-    destination_stop_lats = [lookup_stop_lats[i] for i in destination_stops]
-    destination_stop_lons = [lookup_stop_lons[i] for i in destination_stops]
+    origin_stop_lats = []
+    origin_stop_lons = []
+    for i in origin_stops:
+        try:
+            origin_stop_lats.append(lookup_stop_lats[i])
+            origin_stop_lons.append(lookup_stop_lons[i])
+        except:
+            origin_stop_lats.append(-3.094025)
+            origin_stop_lons.append(53.460255)
+    destination_stop_lats = []
+    destination_stop_lons = []
+    for i in destination_stops:
+        try:
+            destination_stop_lats.append(lookup_stop_lats[i])
+            destination_stop_lons.append(lookup_stop_lons[i])
+        except:
+            destination_stop_lats.append(0)
+            destination_stop_lons.append(0)

Happy to submit it as a pull request, if that is a valid fix, mind you.

@willgeary willgeary self-assigned this Sep 11, 2017

@willgeary

This comment has been minimized.

Show comment
Hide comment
@willgeary

willgeary Oct 12, 2017

Collaborator

Thank you, @amcewen ! I agree with your idea of ignoring instances where stop lat/lons are not found and implemented something similar. Obviously, a more thorough solution would be to investigate why these particular stops are missing lat/lons in the database. But I agree that a single stop missing should not throw an error for an entire operator.

Cumfybus now works for me:

python transitflow.py --name=cumfybus --operator=o-gcw0-cumfybus

Cumfybus

Collaborator

willgeary commented Oct 12, 2017

Thank you, @amcewen ! I agree with your idea of ignoring instances where stop lat/lons are not found and implemented something similar. Obviously, a more thorough solution would be to investigate why these particular stops are missing lat/lons in the database. But I agree that a single stop missing should not throw an error for an entire operator.

Cumfybus now works for me:

python transitflow.py --name=cumfybus --operator=o-gcw0-cumfybus

Cumfybus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment