Skip to content

Commit d4cb7ce

Browse files
committed
Fix for not loading polygons from zm_detect API call
1 parent a8f41a8 commit d4cb7ce

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

mlapi.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ def post(self):
112112

113113
if not req:
114114
req = {}
115+
115116
if req.get('mid') and str(req.get('mid')) in g.monitor_config:
116117
mid = str(req.get('mid'))
117118
g.logger.Debug (1, 'Monitor ID {} provided & matching config found in mlapi, ignoring objectconfig.ini'.format(mid))
118119
config_copy = copy.copy(g.config)
119120
poly_copy = copy.copy(g.polygons)
120121
g.polygons = copy.copy(g.monitor_polygons[mid])
121122

122-
123123
for key in g.monitor_config[mid]:
124124
# This will also take care of copying over mid specific stream_options
125125
g.logger.Debug(2, 'Overriding global {} with {}...'.format(key, g.monitor_config[mid][key][:30]))
@@ -139,8 +139,6 @@ def post(self):
139139

140140
g.polygons[:] = [item for item in g.polygons if utils.findWholeWord(item['name'])(r)]
141141
g.logger.Debug(2, 'Final polygons being used: {}'.format(g.polygons))
142-
143-
144142
if g.config['ml_sequence'] and g.config['use_sequence'] == 'yes':
145143
g.log.Debug(2,'using ml_sequence')
146144
ml_options = g.config['ml_sequence']
@@ -153,7 +151,7 @@ def post(self):
153151
ml_options = utils.convert_config_to_ml_sequence()
154152

155153
g.logger.Debug (2, 'Overwriting ml_sequence of pre loaded model')
156-
m.set_ml_options(ml_options)
154+
m.set_ml_options(ml_options)
157155
else:
158156
g.logger.Debug(1,'Monitor ID not specified, or not found in mlapi config, using zm_detect overrides')
159157
ml_overrides = req.get('ml_overrides',{})
@@ -167,20 +165,22 @@ def post(self):
167165
else:
168166
g.logger.Debug(2,'mapping legacy ml data from config')
169167
ml_options = utils.convert_config_to_ml_sequence()
168+
if 'polygons' in req.get('stream_options', {}):
169+
g.logger.Debug(2, "Set polygons from request")
170+
g.polygons = req.get('stream_options')['polygons']
171+
poly_copy = copy.deepcopy(g.polygons)
170172

171-
#print (ml_options)
172-
173173
if g.config.get('stream_sequence'):
174174
g.logger.Debug(2, 'Found stream_sequence in mlapi config, ignoring objectconfig.ini')
175175
stream_options = ast.literal_eval(g.config.get('stream_sequence'))
176176
else:
177177
stream_options = req.get('stream_options')
178178
if not stream_options:
179-
if config_copy:
180-
g.log.Debug(2, 'Restoring global config & ml_options')
181-
g.config = config_copy
182-
g.polygons = poly_copy
183-
abort(400, msg='No stream options found')
179+
if config_copy:
180+
g.log.Debug(2, 'Restoring global config & ml_options')
181+
g.config = config_copy
182+
g.polygons = poly_copy
183+
abort(400, msg='No stream options found')
184184
stream_options['api'] = zmapi
185185
stream_options['polygons'] = g.polygons
186186

0 commit comments

Comments
 (0)