updated function to get visual communication
This commit is contained in:
Regular → Executable
+15
-12
@@ -1,3 +1,4 @@
|
|||||||
|
"""Definition of function to get visual communication from database."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -18,19 +19,21 @@ def get_visual_communication(
|
|||||||
query['annotation'] = {'$ne': None}
|
query['annotation'] = {'$ne': None}
|
||||||
else:
|
else:
|
||||||
query['annotation'] = {'$eq': None}
|
query['annotation'] = {'$eq': None}
|
||||||
data = collection.aggregate([
|
data = collection.aggregate(
|
||||||
{
|
pipeline=[
|
||||||
'$match': query, # find using filters
|
{
|
||||||
},
|
'$match': query, # find using filters
|
||||||
{
|
|
||||||
'$sample': {
|
|
||||||
'size': 1, # get one random
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
])
|
'$sample': {
|
||||||
|
'size': 1, # get one random
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
data_list = list(data) # read data from cursor object
|
data_list = list(data) # read data from cursor object
|
||||||
if len(data_list) == 0:
|
if len(data_list) == 0:
|
||||||
logging.error('failed getting visual communication')
|
|
||||||
raise NoDocumentFoundException()
|
raise NoDocumentFoundException()
|
||||||
logging.info('finished')
|
vis_com = VisualCommunication.model_validate(data_list[0])
|
||||||
return VisualCommunication.model_validate(data_list[0])
|
logging.debug('finished')
|
||||||
|
return vis_com
|
||||||
|
|||||||
Reference in New Issue
Block a user