Skip to content

Commit

Permalink
chore: include statewide total in county summary
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams committed Oct 31, 2024
1 parent 0d0b910 commit a917787
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/wmrc/yearly.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def county_summaries(year_df: pd.DataFrame, county_fields: list[str]) -> pd.Data
counties_df["county_wide_msw_composted"] = composted_df.sum()
counties_df["county_wide_msw_digested"] = digested_df.sum()
counties_df["county_wide_msw_landfilled"] = landfilled_df.sum()
statewide = counties_df.sum()
statewide.name = "Statewide"
counties_df = pd.concat([counties_df, pd.DataFrame(statewide).T], axis=0)

counties_df["county_wide_msw_diverted_total"] = (
counties_df["county_wide_msw_recycled"]
+ counties_df["county_wide_msw_composted"]
Expand Down
18 changes: 11 additions & 7 deletions tests/test_yearly.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ def test_county_wide_metrics_happy_path(self):

expected_output = pd.DataFrame(
{
"county_wide_msw_recycled": [7.5, 7.5],
"county_wide_msw_composted": [12.5, 12.5],
"county_wide_msw_digested": [2.5, 2.5],
"county_wide_msw_landfilled": [55.0, 55.0],
"county_wide_msw_diverted_total": [22.5, 22.5],
"county_wide_msw_recycling_rate": [22.5 / (22.5 + 55.0) * 100, 22.5 / (22.5 + 55.0) * 100],
"county_wide_msw_recycled": [7.5, 7.5, 15.0],
"county_wide_msw_composted": [12.5, 12.5, 25.0],
"county_wide_msw_digested": [2.5, 2.5, 5.0],
"county_wide_msw_landfilled": [55.0, 55.0, 110.0],
"county_wide_msw_diverted_total": [22.5, 22.5, 45.0],
"county_wide_msw_recycling_rate": [
22.5 / (22.5 + 55.0) * 100,
22.5 / (22.5 + 55.0) * 100,
45.0 / (45.0 + 110.0) * 100,
],
},
index=["Cache_County__c", "Utah_County__c"],
index=["Cache_County__c", "Utah_County__c", "Statewide"],
)

output = yearly.county_summaries(facility_year_df, ["Cache_County__c", "Utah_County__c"])
Expand Down

0 comments on commit a917787

Please sign in to comment.