From 81b27ed1ac02e9290e0f3e0a5486b2db80aa20a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Wed, 8 Nov 2023 18:26:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=90=20Use=20percent=20instead=20of=20r?= =?UTF-8?q?atio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddj_cloud/scrapers/talsperren/exporters/map.py | 16 ++++++++-------- ddj_cloud/scrapers/talsperren/talsperren.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ddj_cloud/scrapers/talsperren/exporters/map.py b/ddj_cloud/scrapers/talsperren/exporters/map.py index ea82430..e9472ef 100644 --- a/ddj_cloud/scrapers/talsperren/exporters/map.py +++ b/ddj_cloud/scrapers/talsperren/exporters/map.py @@ -10,7 +10,7 @@ class MapExporter(Exporter): filename = "map" - def _add_daily_fill_ratio_to_map( + def _add_daily_fill_percent_to_map( self, df_base: pd.DataFrame, df_map: pd.DataFrame ) -> pd.DataFrame: # Resample df to daily @@ -27,7 +27,7 @@ def _add_daily_fill_ratio_to_map( .resample("D") .aggregate( # type: ignore { - "fill_ratio": "median", + "fill_percent": "median", } ) ) @@ -50,12 +50,12 @@ def _add_daily_fill_ratio_to_map( ts = today_midnight - dt.timedelta(days=days_offset) ts = pd.Timestamp(ts) df_day = df_daily.loc[(slice(None), ts), :].reset_index(level=1, drop=True) - df_day.rename(columns={"fill_ratio": f"fill_ratio_day_{days_offset}"}, inplace=True) + df_day.rename(columns={"fill_percent": f"fill_percent_day_{days_offset}"}, inplace=True) df_map = df_map.merge(df_day, how="left", on="id") return df_map - def _add_monthly_fill_ratio_to_map( + def _add_monthly_fill_percent_to_map( self, df_base: pd.DataFrame, df_map: pd.DataFrame ) -> pd.DataFrame: # Resample df to monthly @@ -73,7 +73,7 @@ def _add_monthly_fill_ratio_to_map( .resample("M", closed="right", label="left") .aggregate( # type: ignore { - "fill_ratio": "median", + "fill_percent": "median", } ) ) @@ -97,7 +97,7 @@ def _add_monthly_fill_ratio_to_map( ts = pd.Timestamp(ts) df_month = df_monthly.loc[(slice(None), ts), :].reset_index(level=1, drop=True) df_month.rename( - columns={"fill_ratio": f"fill_ratio_month_{months_offset}"}, inplace=True + columns={"fill_percent": f"fill_percent_month_{months_offset}"}, inplace=True ) df_map = df_map.merge(df_month, how="left", on="id") @@ -114,10 +114,10 @@ def run(self, df_base: pd.DataFrame) -> pd.DataFrame: df_map.reset_index(drop=True, inplace=True) # Add daily fill ratio - df_map = self._add_daily_fill_ratio_to_map(df_base, df_map) + df_map = self._add_daily_fill_percent_to_map(df_base, df_map) # Add monthly fill ratio - df_map = self._add_monthly_fill_ratio_to_map(df_base, df_map) + df_map = self._add_monthly_fill_percent_to_map(df_base, df_map) # round all floats to 5 decimals df_map = df_map.round(5) diff --git a/ddj_cloud/scrapers/talsperren/talsperren.py b/ddj_cloud/scrapers/talsperren/talsperren.py index 1adac93..fef8891 100644 --- a/ddj_cloud/scrapers/talsperren/talsperren.py +++ b/ddj_cloud/scrapers/talsperren/talsperren.py @@ -94,7 +94,7 @@ def _get_base_dataset(): # Add additional columns used for exporting # Calculate fill ratio - df["fill_ratio"] = df["content_mio_m3"] / df["capacity_mio_m3"] + df["fill_percent"] = df["content_mio_m3"] / df["capacity_mio_m3"] * 100 # Add metadata from federation classes metas = {