From 78198c1152fe3897d4a6736699add7d35835801d Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <alexander@mail-schlemmer.de> Date: Thu, 28 Oct 2021 15:12:24 +0200 Subject: [PATCH] WIP: created draft for generic analysis method --- .../serverside/generic_analysis.py | 58 +++++++++++++++++++ src/caosadvancedtools/serverside/model.yml | 15 +++++ src/caosadvancedtools/serverside/sync.py | 7 +++ 3 files changed, 80 insertions(+) create mode 100644 src/caosadvancedtools/serverside/generic_analysis.py create mode 100644 src/caosadvancedtools/serverside/model.yml create mode 100755 src/caosadvancedtools/serverside/sync.py diff --git a/src/caosadvancedtools/serverside/generic_analysis.py b/src/caosadvancedtools/serverside/generic_analysis.py new file mode 100644 index 00000000..8b02326e --- /dev/null +++ b/src/caosadvancedtools/serverside/generic_analysis.py @@ -0,0 +1,58 @@ +# encoding: utf-8 +# +# Copyright (C) 2021 Alexander Schlemmer <alexander.schlemmer@ds.mpg.de> +# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021 Henrik tom Wörden <h.tomwoerden@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# +# See: https://gitlab.indiscale.com/caosdb/src/caosdb-advanced-user-tools/-/issues/55 + +# This source file is work in progress and currently untested. + +import importlib +import argparse +import caosdb as db + +def _parse_arguments(): + """Parses the command line arguments. + """ + parser = argparse.ArgumentParser(description='__doc__') + parser.add_argument("--entity", help="An id an input dataset.") + parser.add_argument("--entity", help="An id of a parameter record.") + parser.add_argument( + '-a', '--auth-token', required=False, + help="An authentication token (not needed, only for compatibility).") + + return parser.parse_args() + + +def run(plugin: str): + """ + Generically run a data analysis script. + This script should be installed as a pip package. + It should be located in package plugin and implement at least + a main function that takes a DataAnalysisRecord as a single argument. + """ + m = importlib.import_module(plugin) + args = _parse_arguments() + input_dataset = db.Record(id=args.entity) + parameters = db.Record(id=args.parameter) + + dataAnalysisRecord = db.Record() + dataAnalysisRecord.add_property(input_dataset) + dataAnalysisRecord.add_property(parameters) + + m.main(dataAnalysisRecord) diff --git a/src/caosadvancedtools/serverside/model.yml b/src/caosadvancedtools/serverside/model.yml new file mode 100644 index 00000000..2f5a9634 --- /dev/null +++ b/src/caosadvancedtools/serverside/model.yml @@ -0,0 +1,15 @@ +# Parent of all datasets which are used as input to or output from +# analysis scripts +Dataset: + +# Parent of all parametersets which are used as input for analysis scripts +ParameterSet: + +DataAnalysis: + recommended_properties: + InputDataset: + datatype: Dataset + OutputDataset: + datatype: Dataset + ParameterSet: + date: \ No newline at end of file diff --git a/src/caosadvancedtools/serverside/sync.py b/src/caosadvancedtools/serverside/sync.py new file mode 100755 index 00000000..04283a15 --- /dev/null +++ b/src/caosadvancedtools/serverside/sync.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +# Sync data model for generic data analysis method +# A. Schlemmer, 09/2021 + +from caosadvancedtools.models import parser +model = parser.parse_model_from_yaml("model.yml") +model.sync_data_model() -- GitLab