Forráskód Böngészése

add switch set routers and logic

highing666 3 éve
szülő
commit
6d98f187b7

+ 3 - 3
app/api/routers/devices.py

@@ -55,7 +55,7 @@ async def get_acatah_supply_air_temperature_set(
 
 @router.post('/instructions/acatah/freq-set', response_model=domain_devices.ACATAHFreqSetResponse)
 async def get_acatah_freq_set(params: domain_devices.ACATAHFreqSetRequest):
-    freq_set = build_acatah_freq_set(params)
+    freq_set = await build_acatah_freq_set(params)
 
     logger.info(params)
     logger.info(f'{params.device_id}: freq set - {freq_set}')
@@ -65,7 +65,7 @@ async def get_acatah_freq_set(params: domain_devices.ACATAHFreqSetRequest):
 
 @router.post('/instructions/acatah/switch-set', response_model=domain_devices.ACATAHSwitchSetResponse)
 async def get_acatah_switch_set(params: domain_devices.ACATAHSwitchSetRequest):
-    switch_set = build_acatah_switch_set(params)
+    switch_set = await build_acatah_switch_set(params)
 
     logger.info(params)
     logger.info(f'{params.device_id}: switch set - {switch_set}')
@@ -75,7 +75,7 @@ async def get_acatah_switch_set(params: domain_devices.ACATAHSwitchSetRequest):
 
 @router.post('/instructions/acvtsf/switch-set', response_model=domain_devices.ACVTSFSwitchSetResponse)
 async def get_acvtsf_switch_set(params: domain_devices.ACVTSFSwitchSetRequest):
-    switch_set = build_acvtsf_switch_set(params)
+    switch_set = await build_acvtsf_switch_set(params)
 
     logger.info(params)
     logger.info(f'{params.device_id}: switch set - {switch_set}')

+ 6 - 4
app/controllers/equipment/ahu/basic.py

@@ -36,7 +36,7 @@ class AHUController:
             else:
                 temp_freq_set = pre_fan_freq_set
 
-        temperature_value_list = np.array([item['value'] for item in supply_air_temperature_set_duration])
+        temperature_value_list = np.array(supply_air_temperature_set_duration)
         freq_upper_limit = 90.0
         if (temperature_value_list.size > 0
                 and np.all(temperature_value_list == temperature_value_list[0])
@@ -66,11 +66,12 @@ async def get_freq_controlled(project_id: str, equipment_id: str) -> None:
             hot_rate = count.get('hotNum') / (count.get('hotNum') + count.get('coldNum') + count.get('normalNum'))
         except (ZeroDivisionError, KeyError):
             hot_rate = 0.0
-        supply_air_temperature_set = await platform.get_duration(
+        raw_supply_air_temperature_set = await platform.get_duration(
             InfoCode.supply_air_temperature_set,
             equipment_id,
             30 * 60
         )
+        supply_air_temperature_set = [item['value'] for item in raw_supply_air_temperature_set]
 
     equip_params = {
         'id': equipment_id,
@@ -95,7 +96,7 @@ async def get_freq_controlled(project_id: str, equipment_id: str) -> None:
 
 
 @logger.catch()
-def build_acatah_freq_set(params: ACATAHFreqSetRequest) -> float:
+async def build_acatah_freq_set(params: ACATAHFreqSetRequest) -> float:
     acat_system = ACAT(
         supply_static_press=params.system_supply_static_press,
         supply_static_press_set=params.system_supply_static_press_set
@@ -105,5 +106,6 @@ def build_acatah_freq_set(params: ACATAHFreqSetRequest) -> float:
     )
 
     ahu_controller = AHUController(ahu, acat_system)
-    # new_freq_set = await ahu_controller.build_freq_set(params.supply_air_temperature_set, params.spaces_hot_rate)
+    new_freq_set = await ahu_controller.build_freq_set(params.supply_air_temperature_set, params.spaces_hot_rate)
 
+    return new_freq_set

+ 24 - 6
app/controllers/equipment/ahu/switch.py

@@ -16,9 +16,9 @@ class AHUSwitch(Switch):
     def __init__(self, equipment: AHU):
         super(AHUSwitch, self).__init__(equipment)
 
-    def break_time_action(self, begin: str, end: str, day_type: str) -> str:
+    def break_time_action(self, begin: str, end: str, is_workday: bool) -> str:
         if self._equip.in_cloud_status:
-            if day_type == 'WeekDay':
+            if is_workday:
                 if begin and end:
                     switch_flag = True
                     if begin <= end:
@@ -54,10 +54,11 @@ async def fetch_break_time(project_id: str, device_id: str) -> Tuple[str, str]:
 @logger.catch()
 async def ahu_switch_control(project_id: str, equipment_id: str) -> None:
     equip_params, day_type = await fetch_data(project_id, equipment_id)
+    is_workday = True if day_type.get('day_type') == 'WeekDay' else False
     begin, end = await fetch_break_time(project_id, equipment_id)
     switch_controller = AHUSwitch(AHU(**equip_params))
-    action = await switch_controller.build_next_action(day_type.get('day_type'))
-    break_action = switch_controller.break_time_action(begin, end, day_type.get('day_type'))
+    action = await switch_controller.build_next_action(is_workday)
+    break_action = switch_controller.break_time_action(begin, end, is_workday)
     if break_action == 'off':
         action = 'off'
     logger.debug(f'AHU-{equipment_id}: {action}')
@@ -65,5 +66,22 @@ async def ahu_switch_control(project_id: str, equipment_id: str) -> None:
 
 
 @logger.catch()
-def build_acatah_switch_set(params: ACATAHSwitchSetRequest) -> str:
-    pass
+async def build_acatah_switch_set(params: ACATAHSwitchSetRequest) -> str:
+    ahu = AHU(
+        running_status=params.running_status,
+        in_cloud_status=params.in_cloud_status,
+        on_time=params.on_time,
+        off_time=params.off_time
+    )
+    ahu_switch_controller = AHUSwitch(ahu)
+    action = await ahu_switch_controller.build_next_action(params.is_workday)
+    break_action = ahu_switch_controller.break_time_action(
+        params.break_start_time,
+        params.break_end_time,
+        params.is_workday
+    )
+
+    if break_action == 'off':
+        action = 'off'
+
+    return action

+ 2 - 1
app/controllers/equipment/pau/switch.py

@@ -23,6 +23,7 @@ async def pau_switch_control(project_id: str, equipment_id: str) -> None:
 @logger.catch()
 async def get_switch_action(project_id: str, device_id: str) -> str:
     device_params, day_type = await fetch_data(project_id, device_id)
-    action = await PAUSwitch(PAU(**device_params)).build_next_action(day_type.get('day_type'))
+    is_workday = True if day_type.get('day_type') == 'WeekDay' else False
+    action = await PAUSwitch(PAU(**device_params)).build_next_action(is_workday)
 
     return action

+ 2 - 2
app/controllers/equipment/switch.py

@@ -18,9 +18,9 @@ class Switch:
         self._equip = equipment
         self._now_time = arrow.get(get_time_str(), TIME_FMT).time().strftime('%H%M%S')
 
-    async def build_next_action(self, day_type: str) -> str:
+    async def build_next_action(self, is_workday: bool) -> str:
         if self._equip.in_cloud_status:
-            if day_type == 'WeekDay':
+            if is_workday:
                 if self._equip.on_time <= self._equip.off_time:
                     if self._equip.on_time <= self._now_time <= self._equip.off_time:
                         switch_flag = True

+ 15 - 4
app/controllers/equipment/ventilation_fan/switch.py

@@ -16,13 +16,24 @@ class VentilationFanSwitch(Switch):
 @logger.catch()
 async def ventilation_fan_switch_control(project_id: str, equipment_id: str) -> None:
     equip_params, day_type = await fetch_data(project_id, equipment_id)
-    action = await VentilationFanSwitch(VentilationFan(**equip_params)).build_next_action(day_type.get('day_type'))
-    if day_type.get('day_type') != 'WeekDay':
+    is_workday = True if day_type.get('day_type') == 'WeekDay' else False
+    action = await VentilationFanSwitch(VentilationFan(**equip_params)).build_next_action(is_workday)
+    if not is_workday:
         action = 'off'
     logger.debug(f'VTSF-{equipment_id}: {action}')
     await send_switch_command(project_id, equipment_id, action)
 
 
 @logger.catch()
-def build_acvtsf_switch_set(params: ACVTSFSwitchSetRequest) -> str:
-    pass
+async def build_acvtsf_switch_set(params: ACVTSFSwitchSetRequest) -> str:
+    vrf = VentilationFan(
+        running_status=params.running_status,
+        in_cloud_status=params.in_cloud_status,
+        on_time=params.on_time,
+        off_time=params.off_time,
+    )
+    action = await VentilationFanSwitch(vrf).build_next_action(params.is_workday)
+    if not params.is_workday:
+        action = 'off'
+
+    return action

+ 1 - 1
app/models/domain/devices.py

@@ -90,7 +90,7 @@ class ACATAHFreqSetRequest(BaseModel):
     system_supply_static_press: float
     system_supply_static_press_set: float
     current_freq_set: float
-    supply_air_temperature_set: float
+    supply_air_temperature_set: List[float]
     spaces_hot_rate: float