윤영준 윤영준 05-24
rewriting of event handling class, StreamSources 1. counting error fixed (ok_counts and failure_counts)
1. counting error fixed (ok_counts and failure_counts)
@f6108e8dff60c1e2eab568ba7cc2c8add0840428
postprocess_draft.py
--- postprocess_draft.py
+++ postprocess_draft.py
@@ -63,6 +63,7 @@
             self.sources[key] = {
                 "status_counts": [],
                 "ok_counts": 0,
+                "failure_counts" : 0,
                 "force_send_mode": False,
                 "most_recent_image" : None,
                 "most_recent_mask" : None,
@@ -91,20 +92,22 @@
         flag_send_event = False
 
         status_value = 1 if status == "OK" else 0
+
         self.sources[source]["status_counts"].append(status_value)
         if len(self.sources[source]["status_counts"]) > self.buffer_size:
             self.sources[source]["status_counts"].pop(0)
-
+        print(len(self.sources[source]["status_counts"]))
 
         if self.sources[source]["force_send_mode"]:
             seek_n_recent_memory = min(len(self.sources[source]["status_counts"]), self.failure_mode_check_past_n)
-            failure_counts = (self.failure_mode_check_past_n
-                              - sum(self.sources[source]["status_counts"][seek_n_recent_memory]))
-            ok_counts = self.failure_mode_check_past_n - failure_counts
+            print(seek_n_recent_memory)
+            self.sources[source]['ok_counts'] = (seek_n_recent_memory
+                              - sum(self.sources[source]["status_counts"][:-seek_n_recent_memory-1]))
+            self.sources[source]['failure_counts'] = seek_n_recent_memory - self.sources[source]['ok_counts']
             flag_send_event = True
 
             # mode switching condition check
-            if ok_counts >= self.normal_mode_thres:
+            if self.sources[source]['ok_counts'] >= self.normal_mode_thres:
                 self.sources[source]["force_send_mode"] = False
                 flag_send_event = False
                 self.sources[source]["failure_to_normal_mode_change_alert"] = True
@@ -112,12 +115,14 @@
 
         else:
             seek_n_recent_memory = min(len(self.sources[source]["status_counts"]), self.normal_mode_check_past_n)
-            failure_counts = (self.normal_mode_check_past_n
-                              - sum(self.sources[source]["status_counts"][:seek_n_recent_memory]))
-            # ok_counts = self.normal_mode_check_past_n - failure_counts
+            print(seek_n_recent_memory)
+            self.sources[source]['ok_counts'] = (seek_n_recent_memory
+                              - sum(self.sources[source]["status_counts"][:-seek_n_recent_memory-1]))
+            self.sources[source]['failure_counts'] = seek_n_recent_memory - self.sources[source]['ok_counts']
+            # print(self.sources[source]['failure_counts'])
 
             # mode switching condition check
-            if failure_counts >= self.normal_mode_thres:
+            if self.sources[source]['failure_counts'] >= self.failure_mode_thres:
                 self.sources[source]["force_send_mode"] = True
                 flag_send_event = True
                 self.sources[source]["normal_to_failure_mode_change_alert"] = True
@@ -192,7 +197,6 @@
                 self.area_percent = float(self.area_percent)
             except (TypeError, ValueError) as e:
                 raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}")
-            print(len(request.files))
             self.image = request.files.get('image')
             self.mask = request.files.get('mask')
             self.seg_image = request.files.get('seg_mask')
Add a comment
List