@@ -170,14 +170,15 @@ def invoke(self, db_task, data):
170
170
})
171
171
quality = data .get ("quality" )
172
172
mapping = data .get ("mapping" , {})
173
+ attr_mapping = data .get ("attrMapping" , {})
173
174
mapping_by_default = {}
174
175
task_attributes = {}
175
176
for db_label in (db_task .project .label_set if db_task .project_id else db_task .label_set ).prefetch_related ("attributespec_set" ).all ():
176
177
mapping_by_default [db_label .name ] = db_label .name
177
178
task_attributes [db_label .name ] = {}
178
179
for attribute in db_label .attributespec_set .all ():
179
180
task_attributes [db_label .name ][attribute .name ] = {
180
- 'input_rype ' : attribute .input_type ,
181
+ 'input_type ' : attribute .input_type ,
181
182
'values' : attribute .values .split ('\n ' )
182
183
}
183
184
if not mapping :
@@ -189,12 +190,19 @@ def invoke(self, db_task, data):
189
190
mapping = {k :v for k ,v in mapping .items () if v in mapping_by_default }
190
191
supported_attrs = {}
191
192
for func_label , func_attrs in self .func_attributes .items ():
192
- if func_label in mapping :
193
- supported_attrs [func_label ] = {}
194
- task_attr_names = [task_attr for task_attr in task_attributes [mapping [func_label ]]]
195
- for attr in func_attrs :
196
- if attr ['name' ] in task_attr_names :
197
- supported_attrs [func_label ].update ({attr ["name" ] : attr })
193
+ if func_label not in mapping :
194
+ continue
195
+
196
+ mapped_label = mapping [func_label ]
197
+ mapped_attributes = attr_mapping [func_label ].get ("attributes" )
198
+ supported_attrs [func_label ] = { }
199
+ task_attr_names = [task_attr for task_attr in task_attributes [mapped_label ]]
200
+
201
+ for attr in func_attrs :
202
+ mapped_attr = mapped_attributes .get (attr ["name" ])
203
+ if mapped_attr in task_attr_names :
204
+ supported_attrs [func_label ].update ({ attr ["name" ]: task_attributes [mapped_label ][mapped_attr ] })
205
+
198
206
if self .kind == LambdaType .DETECTOR :
199
207
payload .update ({
200
208
"image" : self ._get_image (db_task , data ["frame" ], quality )
@@ -259,28 +267,42 @@ def check_attr_value(value, func_attr, db_attr):
259
267
return db_attr_type == "text" or \
260
268
(db_attr_type in ["select" , "radio" ] and len (value .split (" " )) == 1 )
261
269
elif func_attr_type == "select" :
262
- return db_attr [ "input_type" ] in ["radio" , "text" ]
270
+ return db_attr_type in ["radio" , "text" ]
263
271
elif func_attr_type == "radio" :
264
- return db_attr [ "input_type" ] in ["select" , "text" ]
272
+ return db_attr_type in ["select" , "text" ]
265
273
elif func_attr_type == "checkbox" :
266
274
return value in ["true" , "false" ]
267
275
else :
268
276
return False
269
277
if self .kind == LambdaType .DETECTOR :
270
278
for item in response :
271
- if item ['label' ] in mapping :
272
- attributes = deepcopy (item .get ("attributes" , []))
273
- item ["attributes" ] = []
274
- for attr in attributes :
275
- db_attr = supported_attrs .get (item ['label' ], {}).get (attr ["name" ])
276
- func_attr = [func_attr for func_attr in self .func_attributes .get (item ['label' ], []) if func_attr ['name' ] == attr ["name" ]]
277
- # Skip current attribute if it was not declared as supportd in function config
278
- if not func_attr :
279
- continue
280
- if attr ["name" ] in supported_attrs .get (item ['label' ], {}) and check_attr_value (attr ["value" ], func_attr [0 ], db_attr ):
281
- item ["attributes" ].append (attr )
282
- item ['label' ] = mapping [item ['label' ]]
283
- response_filtered .append (item )
279
+ item_label = item ['label' ]
280
+
281
+ if item_label not in mapping :
282
+ continue
283
+
284
+ attributes = deepcopy (item .get ("attributes" , []))
285
+ item ["attributes" ] = []
286
+ supported_label = supported_attrs .get (item_label , {})
287
+ mapped_attributes = attr_mapping [item_label ]['attributes' ]
288
+
289
+ for attr in attributes :
290
+ if attr ['name' ] not in mapped_attributes :
291
+ continue
292
+
293
+ func_attr = [func_attr for func_attr in self .func_attributes .get (item_label , []) if func_attr ['name' ] == attr ["name" ]]
294
+ # Skip current attribute if it was not declared as supported in function config
295
+ if not func_attr :
296
+ continue
297
+
298
+ db_attr = supported_label .get (attr ["name" ])
299
+
300
+ if check_attr_value (attr ["value" ], func_attr [0 ], db_attr ):
301
+ attr ["name" ] = mapped_attributes [attr ['name' ]]
302
+ item ["attributes" ].append (attr )
303
+
304
+ item ['label' ] = mapping [item ['label' ]]
305
+ response_filtered .append (item )
284
306
285
307
return response_filtered
286
308
0 commit comments