Skip to content

Commit 7a9c861

Browse files
authored
Merge pull request #436 from cal-itp/tircp_cleanup
TIRCP
2 parents cbf295e + b2f045c commit 7a9c861

File tree

4 files changed

+63
-26
lines changed

4 files changed

+63
-26
lines changed

consolidated_app/utilities.py

-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
from calitp import *
44
from plotnine import *
55
import intake
6-
from shared_utils import geography_utils
76

87
import altair as alt
9-
import altair_saver
108
from shared_utils import geography_utils
119
from shared_utils import altair_utils
1210
from shared_utils import calitp_color_palette as cp

tircp/A7_zev.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
from calitp import *
33
import A1_data_prep
44

5-
from plotnine import *
6-
import intake
7-
from shared_utils import geography_utils
8-
95
import altair as alt
10-
import altair_saver
11-
from shared_utils import geography_utils
126
from shared_utils import altair_utils
137
from shared_utils import calitp_color_palette as cp
148
from shared_utils import styleguide
@@ -28,20 +22,21 @@ def grab_zev_count(df, description_col: str):
2822
# Replace numbers that are written out into integers
2923
df[description_col] = (
3024
df[description_col]
31-
.str.replace("seven", "7")
3225
.str.replace("two", "2")
3326
.str.replace("three", "3")
3427
.str.replace("four", "4")
3528
.str.replace("five", "5")
3629
.str.replace("six", "6")
30+
.str.replace("seven", "7")
3731
.str.replace("eight", "8")
32+
.str.replace("nine", "9")
3833
.str.replace("eleven", "11")
3934
.str.replace("fifteen", "15")
4035
.str.replace("twenty", "20")
4136
)
4237

4338
# Extract numbers from description into a new column
44-
# cast as float, fill in zeroes
39+
# cast as float, fill in NA with 0
4540
df["number_of_zev"] = (
4641
df[description_col].str.extract("(\d+)").astype("float64").fillna(0)
4742
)
@@ -67,11 +62,6 @@ def grab_zev_count(df, description_col: str):
6762
"""
6863
Summary table for ZEV
6964
"""
70-
# Format numbers to currency in uuu8
71-
#def currency_format(df, col_name: str):
72-
# df[col_name] = "$" + (df[col_name].astype(float)).round(0).astype(str)
73-
# return df
74-
7565
def zev_summary(
7666
df_zev,
7767
df_all_projects,
@@ -130,7 +120,6 @@ def labeling(word):
130120
return word
131121

132122
### Bar chart with interactive tooltip: x_col and y_col will show up ###
133-
### This function only returns a chart, doesn't save
134123
def basic_bar_chart(df, x_col, y_col, colorcol, chart_title=''):
135124
if chart_title == "":
136125
chart_title = (f"{labeling(x_col)} by {labeling(y_col)}")
@@ -150,7 +139,6 @@ def basic_bar_chart(df, x_col, y_col, colorcol, chart_title=''):
150139
)
151140

152141
chart=styleguide.preset_chart_config(chart)
153-
# chart.save(f"./bar_{chart_title}.png")
154142
return chart
155143

156144

tircp/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# TIRCP
2+
3+
**TIRCP**, The Transit and Intercity Rail Capital Program (TIRCP) was created by Senate Bill (SB) 862 (Chapter 36, Statutes of 2014) and modified by 9 (Chapter 710, Statutes of 2015), to provide grants from the Greenhouse Gas Reduction Fund (GGRF) to fund transformative capital improvements that will modernize California’s intercity, commuter, and urban rail systems, and bus and ferry transit systems to significantly reduce emissions of greenhouse gases, vehicle miles traveled, and congestion. [Source](https://dot.ca.gov/programs/rail-and-mass-transportation/transit-and-intercity-rail-capital-program)
4+
5+
## Sections
6+
7+
### [Presentations](./presentations/):
8+
1. [CTC Presentation](./presentations/Interim_Expenditures_Solution.ipynb): Notebook for CTC presentation.
9+
2. [Interim Expenditures](./presentations/Interim_Expenditures_Solution.ipynb): Notebook that takes expenditures data from InfoAdvantage and merges it with TIRCP data on Project ID. This was prepared for an internal PMP presentation.
10+
11+
### [Zero Emission Vehicles]:
12+
1. [ZEV LCTOP TIRCP](./zev_lctop_tircp.ipynb): Notebook that estimates the number, type (LRV versus bus), and funding amount for purchasing ZEV through the LCTOP and TIRCP programs. The associated functions are under A7_zev.py.
13+
3. [ZEV Charts](./zev_charts): The saved charts from the notebook.
14+
15+
16+
### [Other]:
17+
1. [Tableau](./A2_tableau.py): This script prepares the Excel workbook that serves as the data source for the TIRCP Tableau dashboard.
18+
2. [Semiannual Report](./A3_semiannual_report.py): This script automates the Semiannual Report that summarizes how TIRCP projects have progressed.
19+
3. [Program Allocation Plan](./A4_program_allocation_plan.py): This script automates the Program Allocation Plan that is submitted every few months to show how funds are scheduled to be allocated.
20+
4. [Crosswalks](./A5_crosswalks.py): There are manual portions of cleaning up this data and all the crosswalks are located here.
21+
5. [Full Script](./A6_full_script.py): A function that builds the first three reports and saves them to GCS.

tircp/zev_lctop_tircp.ipynb

+39-9
Original file line numberDiff line numberDiff line change
@@ -288,24 +288,44 @@
288288
{
289289
"cell_type": "code",
290290
"execution_count": null,
291-
"id": "4aa9c044-945e-4c17-ab5b-8cf3ca0393ec",
291+
"id": "a6cf9006-2654-4b6d-8726-82f3e41ffe20",
292292
"metadata": {},
293293
"outputs": [],
294294
"source": [
295-
"# Function for comparing total funding amount versus total estimated expense\n",
296-
"def funding_vs_expenses(df):\n",
297-
" if df[\"total_project_request_99314_+_99313\"] == df[\"total_project_cost\"]:\n",
295+
"def funding_vs_expenses(row):\n",
296+
" if row[\"total_project_request_99314_+_99313\"] == row[\"total_project_cost\"]:\n",
298297
" return \"Fully funded\"\n",
299-
" if df[\"total_project_cost\"] == 0:\n",
298+
" if row[\"total_project_cost\"] == 0:\n",
300299
" return \"No project cost info, just 0\"\n",
301-
" elif df[\"total_project_request_99314_+_99313\"] > df[\"total_project_cost\"]:\n",
300+
" elif row[\"total_project_request_99314_+_99313\"] > row[\"total_project_cost\"]:\n",
302301
" return \"Funding exceeds total expenses\"\n",
303-
" elif df[\"total_project_request_99314_+_99313\"] < df[\"total_project_cost\"]:\n",
302+
" elif row[\"total_project_request_99314_+_99313\"] < row[\"total_project_cost\"]:\n",
304303
" return \"Not fully funded\"\n",
305304
" else:\n",
306305
" return \"Not fully funded\""
307306
]
308307
},
308+
{
309+
"cell_type": "code",
310+
"execution_count": null,
311+
"id": "4d5c6f83-8acd-4976-ad05-5f288aeb81db",
312+
"metadata": {},
313+
"outputs": [],
314+
"source": [
315+
"df_lctop3['fully_funded'] = df_lctop3.apply(lambda x: funding_vs_expenses(x), axis=1)"
316+
]
317+
},
318+
{
319+
"cell_type": "code",
320+
"execution_count": null,
321+
"id": "383bfa38-758f-441f-9ed7-9760a3127a0d",
322+
"metadata": {},
323+
"outputs": [],
324+
"source": [
325+
"# Apply function to determine if a project is fully funded or not\n",
326+
"df_lctop3['fully_funded'] = df_lctop3.apply(funding_vs_expenses, axis=1)"
327+
]
328+
},
309329
{
310330
"cell_type": "code",
311331
"execution_count": null,
@@ -501,7 +521,7 @@
501521
},
502522
"outputs": [],
503523
"source": [
504-
"# df_tircp_zev"
524+
"# df_tircp_zev.head(5)"
505525
]
506526
},
507527
{
@@ -553,7 +573,7 @@
553573
"\n",
554574
"# Open the workbook in a dictionary\n",
555575
"dict_df1 = pd.read_excel(\n",
556-
" \"gs://calitp-analytics-data/data-analyses/tircp/LCTOP_TIRCP_manual_ZEV_count.xlsx\",\n",
576+
" \"gs://calitp-analytics-data/data-analyses/tircp/LCTOP_TIRCP_ZEV_manual.xlsx\",\n",
557577
" sheet_name=sheets_list,\n",
558578
")"
559579
]
@@ -570,6 +590,16 @@
570590
"tircp_clean = to_snakecase(dict_df1.get(\"tircp\"))"
571591
]
572592
},
593+
{
594+
"cell_type": "code",
595+
"execution_count": null,
596+
"id": "3a75d4eb-4eb2-475f-af81-99138a599e30",
597+
"metadata": {},
598+
"outputs": [],
599+
"source": [
600+
"tircp_clean.head(2)"
601+
]
602+
},
573603
{
574604
"cell_type": "markdown",
575605
"id": "c6ba5966-b1e0-4b07-8718-d573764de145",

0 commit comments

Comments
 (0)