{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import requests\n", "import json\n", "import numpy as np\n", "import pandas as pd\n", "import config as cfg\n", "import math\n", "\n", "#import folium\n", "#import ipywidgets as widgets\n", "#from ipywidgets import Layout\n", "#import matplotlib.pyplot as plt\n", "import plotly.graph_objects as go\n", "\n", "#from ipyleaflet import Map, basemaps, basemap_to_tiles, DrawControl, Polyline, TileLayer, GeoJSON, AntPath, Marker, Icon, Circle, CircleMarker" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "par = {\n", " \"key\":cfg.conf['key_TT2'],\n", " # \"callback\":callback,\n", " # \"fuelBudgetInLiters\":float,\n", " \"maxChargeInkWh\": 95,\n", " \"currentChargeInkWh\" : 80,\n", " # \"timeBudgetInSec\":float,\n", " # \"distanceBudgetInMeters\":float,\n", " # \"report\":effectiveSettings,\n", " # \"departAt\":time,\n", " # \"routeType\":routeType,\n", " \"traffic\": \"true\",\n", " \"avoid\": \"unpavedRoads\",\n", " \"travelMode\": \"car\",\n", " # \"hilliness\":hilliness,\n", " # \"windingness\":windingness,\n", " \"vehicleMaxSpeed\": 200,\n", " \"vehicleWeight\": 2000,\n", " \"vehicleAxleWeight\": 1000,\n", " \"vehicleLength\": 3,\n", " \"vehicleWidth\": 2,\n", " \"vehicleHeight\": 1.5,\n", " \"vehicleCommercial\": \"true\",\n", " # \"vehicleLoadType\":vehicleLoadType,\n", " # \"vehicleAdrTunnelRestrictionCode\":vehicleAdrTunnelRestrictionCode,\n", " \"vehicleEngineType\":\"electric\",\n", " # \"constantSpeedConsumptionInLitersPerHundredkm\":CombustionConstantSpeedConsumptionPairs,\n", " # \"currentFuelInLiters\":float,\n", " # \"auxiliaryPowerInLitersPerHour\":float,\n", " # \"fuelEnergyDensityInMJoulesPerLiter\":float,\n", " # \"accelerationEfficiency\":float,\n", " # \"decelerationEfficiency\":float,\n", " # \"uphillEfficiency\":float,\n", " # \"downhillEfficiency\":float,\n", " #\"velocityOffsetUnlimitedHighway\":20,\n", " #\"velocityOffsetFRC1\":15,\n", " #\"velocityOffsetFRC2\":10,\n", " #\"velocityOffsetFRC3\":8,\n", " #\"velocityOffsetFRC4\":0,\n", " #\"velocityOffsetFRC5\":0,\n", " \"constantSpeedConsumptionInkWhPerHundredkm\": '0,29.4:27,27.9:45,29.4:60,23.1:75,24.7:90,27.8:100,29.5:110,31.55:120,34.35:130,35.55',\n", " # \"currentChargeInkWh\":float,\n", " # \"maxChargeInkWh\":float,\n", " \"auxiliaryPowerInkW\": 3,\n", " }" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def response_url(url,parameters,cfg,headers=-1,payload=-1):\n", " try:\n", " if headers==-1 and payload==-1: # only get ...\n", " response = requests.get(url,params=parameters,timeout=300)#,proxies=cfg.conf['proxies'])\n", " else: # post with headers + json ...\n", " #response = requests.post(url,params=parameters,headers=headers,json=payload,timeout=300,proxies=cfg.conf['proxies'])\n", " response = requests.post(url,params=parameters,headers=headers,json=payload,timeout=300)\n", " response.raise_for_status() # Raise error in case of failure \n", " except requests.exceptions.HTTPError as httpErr: \n", " print (\"Http Error:\",httpErr) \n", " print(response.json())\n", " except requests.exceptions.ConnectionError as connErr: \n", " print (\"Error Connecting:\",connErr) \n", " except requests.exceptions.Timeout as timeOutErr: \n", " print (\"Timeout Error:\",timeOutErr) \n", " except requests.exceptions.RequestException as reqErr: \n", " print (\"Something Else:\",reqErr) \n", " #print(response.url)\n", " #print(response.json())\n", " return response.json()\n", "\n", "# Geocoding\n", "def Mapbox_Geocoding(City_str):\n", " url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + City_str + '.json'\n", " parameters = {'access_token':cfg.conf['key_MapBox']}\n", " return response_url(url,parameters,cfg)['features'][0]['center']\n", "\n", "# TT EV HCP3 routing\n", "def TomTom_HCP3_Routing(lat_s,lng_s,lat_d,lng_d,cfg,parameters):\n", "\n", " url = \"https://api.tomtom.com/routing-hcp3/1//calculateRoute/\" + str(lat_s)+ ',' +str(lng_s)+\":\"+str(lat_d)+ ',' +str(lng_d) + \"/json?\"\n", "\n", " response = response_url(url,parameters,cfg)#,headers,payload)\n", " #print(response)\n", " # data frame\n", " df = pd.DataFrame(data=response['routes'][0]['legs'][0]['points'], columns=['latitude','longitude']) # legs[0]\n", " \n", " # single values \n", " singVal = [] \n", " singValName = []\n", " singValName.append('batteryConsumptionInkWh_summary')\n", " singVal.append(response['routes'][0]['summary']['batteryConsumptionInkWh'])\n", " singValName.append('lengthInKiloMeters_summary')\n", " singVal.append(response['routes'][0]['summary']['lengthInMeters']/1000) # km\n", " singValName.append('travelTimeInMinutes_summary')\n", " singVal.append(response['routes'][0]['summary']['travelTimeInSeconds']/60) # min\n", " singValName.append('trafficDelayInMinutes_summary')\n", " singVal.append(response['routes'][0]['summary']['trafficDelayInSeconds']/60) # min\n", " df2 = pd.DataFrame(columns=singValName)\n", " df2.loc[0] = singVal\n", " \n", " return df,df2\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "lat": [ 48.78574, 48.78507, 48.78485, 48.78489, 48.78493, 48.7853, 48.78533, 48.78538, 48.78547, 48.78531, 48.78484, 48.78476, 48.78471, 48.78451, 48.78426, 48.78418, 48.78407, 48.78396, 48.7839, 48.78386, 48.7838, 48.78368, 48.78355, 48.78344, 48.78341, 48.78336, 48.78282, 48.78275, 48.7827, 48.7825, 48.78237, 48.78198, 48.78195, 48.78191, 48.78184, 48.78182, 48.78172, 48.78164, 48.78157, 48.78165, 48.78196, 48.78197, 48.78198, 48.78265, 48.78271, 48.78281, 48.78359, 48.78368, 48.78373, 48.78379, 48.784, 48.78449, 48.78455, 48.78468, 48.78477, 48.78483, 48.78487, 48.7849, 48.785, 48.78506, 48.7851, 48.78517, 48.78532, 48.78539, 48.78542, 48.78557, 48.78563, 48.78571, 48.78581, 48.786, 48.78587, 48.78583, 48.78572, 48.78557, 48.78552, 48.78541, 48.78537, 48.78534, 48.78523, 48.78511, 48.78507, 48.78499, 48.78491, 48.78481, 48.78475, 48.78466, 48.78449, 48.78428, 48.78423, 48.78418, 48.78415, 48.78397, 48.78396, 48.78378, 48.78372, 48.78364, 48.78355, 48.78345, 48.78336, 48.78311, 48.78301, 48.78291, 48.78269, 48.78251, 48.78247, 48.78241, 48.78232, 48.78217, 48.7821, 48.78178, 48.78163, 48.78146, 48.7814, 48.78122, 48.7811, 48.78109, 48.78094, 48.78092, 48.78058, 48.78009, 48.77999, 48.7797, 48.77965, 48.77952, 48.77948, 48.77941, 48.7793, 48.77929, 48.77923, 48.77904, 48.7786, 48.77855, 48.77846, 48.77797, 48.77778, 48.77769, 48.77762, 48.77752, 48.77732, 48.77697, 48.77688, 48.77677, 48.77659, 48.77648 ], "lon": [ 11.39516, 11.39553, 11.39565, 11.39583, 11.39598, 11.39728, 11.39738, 11.39755, 11.39783, 11.39792, 11.39819, 11.39825, 11.39827, 11.39839, 11.39852, 11.39857, 11.39865, 11.39871, 11.39874, 11.39878, 11.39884, 11.39898, 11.39919, 11.39938, 11.39946, 11.39953, 11.40065, 11.4008, 11.40088, 11.40131, 11.4016, 11.40242, 11.40252, 11.40259, 11.40273, 11.40279, 11.403, 11.40315, 11.40333, 11.40342, 11.40379, 11.40381, 11.40381, 11.4046, 11.40467, 11.40478, 11.4057, 11.40581, 11.40586, 11.40593, 11.40618, 11.40677, 11.40684, 11.407, 11.4071, 11.40717, 11.40721, 11.40725, 11.40737, 11.40745, 11.40749, 11.40757, 11.40775, 11.40784, 11.40788, 11.40806, 11.40813, 11.40822, 11.40835, 11.40858, 11.40889, 11.40903, 11.40931, 11.40966, 11.40978, 11.41006, 11.41015, 11.41022, 11.41047, 11.41069, 11.41077, 11.41088, 11.41103, 11.41117, 11.41126, 11.41137, 11.4116, 11.41184, 11.41191, 11.41195, 11.41198, 11.41217, 11.41219, 11.41236, 11.41241, 11.41251, 11.4126, 11.41271, 11.41279, 11.41301, 11.41311, 11.4132, 11.41338, 11.41352, 11.41356, 11.41359, 11.41366, 11.41379, 11.41383, 11.4141, 11.41422, 11.41433, 11.41439, 11.41452, 11.4146, 11.4146, 11.41472, 11.41473, 11.41498, 11.4153, 11.41537, 11.41554, 11.41558, 11.41565, 11.41567, 11.41572, 11.41578, 11.41579, 11.41581, 11.41593, 11.41613, 11.41616, 11.41619, 11.4164, 11.41647, 11.4165, 11.41653, 11.41656, 11.41662, 11.41672, 11.41675, 11.41677, 11.41682, 11.41685 ], "marker": { "color": "rgb(180,50,50)", "opacity": 0.25, "size": 8 }, "mode": "markers+lines+text", "name": "TomTom Routing", "text": "TT HCP3 Routing", "type": "scattermapbox" }, { "lat": [ "48.776529" ], "lon": [ "11.417135" ], "marker": { "color": "rgb(180,50,50)", "opacity": 0.8, "size": 25 }, "mode": "markers", "name": "TomTom Routing", "text": "TT HCP3 Routing", "type": "scattermapbox" }, { "lat": [ "48.785931" ], "lon": [ "11.395945" ], "marker": { "color": "rgb(180,50,50)", "opacity": 0.8, "size": 25 }, "mode": "markers", "name": "TomTom Routing", "text": "TT HCP3 Routing", "type": "scattermapbox" } ], "layout": { "mapbox": { "center": { "lat": 48.776529, "lon": 11.417135 }, "style": "stamen-terrain", "zoom": 10 }, "margin": { "b": 0, "l": 0, "r": 0, "t": 0 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "