From 6e1db6b5cc4002e0a0f4976c08e5faaed9115871 Mon Sep 17 00:00:00 2001 From: Killian <74175986+killianrochet@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:42:31 +0100 Subject: [PATCH] First version of the multiplate export / download of experiments. Goal is to allow users download multiples experiments (inside a project). Useful for experiment / metadata export --- elab_bridge/server_interface.py | 16 ++++++++++++++++ elab_bridge/tests/test_server_interface.py | 21 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/elab_bridge/server_interface.py b/elab_bridge/server_interface.py index eb56c0a..21a5c6c 100644 --- a/elab_bridge/server_interface.py +++ b/elab_bridge/server_interface.py @@ -4,6 +4,22 @@ import pandas as pd +def extended_download(server_config_json, experiment_tags): + api_client = get_elab_config(server_config_json) + experiment_api = elabapi_python.ExperimentsApi(api_client) + + response = experiment_api.read_experiments_with_http_info(tags=experiment_tags) + + experiments = response[0] + + experiment_ids = [] + + for experiment in experiments: + experiment_ids.append(experiment.id) + + return experiment_ids + + def download_experiment(save_to, server_config_json, experiment_id, format='json', experiment_axis='columns'): """ Download an individual experiment. diff --git a/elab_bridge/tests/test_server_interface.py b/elab_bridge/tests/test_server_interface.py index 50726de..647dd91 100644 --- a/elab_bridge/tests/test_server_interface.py +++ b/elab_bridge/tests/test_server_interface.py @@ -1,6 +1,6 @@ from diglab_utils.test_utils import (test_directory, initialize_test_dir) from elab_bridge.server_interface import (download_experiment, upload_template, upload_experiment, - delete_template, delete_experiment) + delete_template, delete_experiment, extended_download) SERVER_CONFIG_YAML = (test_directory / 'testfiles_elab' / 'TestProject' / 'project.json').resolve() @@ -52,3 +52,22 @@ def test_download_experiment(initialize_test_dir): # cleanup delete_experiment(server_config_json=SERVER_CONFIG_YAML, experiment_id=experiment_id) json_file.unlink() + + +def test_extended_download(initialize_test_dir): + json_file = test_directory / 'testfiles_elab' / 'downloaded_experiment.json' + + experiments_ids = extended_download(server_config_json=SERVER_CONFIG_YAML, experiment_tags=['BIDS']) + print(experiments_ids) + + for experiment_id in experiments_ids: + + experiment = download_experiment(save_to=json_file, + server_config_json=SERVER_CONFIG_YAML, + experiment_id=experiment_id, + format='json') + assert json_file.exists() + assert 'extra_fields' in experiment + + # cleanup + json_file.unlink()