Created
June 14, 2018 00:11
-
-
Save csb19815/476335cb299ddb3d5a1a4b898424bb35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import partridge as ptg" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"(datetime.date(2018, 2, 9), datetime.date(2018, 6, 15))\n" | |
] | |
} | |
], | |
"source": [ | |
"path1 = '/Users/Charlie/Downloads/SFTMA_then.zip'\n", | |
"path2 = '/Users/Charlie/Downloads/SFMTA_now.zip'\n", | |
"\n", | |
"date1, service_ids1 = ptg.read_busiest_date(path1)\n", | |
"date2, service_ids2 = ptg.read_busiest_date(path2)\n", | |
"\n", | |
"print (date1, date2)\n", | |
"\n", | |
"feed1 = ptg.feed(path1, view={'trips.txt': {'service_id': service_ids1}})\n", | |
"feed2 = ptg.feed(path2, view={'trips.txt': {'service_id': service_ids2}})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def service_hours(feed):\n", | |
" # Given a feed that's been filtered to a specific date, \n", | |
" # return the sum of the durations of all trips\n", | |
" trip_lengths = feed.stop_times.groupby('trip_id').arrival_time.agg(['min', 'max'])\n", | |
" service_hours = (trip_lengths['max'] - trip_lengths['min']) / 60 / 60\n", | |
" return service_hours.sum()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(8324.056111111111, 8341.383333333333)" | |
] | |
}, | |
"execution_count": 36, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"service_hours(feed1), service_hours(feed2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"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.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment