Skip to content

Commit

Permalink
feat: calc total diverted tons for county and state
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams committed Aug 20, 2024
1 parent b660a48 commit e12e0fb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/wmrc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
36 changes: 14 additions & 22 deletions src/wmrc/yearly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)

Expand Down
32 changes: 31 additions & 1 deletion tests/test_yearly.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,46 @@
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(
{
"county_wide_msw_recycled": [10, 10, 20],
"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"],
)
Expand All @@ -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,
}
)
Expand Down

0 comments on commit e12e0fb

Please sign in to comment.