updated function to get visual communication

This commit is contained in:
Brian Bjarke Jensen
2024-03-31 12:24:49 +02:00
parent bb95e78132
commit 75b57bd28f
+15 -12
View File
@@ -1,3 +1,4 @@
"""Definition of function to get visual communication from database."""
from __future__ import annotations
import logging
@@ -18,19 +19,21 @@ def get_visual_communication(
query['annotation'] = {'$ne': None}
else:
query['annotation'] = {'$eq': None}
data = collection.aggregate([
{
'$match': query, # find using filters
},
{
'$sample': {
'size': 1, # get one random
data = collection.aggregate(
pipeline=[
{
'$match': query, # find using filters
},
},
])
{
'$sample': {
'size': 1, # get one random
},
},
],
)
data_list = list(data) # read data from cursor object
if len(data_list) == 0:
logging.error('failed getting visual communication')
raise NoDocumentFoundException()
logging.info('finished')
return VisualCommunication.model_validate(data_list[0])
vis_com = VisualCommunication.model_validate(data_list[0])
logging.debug('finished')
return vis_com