ソースを参照

amended judgment for np.NAN

chenhaiyang 4 年 前
コミット
9cea0b9968
2 ファイル変更8 行追加8 行削除
  1. 7 7
      app/controllers/targets.py
  2. 1 1
      app/utils/math.py

+ 7 - 7
app/controllers/targets.py

@@ -128,7 +128,7 @@ class TemperatureTargetController(TargetController):
         _RANGE = 1
         new_target = 24.0
         new_lower_bound, new_upper_bound = new_target - 1.0, new_target + 1.0
-        if self._realtime_data is not np.NAN:
+        if not np.isnan(self._realtime_data):
             if self._season == Season.cooling:
                 if ('a little hot' in self._feedback
                         or 'so hot' in self._feedback
@@ -149,9 +149,9 @@ class TemperatureTargetController(TargetController):
     async def get_targets(self) -> float:
         current_lower_target = self._current_targets['temperatureMin'].loc[self._quarter_time]
         current_upper_target = self._current_targets['temperatureMax'].loc[self._quarter_time]
-        if current_lower_target is np.NAN:
+        if np.isnan(current_lower_target):
             current_lower_target = 23.0
-        if current_upper_target is np.NAN:
+        if np.isnan(current_upper_target):
             current_upper_target = 25.0
 
         return (current_lower_target + current_upper_target) / 2
@@ -159,7 +159,7 @@ class TemperatureTargetController(TargetController):
     async def readjust_current(self, current: float, diff: float) -> float:
         _RANGE = 2
         new_target = current
-        if self._realtime_data is np.NAN:
+        if np.isnan(self._realtime_data):
             new_target += diff
         else:
             if self._season == Season.cooling:
@@ -234,21 +234,21 @@ class Co2TargetController(TargetController):
     async def init_temporary(self) -> float:
         new_target = 1000
         diff = await self.calculate_diff(CO2_RELATED_FEEDBACK_WEIGHT)
-        if self._realtime_data is not np.NAN:
+        if not np.isnan(self._realtime_data):
             new_target += diff
 
         return self._cut(new_target)
 
     async def get_targets(self) -> float:
         current_upper_target = self._current_targets['co2Max'].loc[self._quarter_time]
-        if current_upper_target is np.NAN:
+        if np.isnan(current_upper_target):
             current_upper_target = 500.0
 
         return current_upper_target
 
     async def readjust_current(self, lower: float, upper: float, diff: float) -> float:
         new_target = upper - lower
-        if self._realtime_data is np.NAN:
+        if np.isnan(self._realtime_data):
             new_target += diff
         else:
             if (diff > 50 and self._realtime_data + 100 > upper

+ 1 - 1
app/utils/math.py

@@ -5,7 +5,7 @@ import numpy as np
 
 
 def round_half_up(n: float, decimals: int = 0) -> float:
-    if n is np.nan:
+    if np.isnan(n):
         return n
     else:
         multiplier = 10 ** decimals