{ "cells": [ { "cell_type": "code", "execution_count": 62, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2023-11-06T00:26:14.565659Z", "start_time": "2023-11-06T00:26:14.551906Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import requests\n", "import folium" ] }, { "cell_type": "code", "execution_count": 63, "outputs": [], "source": [ "# Create a JSON request for the API\n", "# This is the data we want to get from the API\n", "northeastern_coordinate = \"-71.09033,42.33976;\"\n", "coordinate_string = '-71.2038948,42.4299758;-71.1060828,42.3511927;-71.0969274,42.3446263;-71.130887,42.35304;-71.1459593,42.3501823;-71.1460435,42.3495825;-71.1217152,42.3426377;-71.1258765,42.331864;-71.1095021,42.3364675;-71.133103,42.3890049;-71.0851891,42.3500031;-71.1123834,42.3360385;-71.2273649,42.3145041;-71.0834061,42.341987;-71.0992038,42.3306454;-71.0990577,42.3381442;-71.0949218,42.3419564;-71.0942861,42.3413301;-71.0908104,42.329969;-71.0913583,42.3490205;-71.1000217,42.3323776;-71.1241295,42.3518397;-71.1618052,42.3245965;-71.1625829,42.340795;-71.167854,42.4107892;-71.155555,42.3317473;-71.1227278,42.3965778;-71.3598149,42.3140229;-71.1126695,42.3836229;-71.119149,42.3884;-71.0872846,42.2961434;-71.1427371,42.3433772;-71.1438455,42.3569102;-71.1313443,42.3525708;-71.1284677,42.3631904;-71.119301,42.388547;-71.097883,42.381008;-71.1107166,42.3741209;-71.1194344,42.3754427;-71.1013044,42.3627462;-71.1108423,42.3838224;-71.1026937,42.3820702;-71.1189467,42.373465;-71.1208817,42.3732344;-71.0968274,42.3799095;-71.094048,42.339381;-71.1854722,42.3621177;-71.1146697,42.3782386;-71.0935443,42.3817274;-71.0906355,42.3616095;-71.1161887,42.3766442;-71.0962734,42.3627993;-71.1155576,42.3784629;-71.0949101,42.3797674;-71.1087411,42.3640287;-71.09476,42.37736;-71.1014951,42.3614115;-71.1024769,42.3822934;-71.1011111,42.3636597;-71.0898829,42.3463992;-71.0983169,42.3319001;-71.0945712,42.3253252;-71.1122037,42.4008442'\n", "coordinates = requests.get('http://acetyl.net:5000/trip/v1/bike/' + northeastern_coordinate + coordinate_string)\n", "\n", "coordinates = coordinates.json()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T00:26:15.268775Z", "start_time": "2023-11-06T00:26:14.558083Z" } }, "id": "aa618161182b5b07" }, { "cell_type": "code", "execution_count": 64, "outputs": [], "source": [ "# Create a dataframe from the JSON\n", "df = pd.DataFrame(coordinates['waypoints'])" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T00:26:15.278022Z", "start_time": "2023-11-06T00:26:15.269158Z" } }, "id": "32c485788eedd94" }, { "cell_type": "code", "execution_count": 65, "outputs": [], "source": [ "# Separate the location column into lon and lat columns\n", "df['lat'] = df['location'].apply(lambda x: x[0])\n", "df['lon'] = df['location'].apply(lambda x: x[1])\n", "\n", "df['waypoint_index'] = df['waypoint_index'].astype(int)\n", "\n", "# Map out the waypoints in order of the waypoint index\n", "df = df.sort_values(by=['waypoint_index'])" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T00:26:15.284313Z", "start_time": "2023-11-06T00:26:15.275568Z" } }, "id": "535ab02638d20cb2" }, { "cell_type": "code", "execution_count": 66, "outputs": [ { "data": { "text/plain": " waypoint_index trips_index \\\n0 0 0 \n14 1 0 \n60 2 0 \n46 3 0 \n16 4 0 \n.. ... ... \n61 59 0 \n15 60 0 \n19 61 0 \n31 62 0 \n62 63 0 \n\n hint distance \\\n0 DoUhgBeFIYCcAAAAJgAAAAAAAAARAAAAm0CKQdkZiEAAAA... 0.236958 \n14 lhgDgIkYA4BkAAAAIgEAAFoBAAAaAAAAJyAzQWNrAEI8Ax... 7.134933 \n60 tg0igLoNIoAOAAAAAAAAADwAAADtAQAA8CrBQAAAAACcrM... 17.496916 \n46 k4chgBiIIYAKAAAAFwAAAPQDAAB_AgAAHn2aP-biHUBi6e... 36.240351 \n16 rLwhgLG8IYAEAAAABQAAADAAAABsAAAA1X8CQHGb7D9Kz6... 24.054372 \n.. ... ... \n61 g38hgI1_IYBOAAAAfwAAAAAAAAAAAAAAZ4ECQsbEUkIAAA... 12.789906 \n15 cX8hgJF_IYA1AAAAMAAAAGcAAABOAAAATyWxQQ77nUEHMC... 22.776295 \n19 5tYhgJHXIYAIAAAArQAAADwAAABCAQAAaRlbQD16mUGpAc... 17.374491 \n31 WhEngAASJ4BcAAAAdwAAAHoBAAAFAAAAI3gkQQlZRUJLNi... 13.907079 \n62 s9QhgLbUIYAwAAAAkAAAAAAAAAAAAAAA2XmpQNgrgEEAAA... 4.111715 \n\n name location lat lon \n0 Northeastern (Inbound) [-71.090331, 42.339762] -71.090331 42.339762 \n14 [-71.083465, 42.34194] -71.083465 42.341940 \n60 Public Alley 901 [-71.089677, 42.346361] -71.089677 42.346361 \n46 [-71.093834, 42.339096] -71.093834 42.339096 \n16 [-71.099284, 42.338007] -71.099284 42.338007 \n.. ... ... ... ... \n61 Tremont Street [-71.098267, 42.332009] -71.098267 42.332009 \n15 Alleghany Street [-71.099348, 42.33047] -71.099348 42.330470 \n19 Dudley Street [-71.090904, 42.329829] -71.090904 42.329829 \n31 Blue Hill Avenue [-71.087449, 42.296172] -71.087449 42.296172 \n62 [-71.09454, 42.325354] -71.094540 42.325354 \n\n[64 rows x 8 columns]", "text/html": "
| \n | waypoint_index | \ntrips_index | \nhint | \ndistance | \nname | \nlocation | \nlat | \nlon | \n
|---|---|---|---|---|---|---|---|---|
| 0 | \n0 | \n0 | \nDoUhgBeFIYCcAAAAJgAAAAAAAAARAAAAm0CKQdkZiEAAAA... | \n0.236958 | \nNortheastern (Inbound) | \n[-71.090331, 42.339762] | \n-71.090331 | \n42.339762 | \n
| 14 | \n1 | \n0 | \nlhgDgIkYA4BkAAAAIgEAAFoBAAAaAAAAJyAzQWNrAEI8Ax... | \n7.134933 | \n\n | [-71.083465, 42.34194] | \n-71.083465 | \n42.341940 | \n
| 60 | \n2 | \n0 | \ntg0igLoNIoAOAAAAAAAAADwAAADtAQAA8CrBQAAAAACcrM... | \n17.496916 | \nPublic Alley 901 | \n[-71.089677, 42.346361] | \n-71.089677 | \n42.346361 | \n
| 46 | \n3 | \n0 | \nk4chgBiIIYAKAAAAFwAAAPQDAAB_AgAAHn2aP-biHUBi6e... | \n36.240351 | \n\n | [-71.093834, 42.339096] | \n-71.093834 | \n42.339096 | \n
| 16 | \n4 | \n0 | \nrLwhgLG8IYAEAAAABQAAADAAAABsAAAA1X8CQHGb7D9Kz6... | \n24.054372 | \n\n | [-71.099284, 42.338007] | \n-71.099284 | \n42.338007 | \n
| ... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
| 61 | \n59 | \n0 | \ng38hgI1_IYBOAAAAfwAAAAAAAAAAAAAAZ4ECQsbEUkIAAA... | \n12.789906 | \nTremont Street | \n[-71.098267, 42.332009] | \n-71.098267 | \n42.332009 | \n
| 15 | \n60 | \n0 | \ncX8hgJF_IYA1AAAAMAAAAGcAAABOAAAATyWxQQ77nUEHMC... | \n22.776295 | \nAlleghany Street | \n[-71.099348, 42.33047] | \n-71.099348 | \n42.330470 | \n
| 19 | \n61 | \n0 | \n5tYhgJHXIYAIAAAArQAAADwAAABCAQAAaRlbQD16mUGpAc... | \n17.374491 | \nDudley Street | \n[-71.090904, 42.329829] | \n-71.090904 | \n42.329829 | \n
| 31 | \n62 | \n0 | \nWhEngAASJ4BcAAAAdwAAAHoBAAAFAAAAI3gkQQlZRUJLNi... | \n13.907079 | \nBlue Hill Avenue | \n[-71.087449, 42.296172] | \n-71.087449 | \n42.296172 | \n
| 62 | \n63 | \n0 | \ns9QhgLbUIYAwAAAAkAAAAAAAAAAAAAAA2XmpQNgrgEEAAA... | \n4.111715 | \n\n | [-71.09454, 42.325354] | \n-71.094540 | \n42.325354 | \n
64 rows × 8 columns
\n