Skip to content

Commit

Permalink
make data collection in scenario evaluation possible for old and newe…
Browse files Browse the repository at this point in the history
…r data
  • Loading branch information
k-rieck committed Nov 25, 2024
1 parent 97916db commit ce4b500
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions hisim/postprocessing/scenario_evaluation/result_data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(

list_with_result_data_folders = self.get_only_useful_data(result_path=result_folder)


if data_processing_mode == ResultDataProcessingModeEnum.PROCESS_ALL_DATA.name:
parameter_key = None

Expand Down Expand Up @@ -119,6 +120,8 @@ def get_only_useful_data(self, result_path: str) -> List[str]:
print(
"len of list with all paths to containing result data ", len(list_with_all_paths_to_check),
)
if len(list_with_all_paths_to_check) == 0:
raise ValueError("Result paths for scenario evaluation could not be found. Please check your result folder paths.")
if len(list_with_all_paths_to_check) < 20:
print(
"list with all paths to containing result data ", list_with_all_paths_to_check,
Expand Down Expand Up @@ -201,23 +204,47 @@ def filter_results_that_failed_to_heat_or_cool_building_sufficiently(
"temp deviation above set cooling [°C*h], folder \n"
)
for folder in list_of_result_path_that_contain_scenario_data:
scenario_data_information = os.path.join(folder, "data_for_scenario_evaluation.json")

scenario_data_information_new_version = os.path.join(folder, "data_for_scenario_evaluation.json")
scenario_data_information_old_version = os.path.join(folder, "data_information_for_scenario_evaluation.json")

main_folder = os.path.normpath(folder + os.sep + os.pardir)
all_kpis_json_file = os.path.join(main_folder, "all_kpis.json")

# get set temperatures used in the simulation
if os.path.exists(scenario_data_information):
with open(scenario_data_information, "r", encoding="utf-8") as data_info_file:
if os.path.exists(scenario_data_information_new_version):
with open(scenario_data_information_new_version, "r", encoding="utf-8") as data_info_file:
try:
simulation_configuration_data = json.load(data_info_file)
except Exception as exc:
content = data_info_file.read()
if content.strip() == "":
raise ValueError(
"The json file is empty. Maybe run the simulation again. "
f"The concerned folder is {folder}"
) from exc
component_entries = simulation_configuration_data["componentEntries"]
for component in component_entries:
if "Building" in component["componentName"]:
set_heating_temperature = float(
component["configuration"].get("set_heating_temperature_in_celsius")
)
set_cooling_temperature = float(
component["configuration"].get("set_cooling_temperature_in_celsius")
)
break
elif os.path.exists(scenario_data_information_old_version):
with open(scenario_data_information_old_version, "r", encoding="utf-8") as data_info_file:
try:
kpi_data = json.load(data_info_file)
simulation_configuration_data = json.load(data_info_file)
except Exception as exc:
content = data_info_file.read()
if content.strip() == "":
raise ValueError(
"The json file is empty. Maybe run the simulation again. "
f"The concerned folder is {folder}"
) from exc
component_entries = kpi_data["componentEntries"]
component_entries = simulation_configuration_data["componentEntries"]
for component in component_entries:
if "Building" in component["componentName"]:
set_heating_temperature = float(
Expand All @@ -228,13 +255,25 @@ def filter_results_that_failed_to_heat_or_cool_building_sufficiently(
)
break
else:
raise FileNotFoundError(f"The file {scenario_data_information} could not be found. ")
raise FileNotFoundError(f"Neither the file {scenario_data_information_new_version} nor the file {scenario_data_information_old_version} could not be found. ")

# open the webtool kpis and check if building got too hot or too cold
if os.path.exists(all_kpis_json_file):
with open(all_kpis_json_file, "r", encoding="utf-8") as kpi_file:
kpi_data = json.load(kpi_file)["BUI1"]
print("kpi_data", kpi_data)
# try two methods because older and newer data have different formats
try:
kpi_data = json.load(kpi_file)["BUI1"]
except:
# Reset file pointer to the beginning
kpi_file.seek(0)
contents = kpi_file.read()
if not contents.strip():
print(f"Raw contents:\n{repr(contents)}")
try:
kpi_data = json.loads(contents)
except json.JSONDecodeError as e:
print("Invalid JSON syntax:", e)

# check if min and max temperatures are too low or too high
min_temperature = float(
kpi_data["Building"]["Minimum building indoor air temperature reached"].get("value")
Expand Down

0 comments on commit ce4b500

Please sign in to comment.