diff options
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 37 |
1 files changed, 35 insertions, 2 deletions
@@ -1,5 +1,9 @@ -# make a function that turns a list of lists of coordinates into a string +import folium +import pandas as pd +import requests + +# make a function that turns a list of lists of coordinates into a string def list_to_string(list_of_lists): """ Takes a list of lists of coordinates and returns a string of the coordinates @@ -7,4 +11,33 @@ def list_to_string(list_of_lists): string = '' for i in list_of_lists: string += str(i[1]) + ',' + str(i[0]) + ';' - return string
\ No newline at end of file + return string + + +def create_json_df(coordinate_string): + coordinates = requests.get('http://acetyl.net:5000/trip/v1/bike/' + coordinate_string) + coordinates = coordinates.json() + + # Create a dataframe from the JSON + df = pd.DataFrame(coordinates['waypoints']) + + # Separate the location column into lon and lat columns + df['lat'] = df['location'].apply(lambda x: x[0]) + df['lon'] = df['location'].apply(lambda x: x[1]) + + df['waypoint_index'] = df['waypoint_index'].astype(int) + + # Map out the waypoints in order of the waypoint index + df = df.sort_values(by=['waypoint_index']) + + return df + + +def get_trip_time(coordinate_string): + """ + Takes a list of lists of coordinates and returns the time of the trip in hours + """ + coordinates = requests.get('http://acetyl.net:5000/trip/v1/bike/' + coordinate_string) + coordinates = coordinates.json() + + return int(coordinates['trips'][0]['duration']) / 3600 |
