Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save csb19815/aadef16178dfcb5ba7a8d88fbf718749 to your computer and use it in GitHub Desktop.
Save csb19815/aadef16178dfcb5ba7a8d88fbf718749 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"import partridge as ptg"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"inpath = '/Users/Charlie/Downloads/target_feed.zip'\n",
"outpath = '/Users/Charlie/Downloads/output_feed.zip'\n",
"agency_id = 'target_agency_id'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2017-25'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"service_ids_by_date = ptg.read_service_ids_by_date(inpath)\n",
"trip_counts_by_date = ptg.read_trip_counts_by_date(inpath)\n",
"\n",
"weekly_trip_counts = defaultdict(int)\n",
"weekly_service_ids = defaultdict(set)\n",
"for date, service_ids in service_ids_by_date.items():\n",
" key = date.strftime('%G-%V')\n",
" weekly_trip_counts[key] += trip_counts_by_date[date]\n",
" weekly_service_ids[key] |= service_ids\n",
"\n",
"week, _ = max(weekly_trip_counts.items(), key=lambda p: p[1])\n",
"service_ids = weekly_service_ids[week]\n",
"\n",
"week"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/Users/Charlie/Downloads/Sydney_shrunk.zip'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ptg.writers.extract_feed(inpath, outpath, {\n",
" 'trips.txt': {'service_id': service_ids},\n",
" 'agency.txt': {'agency_id': agency_id},\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment