Coverage for bim2sim/plugins/PluginComfort/bim2sim_comfort/utils/utils_comfort_templates.py: 0%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-12 17:09 +0000

1import os 

2from pathlib import Path 

3 

4import pandas as pd 

5 

6import openpyxl 

7 

8 

9class ComfortUtils: 

10 @staticmethod 

11 def convert_use_conditions_to_xls(json_file, result_path=""): 

12 """ convert a given UseConditions.json file to .xls. 

13 """ 

14 df_json = pd.read_json(json_file) 

15 df_json = df_json.transpose() 

16 df_json.to_excel(result_path + 'UseConditions_EXTENDED.xlsx') 

17 

18 @staticmethod 

19 def new_empty_json_keeping_first_keys(json_file): 

20 df_json = pd.read_json(json_file) 

21 json_keys = df_json.keys() 

22 new_json = pd.DataFrame(index=json_keys, columns=['clo', 'met']) 

23 new_json.to_excel('EmptyUseConditions.xlsx') 

24 

25 @staticmethod 

26 def convert_xlsx_to_json(xls_name, json_name): 

27 file = pd.read_excel(xls_name) 

28 json_file = file.to_json(json_name) 

29 

30 @staticmethod 

31 def convert_csv_to_json(csv_name, json_name, sep=';'): 

32 file = pd.read_csv(filepath_or_buffer=csv_name, sep=sep, 

33 index_col=0).transpose() 

34 json_file = file.to_json(json_name, indent=4) 

35 

36 @staticmethod 

37 def extend_use_conditions(json_name, use_conditions): 

38 file = pd.read_json(use_conditions).transpose() 

39 new_parameters_json = pd.read_json(json_name).transpose() 

40 

41 # replace TEASER Template Values with new derived values from 

42 # ISO7730 and ASHRAE 

43 file['activity_degree_persons'] = \ 

44 new_parameters_json['ISO7730_ASHRAE_Combined_met'] 

45 file['fixed_heat_flow_rate_persons'] = \ 

46 new_parameters_json['ISO7730_ASHRAE_Combined_WperPerson'] 

47 # Set new clothing params (clo values) derived from ISO7730 and ASHRAE 

48 file['clothing_persons'] = \ 

49 new_parameters_json['ISO7730_ASHRAE_Combined_clo'] 

50 file['surround_clo_persons'] = \ 

51 new_parameters_json['surround_insulation_combined_clo'] 

52 

53 # write new comfort use conditions to the asset directory. 

54 comfort_use_conditions = str(os.path.splitext(use_conditions)[0]) + \ 

55 'Comfort.json' 

56 file.transpose().to_json(comfort_use_conditions, indent=4) 

57 

58 

59 

60if __name__ == '__main__': 

61 # use_conditions_path = Path(__file__).parent.parent.parent.parent.parent \ 

62 # / "assets/enrichment/usage/UseConditions.json" 

63 # ComfortUtils.convert_use_conditions_to_xls( 

64 # use_conditions_path) 

65 # ComfortUtils.new_empty_json_keeping_first_keys(use_conditions_path) 

66 usage_path = Path(__file__).parent.parent.parent.parent.parent / \ 

67 'assets' / 'enrichment' / 'usage' 

68 new_json_name = 'activity_clothing_ISO7730_ASHRAE_V002.json' 

69 

70 ComfortUtils.convert_csv_to_json( 

71 r'C:\Users\richter\sciebo\03-Paperdrafts' 

72 r'\MDPI_SpecialIssue_Comfort_Climate' 

73 r'\activity_clothing_ISO7730_ASHRAE_V002.csv', new_json_name) 

74 ComfortUtils.extend_use_conditions(new_json_name, usage_path / 

75 'UseConditions.json') 

76