{ "cells": [ { "cell_type": "code", "execution_count": 10, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2023-11-06T01:23:16.767323Z", "start_time": "2023-11-06T01:23:16.761053Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import requests\n", "import folium\n", "import utils" ] }, { "cell_type": "code", "execution_count": 11, "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", "route_1 = '-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.1123834,42.3360385;-71.2273649,42.3145041;-71.0992038,42.3306454;-71.0990577,42.3381442;-71.0949218,42.3419564;-71.0942861,42.3413301;-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.1126695,42.3836229;-71.119149,42.3884;-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'\n", "route_2 = '-71.0553792,42.3688272;-71.0688746,42.3576234;-71.0754527,42.3565057;-71.0620802,42.3579151;-71.0586014,42.357357;-71.0572023,42.3587627;-71.0556268,42.36521;-71.0720926,42.3489004;-71.067859,42.3500079;-71.0632036,42.3556154;-71.0620134,42.3248471;-71.0851891,42.3500031;-71.066414,42.354296;-71.0834061,42.341987;-71.0569649,42.3604952;-71.0498714,42.3256817;-71.0908104,42.329969;-71.0616035,42.3537983;-71.0359433,42.3485465;-71.0638101,42.3587772;-71.0555003,42.3640137;-71.0712561,42.3407613;-71.0561781,42.3668968;-71.0664019,42.3554589;-71.059228,42.359349;-71.0668408,42.3524116;-71.0872846,42.2961434;-71.062146,42.366198;-71.0651214,42.3553972;-71.0596124,42.3509517;-71.0359354,42.3478381;-71.061757,42.3691906;-71.0609962,42.3803747;-71.0516339,42.3609921;-71.0809932,42.3675275;-71.0545357,42.3597994;-71.0342146,42.316274;-71.0756902,42.3695046;-71.0678704,42.3701829;-71.0656594,42.3718401;-71.0611749,42.3551807;-71.0554239,42.3739796;-71.0631664,42.3741694;-71.056823,42.361531;-71.0632852,42.2857047;-71.0637877,42.2845163;-71.0496839,42.3519736;-71.0454645,42.3162356;-71.0336324,42.3441918;-71.0487437,42.3508756;-71.0512911,42.3521821;-71.0013637,42.2075316;-71.0607764,42.3763541;-71.0374911,42.316031;-71.0125206,42.3378699;-71.0672898,42.3523158;-71.02832,42.2576602;-71.0502126,42.3516479;-71.0331956,42.3639107;-71.0432778,42.3528151;-71.0035279,42.2392354;-71.0470633,42.3537343;-71.0352443,42.3291218;-71.0240951,42.2743442;-71.0234949,42.3358743;-70.985881,42.420226;-71.0005483,42.2454086;-71.0096371,42.3367603;-71.0447796,42.3509709;-71.0092883,42.2763168;-71.0404428,42.3478375;-71.056908,42.361288;-71.0667744,42.3270498;-71.0119933,42.2806539'" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:16.774149Z", "start_time": "2023-11-06T01:23:16.765417Z" } }, "id": "aa618161182b5b07" }, { "cell_type": "code", "execution_count": 12, "outputs": [], "source": [ "# Create a dataframe from the JSON\n", "df1 = utils.create_json_df(northeastern_coordinate + route_1)\n", "df2 = utils.create_json_df(northeastern_coordinate + route_2)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:18.694403Z", "start_time": "2023-11-06T01:23:16.768656Z" } }, "id": "32c485788eedd94" }, { "cell_type": "code", "execution_count": 13, "outputs": [], "source": [ "# Add columns for the route number\n", "df1['route'] = 1\n", "df2['route'] = 2\n", "\n", "# Concatenate the two dataframes\n", "df = pd.concat([df1, df2], ignore_index=True)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:18.698699Z", "start_time": "2023-11-06T01:23:18.696008Z" } }, "id": "49dba1f17ca8337e" }, { "cell_type": "code", "execution_count": 14, "outputs": [ { "data": { "text/plain": " waypoint_index trips_index \\\n0 0 0 \n17 1 0 \n22 2 0 \n73 3 0 \n11 4 0 \n.. ... ... \n3 70 0 \n12 71 0 \n9 72 0 \n8 73 0 \n14 74 0 \n\n hint distance \\\n0 DoUhgBeFIYCcAAAAJgAAAAAAAAARAAAAm0CKQdkZiEAAAA... 0.236958 \n17 5tYhgJHXIYAIAAAArQAAADwAAABCAQAAaRlbQD16mUGpAc... 17.374491 \n22 XAAigHIAIoBKAAAASwAAAFUAAABDAQAARGUEQURlBEG2ZR... 11.054154 \n73 CdQhgB0OA4AYAAAAHgAAADkAAAAAAAAALdMlQdSMQ0Fd0r... 10.970598 \n11 43YhgPN2IYA1AAAAJAAAAAAAAAA5AAAAEha0QWgpbEEAAA... 18.896385 \n.. ... ... \n3 jt4hgJLeIYA7AAAALQAAAAAAAAAAAAAA4gPGQasVlUEAAA... 4.709088 \n12 0OEhgPvhIYADAAAABgAAAA8AAAA0AAAA2lq-PipQFD-Y-N... 2.009578 \n9 m8shgJ7LIYAOAAAAXgEAAAAAAAAAAAAAOFW-QDE5G0IAAA... 1.716409 \n8 YQ0DgBTPIYDvAAAAdAAAAAAAAAAAAAAAsgLVQbMxTUEAAA... 4.830022 \n14 lhgDgIkYA4BkAAAAIgEAAFoBAAAaAAAAJyAzQWNrAEI8Ax... 7.134933 \n\n name location lat lon \\\n0 Northeastern (Inbound) [-71.090331, 42.339762] -71.090331 42.339762 \n17 Dudley Street [-71.090904, 42.329829] -71.090904 42.329829 \n22 [-71.071196, 42.34085] -71.071196 42.340850 \n73 [-71.066844, 42.327134] -71.066844 42.327134 \n11 Lucy Street [-71.06221, 42.324934] -71.062210 42.324934 \n.. ... ... ... ... \n3 [-71.075414, 42.356537] -71.075414 42.356537 \n12 [-71.085166, 42.349997] -71.085166 42.349997 \n9 Piedmont Street [-71.067854, 42.349993] -71.067854 42.349993 \n8 [-71.072038, 42.348915] -71.072038 42.348915 \n14 [-71.083465, 42.34194] -71.083465 42.341940 \n\n route \n0 2 \n17 2 \n22 2 \n73 2 \n11 2 \n.. ... \n3 2 \n12 2 \n9 2 \n8 2 \n14 2 \n\n[75 rows x 9 columns]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
waypoint_indextrips_indexhintdistancenamelocationlatlonroute
000DoUhgBeFIYCcAAAAJgAAAAAAAAARAAAAm0CKQdkZiEAAAA...0.236958Northeastern (Inbound)[-71.090331, 42.339762]-71.09033142.3397622
17105tYhgJHXIYAIAAAArQAAADwAAABCAQAAaRlbQD16mUGpAc...17.374491Dudley Street[-71.090904, 42.329829]-71.09090442.3298292
2220XAAigHIAIoBKAAAASwAAAFUAAABDAQAARGUEQURlBEG2ZR...11.054154[-71.071196, 42.34085]-71.07119642.3408502
7330CdQhgB0OA4AYAAAAHgAAADkAAAAAAAAALdMlQdSMQ0Fd0r...10.970598[-71.066844, 42.327134]-71.06684442.3271342
114043YhgPN2IYA1AAAAJAAAAAAAAAA5AAAAEha0QWgpbEEAAA...18.896385Lucy Street[-71.06221, 42.324934]-71.06221042.3249342
..............................
3700jt4hgJLeIYA7AAAALQAAAAAAAAAAAAAA4gPGQasVlUEAAA...4.709088[-71.075414, 42.356537]-71.07541442.3565372
127100OEhgPvhIYADAAAABgAAAA8AAAA0AAAA2lq-PipQFD-Y-N...2.009578[-71.085166, 42.349997]-71.08516642.3499972
9720m8shgJ7LIYAOAAAAXgEAAAAAAAAAAAAAOFW-QDE5G0IAAA...1.716409Piedmont Street[-71.067854, 42.349993]-71.06785442.3499932
8730YQ0DgBTPIYDvAAAAdAAAAAAAAAAAAAAAsgLVQbMxTUEAAA...4.830022[-71.072038, 42.348915]-71.07203842.3489152
14740lhgDgIkYA4BkAAAAIgEAAFoBAAAaAAAAJyAzQWNrAEI8Ax...7.134933[-71.083465, 42.34194]-71.08346542.3419402
\n

75 rows × 9 columns

\n
" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(df2)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:18.708601Z", "start_time": "2023-11-06T01:23:18.705324Z" } }, "id": "f231d9a35358988c" }, { "cell_type": "code", "execution_count": 15, "outputs": [ { "data": { "text/plain": "", "text/html": "
Make this Notebook Trusted to load map: File -> Trust Notebook
" }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create a map\n", "m = folium.Map(location=[df['lon'].mean(), df['lat'].mean()], zoom_start=11)\n", "\n", "# Add the points and lines for the two routes with different colors\n", "colors = ['red', 'blue']\n", "\n", "for route in df['route'].unique():\n", " df_route = df[df['route'] == route]\n", " folium.PolyLine(df_route[['lon', 'lat']].values.tolist(), color=colors[route-1]).add_to(m)\n", " for i in range(len(df_route)):\n", " folium.CircleMarker(df_route[['lon', 'lat']].iloc[i].values.tolist(), radius=3, color=colors[route-1]).add_to(m)\n", "\n", "# Display the map\n", "m" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:18.781393Z", "start_time": "2023-11-06T01:23:18.709803Z" } }, "id": "80fd847da2833913" }, { "cell_type": "code", "execution_count": 16, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The trip will take 6.789722222222222 hours\n", "The trip will take 9.955833333333333 hours\n" ] } ], "source": [ "trip_hrs_1 = utils.get_trip_time(route_1)\n", "print(\"The trip will take {} hours\".format(trip_hrs_1))\n", "trip_hrs_2 = utils.get_trip_time(route_2)\n", "print(\"The trip will take {} hours\".format(trip_hrs_2))" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:20.448487Z", "start_time": "2023-11-06T01:23:18.761079Z" } }, "id": "a3ec09dfb5cbb5b3" }, { "cell_type": "code", "execution_count": 17, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " waypoint_index trips_index \\\n", "20 20 0 \n", "\n", " hint distance name \\\n", "20 2M4pgNrOKYCCAQAADAAAAAAAAAAAAAAALKILQ27Ah0AAAA... 0.0 Echo Bridge \n", "\n", " location lat lon route \n", "20 [-71.227365, 42.314504] -71.227365 42.314504 1 \n" ] } ], "source": [ "# Find the westmost point in Route 1\n", "df1 = df[df['route'] == 1]\n", "west = df1[df1['lon'] == df1['lon'].min()]\n", "print(west)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:20.455714Z", "start_time": "2023-11-06T01:23:20.453647Z" } }, "id": "be94c3708a1bd250" }, { "cell_type": "code", "execution_count": 18, "outputs": [], "source": [ "# Remove the westmost point from Route 1\n", "df = df.drop(west.index)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:20.460791Z", "start_time": "2023-11-06T01:23:20.456599Z" } }, "id": "21fef07e5b2a03a0" }, { "cell_type": "code", "execution_count": 18, "outputs": [], "source": [], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-06T01:23:20.460900Z", "start_time": "2023-11-06T01:23:20.458522Z" } }, "id": "eafe5678c44e94fd" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }