\n",
+ ""
],
"text/plain": [
- " trip_instance_key\n",
- "bunched_y_n \n",
- "bunched 1\n",
- "not bunched 7"
+ "alt.Chart(...)"
]
},
- "execution_count": 154,
+ "execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "sf_49.loc[sf_49.rt_hour == 23].groupby([\"bunched_y_n\"]).agg(\n",
- " {\"trip_instance_key\": \"nunique\"}\n",
+ "sf_30_test = agg_operator_route_dir1.loc[\n",
+ " (agg_operator_route_dir1.organization_name == \"City and County of San Francisco\")\n",
+ " & (agg_operator_route_dir1.route_id == \"30\")\n",
+ "]\n",
+ "\n",
+ "sf_30_test_m = pd.melt(\n",
+ " sf_30_test,\n",
+ " id_vars=[\"organization_name\", \"route_id\", \"direction_id\"],\n",
+ " value_vars=[\"pct_bunched\", \"pct_not_bunched\"],\n",
+ ").rename(columns={\"value\": \"percentage\"})\n",
+ "\n",
+ "alt.Chart(sf_30_test_m).mark_bar().encode(\n",
+ " x=alt.X(\n",
+ " \"variable:O\",\n",
+ " axis=alt.Axis(labelAngle=-45),\n",
+ " ),\n",
+ " y=alt.Y(\"percentage:Q\", scale=alt.Scale(domain=[0, 100])),\n",
+ " color=alt.Color(\n",
+ " \"variable:N\",\n",
+ " title=\"Bunched or Not\",\n",
+ " scale=alt.Scale(range=color_dict[\"tri_color\"]),\n",
+ " ),\n",
+ " column=\"direction_id:N\",\n",
+ " tooltip=list(sf_30_test_m.columns),\n",
+ ").properties(\n",
+ " title={\n",
+ " \"text\": \"Total Occurences of Bunching for Operator-Route-Direction\",\n",
+ " },\n",
+ " width=200,\n",
+ " height=250,\n",
")"
]
},
{
"cell_type": "code",
- "execution_count": 155,
- "id": "8cf3d048-1e3a-4402-b85a-73a52727e6b7",
+ "execution_count": 161,
+ "id": "d2cb0fa7-6cbb-4817-9451-d99c7da86328",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
- "
\n",
- "\n",
+ "
\n",
+ ""
],
"text/plain": [
- " stop_id\n",
- "trip_instance_key bunched_y_n \n",
- "2f788ff486bdf8ff8a3435759aebbb2f bunched 1\n",
- " not bunched 29\n",
- "4332a5a17f95bc642d3ff9c3cc057416 not bunched 13\n",
- "6d3e80c5ab0949db88d364fec14ff85e not bunched 25\n",
- "86631e2647c3a05b9d876eee470ac5e6 not bunched 8\n",
- "aa38dc2d39adf3610f8149b05a900bfc not bunched 15\n",
- "c8f5a562a74dcd7d9b138abe4d9a96b2 not bunched 19\n",
- "def34654701618d0a4b4eefe240f9914 not bunched 35"
+ "alt.Chart(...)"
]
},
- "execution_count": 155,
+ "execution_count": 161,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "sf_49.loc[sf_49.rt_hour == 23].groupby([\"trip_instance_key\", \"bunched_y_n\"]).agg(\n",
- " {\"stop_id\": \"nunique\"}\n",
+ "sf_49_test = agg_operator_route_dir1.loc[\n",
+ " (agg_operator_route_dir1.organization_name == \"City and County of San Francisco\")\n",
+ " & (agg_operator_route_dir1.route_id == \"49\")\n",
+ "]\n",
+ "\n",
+ "sf_49_test_m = pd.melt(\n",
+ " sf_49_test,\n",
+ " id_vars=[\"organization_name\", \"route_id\", \"direction_id\"],\n",
+ " value_vars=[\"pct_bunched\", \"pct_not_bunched\"],\n",
+ ").rename(columns={\"value\": \"percentage\"})\n",
+ "\n",
+ "alt.Chart(sf_49_test_m).mark_bar().encode(\n",
+ " x=alt.X(\n",
+ " \"variable:O\",\n",
+ " axis=alt.Axis(labelAngle=-45),\n",
+ " ),\n",
+ " y=alt.Y(\"percentage:Q\", scale=alt.Scale(domain=[0, 100])),\n",
+ " color=alt.Color(\n",
+ " \"variable:N\",\n",
+ " title=\"Bunched or Not\",\n",
+ " scale=alt.Scale(range=color_dict[\"tri_color\"]),\n",
+ " ),\n",
+ " column=\"direction_id:N\",\n",
+ " tooltip=list(sf_49_test_m.columns),\n",
+ ").properties(\n",
+ " title={\n",
+ " \"text\": \"Total Occurences of Bunching for Operator-Route-Direction\",\n",
+ " },\n",
+ " width=200,\n",
+ " height=250,\n",
")"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "f8da417d-b975-4e66-9a37-64980318ea41",
+ "metadata": {},
+ "source": [
+ "#### Aggregate for `operator-route-direction-rt_arrival_hour`\n",
+ "* Testing a couple of options to see the difference.\n",
+ "* Do we care how many stops experience bunching or how many trips experience bunching?\n",
+ "* If one stop for a trip is bunched, the whole trip is considered bunched...Is that too \"draconian\"?\n",
+ " * Per my conversation with Katie, generally if one stop is bunched, the whole trip is considered bunched."
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 153,
- "id": "7fbaafcb-3daa-43ea-8d7a-b090919281e9",
+ "execution_count": 129,
+ "id": "aea6be3d-f024-41c0-806c-b675f19697e0",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.006944444444444444"
- ]
- },
- "execution_count": 153,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
+ "source": [
+ "op_route_dir_hour_groupby_cols = [\n",
+ " \"caltrans_district\",\n",
+ " \"schedule_gtfs_dataset_key\",\n",
+ " \"feed_key\",\n",
+ " \"organization_name\",\n",
+ " \"route_long_name\",\n",
+ " \"route_type\",\n",
+ " \"route_id\",\n",
+ " \"direction_id\",\n",
+ " \"rt_hour\",\n",
+ "]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 131,
+ "id": "d999d94d-3199-4333-8c3f-b0de3b458271",
+ "metadata": {},
+ "outputs": [],
"source": [
- "1 / 144"
+ "agg_operator_route_dir_hour = aggregation(\n",
+ " transit_matters_df1,\n",
+ " op_route_dir_hour_groupby_cols,\n",
+ " op_route_dir_hour_groupby_cols,\n",
+ " \"stop_id\",\n",
+ " \"nunique\",\n",
+ ")"
]
},
{
"cell_type": "code",
- "execution_count": 143,
- "id": "b3fe356e-b0a0-4fe6-bd61-eaccbfa6991e",
+ "execution_count": 141,
+ "id": "70be1dc8-0f7e-43f6-a485-1c21305b9fe2",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.02857142857142857"
- ]
- },
- "execution_count": 143,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
- "1 / 35"
+ "agg_operator_trip_dir_hour2 = aggregation(\n",
+ " transit_matters_df1,\n",
+ " op_route_dir_hour_groupby_cols,\n",
+ " op_route_dir_hour_groupby_cols,\n",
+ " \"trip_instance_key\",\n",
+ " \"nunique\",\n",
+ ")"
]
},
{
"cell_type": "code",
- "execution_count": 138,
+ "execution_count": 137,
"id": "a4c24e52-b061-4ae5-b053-97e5ce175f5d",
"metadata": {},
"outputs": [],
"source": [
- "one_route49 = agg_operator_route_dir_hour.loc[\n",
+ "one_route49_stop_bunched = agg_operator_route_dir_hour.loc[\n",
" (\n",
" agg_operator_route_dir_hour.organization_name\n",
" == \"City and County of San Francisco\"\n",
@@ -4072,24 +4025,24 @@
},
{
"cell_type": "code",
- "execution_count": 139,
+ "execution_count": 144,
"id": "8d94893f-5766-4a77-a30d-f6661f4f1470",
"metadata": {},
"outputs": [],
"source": [
- "one_route49_test2 = agg_operator_route_dir_hour2.loc[\n",
+ "one_route49_test2_trip_bunched = agg_operator_trip_dir_hour2.loc[\n",
" (\n",
- " agg_operator_route_dir_hour2.organization_name\n",
+ " agg_operator_trip_dir_hour2.organization_name\n",
" == \"City and County of San Francisco\"\n",
" )\n",
- " & (agg_operator_route_dir_hour2.route_id == \"49\")\n",
- " & (agg_operator_route_dir_hour2.direction_id == 1)\n",
+ " & (agg_operator_trip_dir_hour2.route_id == \"49\")\n",
+ " & (agg_operator_trip_dir_hour2.direction_id == 1)\n",
"]"
]
},
{
"cell_type": "code",
- "execution_count": 148,
+ "execution_count": 139,
"id": "b8169ed2-dac2-491e-92fe-85ed2e61bcd2",
"metadata": {},
"outputs": [
@@ -4098,23 +4051,23 @@
"text/html": [
"\n",
"\n",
- "
\n",
+ "
\n",
"