From a917787d90c2f99ea3e722568a365f795e136548 Mon Sep 17 00:00:00 2001 From: Jake Adams Date: Thu, 31 Oct 2024 11:40:28 -0600 Subject: [PATCH] chore: include statewide total in county summary --- src/wmrc/yearly.py | 4 ++++ tests/test_yearly.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/wmrc/yearly.py b/src/wmrc/yearly.py index 9c9d252..19a0f80 100644 --- a/src/wmrc/yearly.py +++ b/src/wmrc/yearly.py @@ -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"] diff --git a/tests/test_yearly.py b/tests/test_yearly.py index 9f659a5..2d944bb 100644 --- a/tests/test_yearly.py +++ b/tests/test_yearly.py @@ -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"])