diff --git a/configs/db_new.yaml b/configs/db_new.yaml index a70db6f31a6d7bf8de71f7196fc8fdcac1b1e559..08bed34b38c26c63b517faca51963961f34b82b0 100644 --- a/configs/db_new.yaml +++ b/configs/db_new.yaml @@ -2,12 +2,15 @@ main_config: max_missing : 120 db_params: user: c##mspils + #Passwort ist für eine lokale Datenbank ohne verbindung zum internet. Kann ruhig online stehen. password: cobalt_deviancy dsn: localhost/XE # Auch als Liste möglich zrxp_folder : ../data/dwd_ens_zrpx/ sensor_folder : ../data/db_in/ zrxp_out_folder : ../data/zrxp_out/ + #If True exports the forecasts if successful to zrxp + export_zrxp : True #if True tries to put all files in folder in the external forecast table load_sensor : False load_zrxp : True diff --git a/src/predict_database.py b/src/predict_database.py index 19207e7ec366be7a8ee12d5573f448a9beb783d9..28e8c3439a104c619de2efbaaa026dd47085022c 100644 --- a/src/predict_database.py +++ b/src/predict_database.py @@ -34,6 +34,7 @@ def get_configs(passed_args: argparse.Namespace) -> Tuple[dict, List[dict]]: if isinstance(main_config["zrxp_folder"], str): main_config["zrxp_folder"] = [main_config["zrxp_folder"]] main_config["zrxp_folder"] = list(map(Path, main_config["zrxp_folder"])) + main_config["zrxp_out_folder"] = Path(main_config["zrxp_out_folder"]) main_config["sensor_folder"] = Path(main_config["sensor_folder"]) main_config["start"] = pd.to_datetime(main_config["start"]) if "end" in main_config: @@ -98,8 +99,8 @@ def parse_args() -> argparse.Namespace: help="The start date for the prediction. Format: YYYY-MM-DD HH:MM, overwrites start/end/range in the config file.", ) parser.add_argument( - "--zrxp", action="store_true", help="Save predictions as ZRXP files (not yet implemented)" - ) #TODO: Implement ZRXP + "--zrxp", action="store_true", help="Save predictions as ZRXP files" + ) return parser.parse_args() diff --git a/src/utils/db_tools.py b/src/utils/db_tools.py index 7692012c7d8ab4818accb00009494e111b355816..2601a25c97736280ee7b7363e6b2d7e2d4fb59d2 100644 --- a/src/utils/db_tools.py +++ b/src/utils/db_tools.py @@ -431,6 +431,30 @@ class OracleWaVoConnection: fcst_values = {f"h{i}": None for i in range(1, 49)} else: fcst_values = {f"h{i}": forecast[i - 1].item() for i in range(1, 49)} + + if self.main_config.get("export_zrxp"): + target_file =self.main_config["zrxp_out_folder"] / f"{end_time.strftime("%Y%m%d%H")}_{sensor_name}_{model_name}_{member}.zrx" + #2023 11 19 03 + df_zrxp = pd.DataFrame(forecast,columns=["value"]) + df_zrxp["timestamp"] = end_time + df_zrxp["forecast"] = pd.date_range(start=end_time,periods=49,freq="1h")[1:] + df_zrxp["member"] = member + df_zrxp = df_zrxp[['timestamp','forecast','member','value']] + + + with open(target_file , 'w', encoding="utf-8") as file: + file.write('#REXCHANGEWISKI.' + model_name.split("_")[0] + '.W.KNN|*|\n') + file.write('#RINVAL-777|*|\n') + file.write('#LAYOUT(timestamp,forecast, member,value)|*|\n') + + df_zrxp.to_csv(path_or_buf = target_file, + header = False, + index=False, + mode='a', + sep = ' ', + date_format = '%Y%m%d%H%M') + + stmt = select(PegelForecasts).where( PegelForecasts.tstamp == bindparam("tstamp"),