Skip to content

Instantly share code, notes, and snippets.

@aloncohen1
Last active October 31, 2022 18:05
Show Gist options
  • Save aloncohen1/394a8056c5c764e58d073ceb30675e5a to your computer and use it in GitHub Desktop.
Save aloncohen1/394a8056c5c764e58d073ceb30675e5a to your computer and use it in GitHub Desktop.
static_and_drive.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"id": "EeklA-LMk5zo"
},
"outputs": [],
"source": [
"def generate_signals_df(device_timeline, G):\n",
" \n",
" signals_dfs = []\n",
" drive_end = None\n",
" \n",
" for row in device_timeline\\\n",
" .join(device_timeline[['lat','lng']].shift(-1), lsuffix='_orig', rsuffix='_dest')\\\n",
" .dropna(subset=['lat_orig','lng_orig','lat_dest','lng_dest'],how='any').itertuples():\n",
" \n",
" if not drive_end:\n",
" drive_end = row.start_time\n",
" \n",
" stay_signals = generate_static_signals(row.lat_orig, row.lng_orig, drive_end, row.end_time)\n",
" signals_dfs.append(stay_signals)\n",
" \n",
" route = tc.distance.shortest_path(G, (row.lat_orig, row.lng_orig), (row.lat_dest,row.lng_dest))\n",
" route_geo = get_route_geometry(route, (row.lat_orig, row.lng_orig), (row.lat_dest,row.lng_dest))\n",
"\n",
" drive_signals, drive_end = generate_route_signals(route_geo, row.end_time, 45)\n",
" signals_dfs.append(drive_signals)\n",
" \n",
" device_signals = pd.concat(signals_dfs, ignore_index=True).sort_values('timestamp')\n",
"\n",
" return device_signals"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment