|
@@ -65,24 +65,44 @@ class VAVController(EquipmentController):
|
|
|
return target_result, realtime_result
|
|
|
|
|
|
async def build_virtual_temperature_v2(self):
|
|
|
- weights = sorted(self.weights, key=lambda weight: weight.temporary_weight_update_time)
|
|
|
- if weights[-1].temporary_weight_update_time > get_time_str(60 * 60 * 2, flag='ago'):
|
|
|
- weight_dic = {weight.id: 0.0 for weight in weights}
|
|
|
- weight_dic.update({weights[-1].id: weights[-1].temporary_weight})
|
|
|
+ valid_spaces = []
|
|
|
+ weights = []
|
|
|
+ for sp in self._equipment.spaces:
|
|
|
+ if sp.realtime_temperature > 0.0 and sp.temperature_target > 0.0:
|
|
|
+ valid_spaces.append(sp)
|
|
|
+ for weight in self.weights:
|
|
|
+ if weight.space_id == sp.id:
|
|
|
+ weights.append(weight)
|
|
|
+
|
|
|
+ if valid_spaces:
|
|
|
+ weights = sorted(weights, key=lambda x: x.temporary_weight_update_time)
|
|
|
+ if weights[-1].temporary_weight_update_time > get_time_str(60 * 60 * 2, flag='ago'):
|
|
|
+ weight_dic = {weight.space_id: 0.0 for weight in weights}
|
|
|
+ weight_dic.update({weights[-1].space_id: weights[-1].temporary_weight})
|
|
|
+ else:
|
|
|
+ weight_dic = {weight.space_id: weight.default_weight for weight in weights}
|
|
|
+ total_weight_value = 0.0
|
|
|
+ for v in weight_dic.values():
|
|
|
+ total_weight_value += v
|
|
|
+ if total_weight_value > 0:
|
|
|
+ weight_dic = {k: v / total_weight_value for k, v in weight_dic.items()}
|
|
|
+ else:
|
|
|
+ weight_dic.update({list(weight_dic.keys())[0]: 1.0})
|
|
|
+
|
|
|
+ try:
|
|
|
+ virtual_target, virtual_realtime = 0.0, 0.0
|
|
|
+ for sp in valid_spaces:
|
|
|
+ virtual_target += sp.temperature_target * weight_dic.get(sp.id)
|
|
|
+ virtual_realtime += sp.realtime_temperature * weight_dic.get(sp.id)
|
|
|
+ except KeyError:
|
|
|
+ logger.error(f'{self._equipment.id} has wrong vav-space relation')
|
|
|
+ raise HTTPException(status_code=404, detail='This VAV box has wrong eq-sp relation')
|
|
|
+
|
|
|
+ self._equipment.virtual_target_temperature = virtual_target
|
|
|
+ self._equipment.virtual_realtime_temperature = virtual_realtime
|
|
|
else:
|
|
|
- weight_dic = {weight.id: weight.default_weight for weight in weights}
|
|
|
-
|
|
|
- try:
|
|
|
- virtual_target, virtual_realtime = 0.0, 0.0
|
|
|
- for sp in self._equipment.spaces:
|
|
|
- virtual_target += sp.temperature_target * weight_dic.get(sp.id)
|
|
|
- virtual_realtime += sp.realtime_temperature * weight_dic.get(sp.id)
|
|
|
- except KeyError:
|
|
|
- logger.error(f'{self._equipment.id} has wrong vav-space relation')
|
|
|
- raise HTTPException(status_code=404, detail='This VAV box has wrong eq-sp relation')
|
|
|
-
|
|
|
- self._equipment.virtual_target_temperature = virtual_target
|
|
|
- self._equipment.virtual_realtime_temperature = virtual_realtime
|
|
|
+ self._equipment.virtual_target_temperature = np.NAN
|
|
|
+ self._equipment.virtual_realtime_temperature = np.NAN
|
|
|
|
|
|
async def rectify(self) -> Tuple[float, float]:
|
|
|
for sp in self._equipment.spaces:
|