Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize dataset type for archiving #188

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions autobidsportal/datalad.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
from datalad.support.annexrepo import AnnexRepo
from flask import current_app

from autobidsportal.models import (
DataladDataset,
DatasetType,
Study,
db,
)
from autobidsportal.models import DataladDataset, DatasetType, Study, db


class RiaDataset:
Expand Down Expand Up @@ -46,29 +41,17 @@ def __exit__(self, exc_type, exc_value, traceback):
remove_finalized_dataset(self.path_dataset)


def get_alias(study_id, dataset_type):
def get_alias(study_id: int, dataset_type: DatasetType):
"""Generate an alias for a study in the RIA.

Parameters
----------
study_id : int
study_id
ID of the study.
dataset_type: DatasetType
dataset_type
"tar2bids" or "cfmm2tar".

Raises
------
TypeError
If dataset_type is not DatasetType
"""
if dataset_type is DatasetType.SOURCE_DATA:
text = "sourcedata"
elif dataset_type is DatasetType.RAW_DATA:
text = "rawdata"
elif dataset_type is DatasetType.DERIVED_DATA:
text = "deriveddata"
else:
raise TypeError
text = dataset_type.to_bids_str()
return f"study-{study_id}_{text}"


Expand Down
9 changes: 9 additions & 0 deletions autobidsportal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ class DatasetType(Enum):
RAW_DATA = 2
DERIVED_DATA = 3

def to_bids_str(self) -> str:
"""Produce a BIDS-style string for serialization."""
map_ = {
DatasetType.SOURCE_DATA: "sourcedata",
DatasetType.RAW_DATA: "rawdata",
DatasetType.DERIVED_DATA: "deriveddata",
}
return map_[self]


class DataladDataset(db.Model):
"""A datalad dataset relating to a study."""
Expand Down
1 change: 1 addition & 0 deletions autobidsportal/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ def list_globus_users():
[
{
"id": dataset.study_id,
"type": dataset.dataset_type.to_bids_str(),
"path": f"{path_base}/{dataset.ria_alias}",
"users": [
username.username
Expand Down
Loading