From 75b57bd28f0795b2f85cff19b1a8ed33cf3cc7a2 Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Sun, 31 Mar 2024 12:24:49 +0200 Subject: [PATCH] updated function to get visual communication --- .../utils/get_visual_communication.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) mode change 100644 => 100755 core/database/utils/get_visual_communication.py diff --git a/core/database/utils/get_visual_communication.py b/core/database/utils/get_visual_communication.py old mode 100644 new mode 100755 index 0add874..9b0b043 --- a/core/database/utils/get_visual_communication.py +++ b/core/database/utils/get_visual_communication.py @@ -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