From f0ac4b999dffbadff5d55bb2bd1dfc9207c2505d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Clau=C3=9F?= Date: Fri, 2 Jun 2023 09:21:23 +0200 Subject: [PATCH] add custom function to get config from machine --- src/paveit/datamodels/machines.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/paveit/datamodels/machines.py b/src/paveit/datamodels/machines.py index 0947f02..c9e26cd 100755 --- a/src/paveit/datamodels/machines.py +++ b/src/paveit/datamodels/machines.py @@ -9,9 +9,9 @@ from .components import ( ComponentsServoHydraulicMachineLVDT, ComponentsServoHydraulicMachineTemperatureControl, ) -from .enumeration import Labtest +from .enumeration import Labtest, LabtestsEnum from .usermanagement import Organisation - +from bson import ObjectId # ??? Labtest: Ist das richtig hier? class Experiment(EmbeddedDocument): @@ -57,6 +57,25 @@ class MachineBase(Document): data = mongo_to_dict(data) return data + + def get_config(self, org_id: ObjectId, testname: LabtestsEnum): + test_id = Labtest.objects(org_id=org_id, test=testname).first() + + if not test_id: + return [] + + test_id = test_id.id + + machine_data = self.objects(tests__test=test_id).only('tests').first() + + config_array = [] + for test in machine_data.tests: + if test.test.id == test_id: + config_array = test.config + + return config_array + +get_config_of_machine(ObjectId('6461eaea71b8a84558df5c58'), pdm.LabtestsEnum.CITTStiffness) meta = { 'allow_inheritance': True,