Skip to content

Commit

Permalink
Merge pull request #1079 from cal-itp/ah_gtfs_explore
Browse files Browse the repository at this point in the history
GTFS Digest Portfolio
  • Loading branch information
amandaha8 authored Apr 18, 2024
2 parents 59ee391 + 1222d47 commit 5a60971
Show file tree
Hide file tree
Showing 112 changed files with 9,149 additions and 6,333 deletions.
4,613 changes: 0 additions & 4,613 deletions gtfs_digest/01_existing_charts.ipynb

This file was deleted.

4,825 changes: 4,825 additions & 0 deletions gtfs_digest/01_section3.ipynb

Large diffs are not rendered by default.

286 changes: 259 additions & 27 deletions gtfs_digest/03_report_draft.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
"source": [
"%%capture\n",
"\n",
"import calitp_data_analysis.magics\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"import _report_utils as utils\n",
"import _section1_utils as section1\n",
"import _section2_utils as section2\n",
"import calitp_data_analysis.magics\n",
"import great_tables as gt\n",
"import pandas as pd\n",
"from IPython.display import HTML, Image, Markdown, display, display_html\n",
"\n"
"from shared_utils import catalog_utils, rt_dates, rt_utils\n",
"\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
Expand All @@ -45,7 +46,9 @@
},
"outputs": [],
"source": [
"name = \"Bay Area 511 AC Transit Schedule\""
"# Comment out and leave this cell right below pandas\n",
"# organization_name = \"Peninsula Corridor Joint Powers Board\"\n",
"# organization_name = \"City and County of San Francisco\""
]
},
{
Expand All @@ -57,90 +60,319 @@
},
"outputs": [],
"source": [
"# %%capture_parameters\n",
"# name"
"%%capture_parameters\n",
"organization_name"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7915371-6931-48a3-a03a-a1929970ec89",
"metadata": {},
"outputs": [],
"source": [
"most_recent_date = pd.to_datetime(rt_dates.DATES[\"mar2024\"])\n",
"year = most_recent_date.year"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79b03dda-e15e-40f3-908e-9d5fa4a5acf8",
"metadata": {},
"outputs": [],
"source": [
"name = section1.organization_name_crosswalk(organization_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8e11fd2-041f-4e1d-a00f-6e000269c1a7",
"metadata": {},
"outputs": [],
"source": [
"# Load first dataset to grab the column \"name\"\n",
"operator_profiles = section1.load_operator_profiles(organization_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0dd3557c-3ec2-450f-82f8-b792412c0785",
"id": "5b002155-25c2-4e2b-9729-8510abbef4b0",
"metadata": {},
"outputs": [],
"source": [
"sched_vp_df = utils.load_schedule_vp_metrics(name)"
"# Datasets for Section 1\n",
"operator_route_map = section1.load_operator_map(name)\n",
"monthly_scheduled_service = section1.summarize_monthly(name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0086203-5de0-49cc-b3e5-95991f8edc69",
"id": "f07ccefc-0d71-4ad0-8435-9e2941aba9b2",
"metadata": {},
"outputs": [],
"source": [
"# Datasets for Section 2\n",
"sched_vp_df = section2.load_schedule_vp_metrics(name)\n",
"gtfs_schedule_keys = list(sched_vp_df.schedule_gtfs_dataset_key.unique())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83e64546-97ed-4ba9-a8f6-c09aea1eb64e",
"id": "67a74771-f5c1-4757-9f79-bc5e87fba09e",
"metadata": {},
"outputs": [],
"source": [
"monthly_df = utils.summarize_monthly(\"2023\", name)"
"display(\n",
" HTML(\n",
" \"\"\"\n",
"<style>\n",
"form.vega-bindings {\n",
" position: absolute;\n",
" right: 0px;\n",
" top: 0px;\n",
"}\n",
"</style>\n",
"\"\"\"\n",
" )\n",
")"
]
},
{
"cell_type": "markdown",
"id": "38103db9-fd56-4cbf-9fa7-336da58fd3f6",
"metadata": {
"tags": [
"parameters"
]
},
"source": [
"# {organization_name}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9724e2c8-eb1a-4ac0-9890-02535d17504b",
"metadata": {},
"outputs": [],
"source": [
"# Overview for {name}"
"display(\n",
" Markdown(\n",
" f\"\"\"<h2 style=\"border-bottom: 3px solid #8CBCCB;\"><b>Operator Overview</b></h2>\n",
" \n",
" \"\"\"\n",
" )\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a5dea72a-d04f-4d7d-b9bb-3b7b244cd426",
"cell_type": "code",
"execution_count": null,
"id": "65e5efa4-e731-4429-ae8c-31f90dc4fbf0",
"metadata": {},
"outputs": [],
"source": [
"## Operator Overview - To Come"
"try:\n",
" date = operator_profiles[\"service_date\"].dt.to_pydatetime()[0]\n",
"except:\n",
" pass"
]
},
{
"cell_type": "markdown",
"id": "4d003b0a-f033-4544-a0bb-0dfbd60aacc3",
"cell_type": "code",
"execution_count": null,
"id": "232e2002-d043-43c1-80d2-22c1183c66a1",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" display(\n",
" Markdown(\n",
" f\"\"\"{organization_name} ran <b>{operator_profiles.operator_n_routes.values[0]}</b> \n",
" unique routes on {date.month}/{date.year}. Below is the breakdown of the routes.\"\"\"\n",
" )\n",
" )\n",
"except:\n",
" \n",
" display(\n",
" Markdown(\n",
" f\"\"\"{organization_name} doesn't have an operator profile.\"\"\"\n",
" )\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16cb774e-3e55-4377-8e3a-8707cdb4e965",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" section1.basic_pie_chart(\n",
" section1.route_typology(operator_profiles),\n",
" \"route_type\",\n",
" \"total_routes\",\n",
" \"Total Routes by Typology\",\n",
" )\n",
"except:\n",
" pass\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7f617f8-338d-4ea0-99e7-25c1bfe62e06",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" display(\n",
" Markdown(\n",
" f\"\"\"{organization_name} provided <b>{operator_profiles.operator_route_length_miles.values[0]}</b> miles of public transit.\n",
" The average length of a route is <b>{operator_route_map.route_length_miles.mean()}</b> miles.\n",
" \"\"\"\n",
" )\n",
" )\n",
"except:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b240e52-b3c5-439e-8c34-ede92c1e45cb",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" section1.basic_bar_chart(\n",
" section1.shortest_longest_route(operator_route_map),\n",
" \"route_length_miles\",\n",
" \"route_combined_name\",\n",
" f\"Longest and Shortest Route\"\n",
" )\n",
"except:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "821bca2d-7fdd-4e81-af9b-c02deabfe837",
"metadata": {},
"outputs": [],
"source": [
"display(\n",
" Markdown(f\"{organization_name} provides public transit in the following counties:\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1665382-75c0-4aca-9a59-37c3604f4ad7",
"metadata": {},
"outputs": [],
"source": [
"## Route-Direction Monthly Overview\n",
"Statistics presented on the <b>route</b> level. Scroll down to filter for a specific route. "
"try:\n",
" section1.counties_served(operator_route_map)\n",
"except:\n",
" display(\n",
" Markdown(\n",
" f\"\"\"{organization_name} doesn't have an route geographies.\"\"\"\n",
" )\n",
" )\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6973f1b0-2dfa-47b1-b72f-3980515b7f39",
"id": "aea29023-cf8d-4421-93a5-09c83ff8205d",
"metadata": {},
"outputs": [],
"source": [
"utils.single_bar_chart_dropdown(\n",
" monthly_df,\n",
"monthly_scheduled_service_df_agg = section1.summarize_monthly(name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "716419e0-5ab8-47fd-a02b-c8329ec226ba",
"metadata": {},
"outputs": [],
"source": [
"section1.single_bar_chart_dropdown(\n",
" monthly_scheduled_service_df_agg,\n",
" \"day_type\",\n",
" \"ttl_service_hours\",\n",
" \"time_of_day\",\n",
" \"Total Service Hours across all Routes per Month in 2023\",\n",
" \"Total Service Hours per Month\",\n",
" \"full_date\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aefcfda5-aae2-4d9b-beba-e283aadd6cc5",
"metadata": {},
"outputs": [],
"source": [
"display(\n",
" Markdown(\n",
" f\"\"\"<h2 style=\"border-bottom: 3px solid #8CBCCB;\"><b>Route Summary Statistics for {most_recent_date.month}/{most_recent_date.year}</b></h2>\n",
" \n",
" \"\"\"\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ca1dcfd-df73-49ba-80fa-dba917c7d8cb",
"metadata": {},
"outputs": [],
"source": [
"display(\n",
" Markdown(\n",
" f\"\"\"<h2 style=\"border-bottom: 3px solid #8CBCCB;\"><b>Detailed Route-Direction Overview</b></h2><br>\n",
" \n",
" \"\"\"\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c854432-4c78-4dce-aec5-d6c1a86f0f7d",
"metadata": {},
"outputs": [],
"source": [
"utils.trips_by_gtfs(sched_vp_df)"
"section2.trips_by_gtfs(sched_vp_df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9fbe546f-1c29-4011-b653-c7f35ffb5e20",
"metadata": {},
"outputs": [],
"source": [
"display(\n",
" Markdown(\n",
" f\"\"\"Statistics presented on the <b>route</b> level. Scroll down to filter for a specific route. \n",
" \"\"\"\n",
" )\n",
")"
]
},
{
Expand All @@ -150,7 +382,7 @@
"metadata": {},
"outputs": [],
"source": [
"utils.filtered_route(sched_vp_df)"
"section2.filtered_route(sched_vp_df)"
]
}
],
Expand Down
Loading

0 comments on commit 5a60971

Please sign in to comment.