Skip to content

Commit

Permalink
🧐 Use percent instead of ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
jh0ker committed Nov 8, 2023
1 parent 754cfb3 commit 81b27ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions ddj_cloud/scrapers/talsperren/exporters/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +27,7 @@ def _add_daily_fill_ratio_to_map(
.resample("D")
.aggregate( # type: ignore
{
"fill_ratio": "median",
"fill_percent": "median",
}
)
)
Expand All @@ -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
Expand All @@ -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",
}
)
)
Expand All @@ -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")

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ddj_cloud/scrapers/talsperren/talsperren.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 81b27ed

Please sign in to comment.