diff --git a/src/wmrc/main.py b/src/wmrc/main.py index aa9d81a..0767b6f 100644 --- a/src/wmrc/main.py +++ b/src/wmrc/main.py @@ -514,7 +514,7 @@ def subscribe(cloud_event: CloudEvent) -> None: #: Putting this here means you can call the file via `python main.py` and it will run. Useful for pre-GCF testing. if __name__ == "__main__": - # wmrc_skid = Skid() - # wmrc_skid.process() + wmrc_skid = Skid() + wmrc_skid.process() - run_validation() + # run_validation() diff --git a/src/wmrc/yearly.py b/src/wmrc/yearly.py index 012519b..c3d8b1d 100644 --- a/src/wmrc/yearly.py +++ b/src/wmrc/yearly.py @@ -57,18 +57,14 @@ 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() + counties_df["county_wide_msw_diverted_total"] = ( + counties_df["county_wide_msw_recycled"] + + counties_df["county_wide_msw_composted"] + + counties_df["county_wide_msw_digested"] + ) counties_df["county_wide_msw_recycling_rate"] = ( - ( - counties_df["county_wide_msw_recycled"] - + counties_df["county_wide_msw_composted"] - + counties_df["county_wide_msw_digested"] - ) - / ( - counties_df["county_wide_msw_recycled"] - + counties_df["county_wide_msw_composted"] - + counties_df["county_wide_msw_digested"] - + counties_df["county_wide_msw_landfilled"] - ) + counties_df["county_wide_msw_diverted_total"] + / (counties_df["county_wide_msw_diverted_total"] + counties_df["county_wide_msw_landfilled"]) * 100 ) @@ -194,18 +190,14 @@ def statewide_metrics(county_year_df: pd.DataFrame) -> pd.DataFrame: statewide_series["statewide_msw_composted"] = in_state_only["county_wide_msw_composted"].sum() statewide_series["statewide_msw_digested"] = in_state_only["county_wide_msw_digested"].sum() statewide_series["statewide_msw_landfilled"] = in_state_only["county_wide_msw_landfilled"].sum() + statewide_series["statewide_msw_diverted_total"] = ( + statewide_series["statewide_msw_recycled"] + + statewide_series["statewide_msw_composted"] + + statewide_series["statewide_msw_digested"] + ) statewide_series["statewide_msw_recycling_rate"] = ( - ( - statewide_series["statewide_msw_recycled"] - + statewide_series["statewide_msw_composted"] - + statewide_series["statewide_msw_digested"] - ) - / ( - statewide_series["statewide_msw_recycled"] - + statewide_series["statewide_msw_composted"] - + statewide_series["statewide_msw_digested"] - + statewide_series["statewide_msw_landfilled"] - ) + statewide_series["statewide_msw_diverted_total"] + / (statewide_series["statewide_msw_diverted_total"] + statewide_series["statewide_msw_landfilled"]) * 100 ) diff --git a/tests/test_yearly.py b/tests/test_yearly.py index 3963955..ff26506 100644 --- a/tests/test_yearly.py +++ b/tests/test_yearly.py @@ -1,10 +1,38 @@ import pandas as pd - from wmrc import yearly class TestYearlyMetrics: + def test_county_wide_metrics_happy_path(self): + facility_year_df = pd.DataFrame( + { + "Municipal_Solid_Waste__c": [50, 50], + "Combined_Total_of_Material_Recycled__c": [10, 20], + "Total_Materials_sent_to_composting__c": [0, 50], + "Total_Material_managed_by_ADC__c": [10, 0], + "Municipal_Waste_In_State_in_Tons__c": [80, 30], + "Cache_County__c": [50, 50], + "Utah_County__c": [50, 50], + } + ) + + 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], + }, + index=["Cache_County__c", "Utah_County__c"], + ) + + output = yearly.county_summaries(facility_year_df, ["Cache_County__c", "Utah_County__c"]) + + pd.testing.assert_frame_equal(output, expected_output) + def test_statewide_metrics_happy_path(self): input_df = pd.DataFrame( { @@ -12,6 +40,7 @@ def test_statewide_metrics_happy_path(self): "county_wide_msw_composted": [0, 0, 50], "county_wide_msw_digested": [10, 0, 0], "county_wide_msw_landfilled": [80, 90, 30], + "county_wide_msw_diverted_total": [20, 10, 70], }, index=["foo", "bar", "baz"], ) @@ -22,6 +51,7 @@ def test_statewide_metrics_happy_path(self): "statewide_msw_composted": 50, "statewide_msw_digested": 10, "statewide_msw_landfilled": 200, + "statewide_msw_diverted_total": 100, "statewide_msw_recycling_rate": 100 / 300 * 100, } )