Browse Source

catch TypeError and amend temperature value if target is NAN

chenhaiyang 4 years ago
parent
commit
e0ddb9f99f
2 changed files with 7 additions and 4 deletions
  1. 1 2
      app/controllers/equipment/fcu/q_learning.py
  2. 6 2
      app/services/platform.py

+ 1 - 2
app/controllers/equipment/fcu/q_learning.py

@@ -58,7 +58,6 @@ class QLearningCommandBuilder:
         return int(speed)
 
     async def get_command(self, current_temperature: float, pre_temperature: float, actual_target: float) -> Dict:
-        # actual_target = np.mean(np.array(target))
         input_value = np.array([
             [(current_temperature - actual_target) / 5],
             [(current_temperature - pre_temperature) / 5]
@@ -87,7 +86,7 @@ class QLearningCommandBuilder:
             'onOff': on_off,
             'mode': season,
             'speed': int(speed),
-            'temperature': actual_target,
+            'temperature': actual_target if not np.isnan(actual_target) else None,
             'water': water_on_off
         }
         return command

+ 6 - 2
app/services/platform.py

@@ -64,8 +64,10 @@ class DataPlatformService(Service):
             if arrow.get(latest_time, TIME_FMT).shift(minutes=15) < arrow.get(self._now_time, TIME_FMT):
                 logger.info(f'delayed data - {object_id}: ({latest_time}, {latest_data})')
             value = round_half_up(latest_data, 2)
-        except KeyError and IndexError and TypeError:
+        except KeyError and IndexError:
             value = np.NAN
+        except TypeError:
+            value = -1.0
 
         return value
 
@@ -99,8 +101,10 @@ class DataPlatformService(Service):
             if arrow.get(latest_time, TIME_FMT).shift(minutes=15) < arrow.get(end_time, TIME_FMT):
                 logger.info(f'delayed data - {object_id}: ({latest_time}, {latest_data})')
             value = round_half_up(latest_data, 2)
-        except KeyError and IndexError and TypeError:
+        except KeyError and IndexError:
             value = np.NAN
+        except TypeError:
+            value = -1.0
 
         return value