Skip to content

Commit

Permalink
Update da_report.py
Browse files Browse the repository at this point in the history
Bugfix: api did not work for  deze_week, deze_maand etc.
  • Loading branch information
soeter01 authored Dec 5, 2024
1 parent 059d356 commit 2f227ce
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions dao/prog/da_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

class Report:
periodes = {}
# logging.basicConfig(level=logging.DEBUG) ###


def __init__(self, file_name: str = "../data/options.json"):
self.config = Config(file_name)
Expand Down Expand Up @@ -400,7 +398,7 @@ def aggregate_data(
df_raw["tot"] = df_raw.apply(
lambda x: datetime.datetime.fromtimestamp(x["tijd"]), axis=1
)
# logging.basicConfig(level=logging.DEBUG) ###

if len(df_raw) > 0:
# Extract year and month or day
if agg == "maand":
Expand Down Expand Up @@ -578,7 +576,7 @@ def calc_cost(
prod_df = self.get_sensor_sum(
self.grid_dict["prod"]["sensors"], vanaf, tot, "prod"
)
# logging.basicConfig(level=logging.DEBUG) ###

da_df = self.get_price_data(vanaf, tot)
da_df.index = pd.to_datetime(da_df["time"])
data = self.copy_col_df(cons_df, da_df, "cons")
Expand Down Expand Up @@ -696,9 +694,8 @@ def recalc_df_ha(self, org_data_df: pd.DataFrame, interval: str) -> pd.DataFrame
"profit": "sum",
}
)
logging.debug(f"fi_df: {fi_df.to_string()}")
ds_help = []
for i in range(len(fi_df.index)):
for _ in range(len(fi_df.index)): # Add the recorded datasoort if interval != uur and hence aggregated data is used
ds_help.append('recorded')
fi_df['datasoort'] = ds_help
return fi_df
Expand Down Expand Up @@ -1025,7 +1022,7 @@ def get_grid_data(
:param _source: als != None dan hier de source all, da of ha
:return: een dataframe met de gevraagde griddata
"""
# logging.basicConfig(level=logging.DEBUG) ###

values_table = Table(
"values", self.db_da.metadata, autoload_with=self.db_da.engine
)
Expand Down Expand Up @@ -1189,11 +1186,9 @@ def get_grid_data(
df_ha["datasoort"] = "recorded"
else:
last_moment = vanaf
# logging.debug(f"rs df_ha: {df_ha.to_string()}")


if source == "all" or source == "da":
# logging.debug(f"interval: {interval}")
if last_moment < tot and interval == "uur":
if last_moment < tot and interval == "uur": # no prognoses if interval != uur
# get prognose consumption and production:
prog_table = Table(
"prognoses",
Expand Down Expand Up @@ -1240,7 +1235,6 @@ def get_grid_data(
df_ha = df_prog
else:
df_ha = pd.concat([df_ha, df_prog])
# logging.debug(f"df_ha_tot: {df_ha.to_string()}")

df_prices.index = pd.to_datetime(df_prices["tijd"])
df_ha = self.copy_col_df(df_prices, df_ha, "price")
Expand Down Expand Up @@ -1655,8 +1649,6 @@ def calc_save_baseloads(self):

# ------------------------------------------------
def get_field_data(self, field: str, periode: str):
# logging.basicConfig(level=logging.DEBUG) ###
# logging.debug("rs: get field data")
period = self.periodes[periode]
if not (field in self.energy_balance_dict):
result = None
Expand Down Expand Up @@ -1709,8 +1701,6 @@ def get_field_data(self, field: str, periode: str):

def get_price_data(self, start, end):
from dao.prog.utils import get_value_from_dict
# logging.basicConfig(level=logging.DEBUG) ###
logging.debug("rs: get price data")

df_da = self.db_da.get_column_data("values", "da", start=start, end=end)
old_dagstr = ""
Expand Down Expand Up @@ -1750,8 +1740,6 @@ def get_soc_data(
return df

def get_api_data(self, field: str, periode: str, cumulate: bool = False):
# logging.basicConfig(level=logging.DEBUG) ###
logging.debug(f"{datetime.datetime.now()}: rs: get api data") ###
periode = periode.replace("_", " ")
grid_fields = [
"consumption",
Expand All @@ -1761,15 +1749,12 @@ def get_api_data(self, field: str, periode: str, cumulate: bool = False):
"profit",
"netto_cost",
]
# logging.debug(f"rs: field; {field}, period: {periode}")
df = pd.DataFrame()
if field in ["grid"] + grid_fields: # grid data
df_grid = self.get_grid_data(periode)
# logging.debug(f"rs: dfgrid: {df_grid.to_string()}")
df_grid["time"] = df_grid["vanaf"].apply(
lambda x: pd.to_datetime(x).strftime("%Y-%m-%d %H:%M")
)
# logging.debug(f"rs: dfgrid2: {df_grid.to_string()}")

if field in grid_fields:
df = df_grid[["time", field, "datasoort"]].copy()
Expand Down

0 comments on commit 2f227ce

Please sign in to comment.