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
... | ... | @@ -63,6 +63,7 @@ |
63 | 63 |
self.sources[key] = { |
64 | 64 |
"status_counts": [], |
65 | 65 |
"ok_counts": 0, |
66 |
+ "failure_counts" : 0, |
|
66 | 67 |
"force_send_mode": False, |
67 | 68 |
"most_recent_image" : None, |
68 | 69 |
"most_recent_mask" : None, |
... | ... | @@ -91,20 +92,22 @@ |
91 | 92 |
flag_send_event = False |
92 | 93 |
|
93 | 94 |
status_value = 1 if status == "OK" else 0 |
95 |
+ |
|
94 | 96 |
self.sources[source]["status_counts"].append(status_value) |
95 | 97 |
if len(self.sources[source]["status_counts"]) > self.buffer_size: |
96 | 98 |
self.sources[source]["status_counts"].pop(0) |
97 |
- |
|
99 |
+ print(len(self.sources[source]["status_counts"])) |
|
98 | 100 |
|
99 | 101 |
if self.sources[source]["force_send_mode"]: |
100 | 102 |
seek_n_recent_memory = min(len(self.sources[source]["status_counts"]), self.failure_mode_check_past_n) |
101 |
- failure_counts = (self.failure_mode_check_past_n |
|
102 |
- - sum(self.sources[source]["status_counts"][seek_n_recent_memory])) |
|
103 |
- ok_counts = self.failure_mode_check_past_n - failure_counts |
|
103 |
+ print(seek_n_recent_memory) |
|
104 |
+ self.sources[source]['ok_counts'] = (seek_n_recent_memory |
|
105 |
+ - sum(self.sources[source]["status_counts"][:-seek_n_recent_memory-1])) |
|
106 |
+ self.sources[source]['failure_counts'] = seek_n_recent_memory - self.sources[source]['ok_counts'] |
|
104 | 107 |
flag_send_event = True |
105 | 108 |
|
106 | 109 |
# mode switching condition check |
107 |
- if ok_counts >= self.normal_mode_thres: |
|
110 |
+ if self.sources[source]['ok_counts'] >= self.normal_mode_thres: |
|
108 | 111 |
self.sources[source]["force_send_mode"] = False |
109 | 112 |
flag_send_event = False |
110 | 113 |
self.sources[source]["failure_to_normal_mode_change_alert"] = True |
... | ... | @@ -112,12 +115,14 @@ |
112 | 115 |
|
113 | 116 |
else: |
114 | 117 |
seek_n_recent_memory = min(len(self.sources[source]["status_counts"]), self.normal_mode_check_past_n) |
115 |
- failure_counts = (self.normal_mode_check_past_n |
|
116 |
- - sum(self.sources[source]["status_counts"][:seek_n_recent_memory])) |
|
117 |
- # ok_counts = self.normal_mode_check_past_n - failure_counts |
|
118 |
+ print(seek_n_recent_memory) |
|
119 |
+ self.sources[source]['ok_counts'] = (seek_n_recent_memory |
|
120 |
+ - sum(self.sources[source]["status_counts"][:-seek_n_recent_memory-1])) |
|
121 |
+ self.sources[source]['failure_counts'] = seek_n_recent_memory - self.sources[source]['ok_counts'] |
|
122 |
+ # print(self.sources[source]['failure_counts']) |
|
118 | 123 |
|
119 | 124 |
# mode switching condition check |
120 |
- if failure_counts >= self.normal_mode_thres: |
|
125 |
+ if self.sources[source]['failure_counts'] >= self.failure_mode_thres: |
|
121 | 126 |
self.sources[source]["force_send_mode"] = True |
122 | 127 |
flag_send_event = True |
123 | 128 |
self.sources[source]["normal_to_failure_mode_change_alert"] = True |
... | ... | @@ -192,7 +197,6 @@ |
192 | 197 |
self.area_percent = float(self.area_percent) |
193 | 198 |
except (TypeError, ValueError) as e: |
194 | 199 |
raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}") |
195 |
- print(len(request.files)) |
|
196 | 200 |
self.image = request.files.get('image') |
197 | 201 |
self.mask = request.files.get('mask') |
198 | 202 |
self.seg_image = request.files.get('seg_mask') |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?