5
5
from .httpurllib import request_post
6
6
from .httpurllib import make_url
7
7
from .class_template import ClassTemplate
8
+ from .eplus_object import EnergyPlusObject
8
9
9
10
10
11
class Model (object ):
@@ -454,7 +455,7 @@ def bldg_orientation(self):
454
455
else :
455
456
return - 1
456
457
457
- def hvac_swap (self , temp_dir , autosize = True , select_sys = None ):
458
+ def hvac_swap (self , temp_dir = None , hvac_type = 1 , autosize = True , select_sys = None , zone_group = None ):
458
459
"""
459
460
Test function - do not use it
460
461
"""
@@ -464,13 +465,10 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
464
465
if len (test ) is 3 :
465
466
track = "track_token"
466
467
467
- files = dict ()
468
- if temp_dir is not None :
469
- files ['model' ] = open (temp_dir , 'rb' )
470
-
471
468
payload = {
472
469
'project_api_key' : self ._project_api_key ,
473
- track : self ._track_token
470
+ track : self ._track_token ,
471
+ 'hvac_type' : hvac_type
474
472
}
475
473
476
474
if autosize is True :
@@ -481,7 +479,15 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
481
479
if select_sys is not None :
482
480
payload ['select_system' ] = select_sys
483
481
484
- r = request_post (url , params = payload , files = files )
482
+ if zone_group is not None :
483
+ payload ['zone_group' ] = zone_group
484
+
485
+ if temp_dir is not None :
486
+ files = dict ()
487
+ files ['model' ] = open (temp_dir , 'rb' )
488
+ r = request_post (url , params = payload , files = files )
489
+ else :
490
+ r = request_post (url , params = payload )
485
491
resp_json = r .json ()
486
492
if r .status_code > 200 :
487
493
# log action
@@ -504,13 +510,15 @@ def hvac_swap(self, temp_dir, autosize=True, select_sys=None):
504
510
print ('Name: ' + sys ['hvac' ] + ', Type: ' + sys ['object' ])
505
511
print ('Description: ' + sys ['description' ])
506
512
print ('Supply: ' )
507
- supply = sys ['supply' ]
508
- for supply_comp in supply :
509
- print (supply_comp )
513
+ if 'supply' in sys :
514
+ supply = sys ['supply' ]
515
+ for supply_comp in supply :
516
+ print (supply_comp )
510
517
print ('Demand: ' )
511
- demand = sys ['demand' ]
512
- for demand_comp in demand :
513
- print (demand_comp )
518
+ if 'demand' in sys :
519
+ demand = sys ['demand' ]
520
+ for demand_comp in demand :
521
+ print (demand_comp )
514
522
print ('BuildSim choose the first listed system for merge.' )
515
523
print (data ['message' ])
516
524
@@ -859,6 +867,58 @@ def zone_load(self, zone_name=None):
859
867
else :
860
868
return - 1
861
869
870
+ def add_object (self , object_array ):
871
+ """
872
+ add objects to the energy model
873
+
874
+ :param object_array: the array of EnergyPlusObject class
875
+ :return:
876
+ """
877
+ # validation
878
+ idf_data = list ()
879
+ for template in object_array :
880
+ if not isinstance (template , EnergyPlusObject ):
881
+ print ("The add object must be type of EnergyPlusObject" )
882
+ raise Exception ("Type error" )
883
+ else :
884
+ temp_obj = template .get_object ()
885
+ idf_data .append (temp_obj )
886
+
887
+ url = self ._base_url + 'AddNewObjects_API'
888
+ track = "folder_api_key"
889
+ test = self ._track_token .split ("-" )
890
+ if len (test ) is 3 :
891
+ track = "track_token"
892
+ payload = {
893
+ 'project_api_key' : self ._project_api_key ,
894
+ track : self ._track_token ,
895
+ 'object_list' : idf_data
896
+ }
897
+
898
+ print (payload )
899
+ r = request_post (url , params = payload )
900
+ if r .status_code == 200 :
901
+ data = r .json ()
902
+ print (data ['message' ])
903
+
904
+ # log action
905
+ if self ._logger is not None :
906
+ self ._logger .write_in_message ('Model' , 'AddNewObjects_API' , self ._project_api_key ,
907
+ self ._track_token , r .status_code , data ['tracking' ])
908
+
909
+ return data ['tracking' ]
910
+ else :
911
+ r_json = r .json ()
912
+ # log action
913
+ if self ._logger is not None :
914
+ self ._logger .write_in_message ('Model' , 'AddModifyZone' , self ._project_api_key ,
915
+ self ._track_token , r .status_code , 'error' )
916
+ try :
917
+ print ('Code: ' + str (r .status_code ) + ' message: ' + r_json ['error_msg' ])
918
+ except TypeError :
919
+ print (r_json )
920
+ return False
921
+
862
922
def add_modify_zone (self , zone_list , template_array ):
863
923
"""
864
924
add and modify object according to zone
0 commit comments