Claim dataset

ClaimDataset.py

from LOGS import LOGS
from LOGS.Entities import (
    DatasetRequestParameter,
    DatasetSortingOptions,
    ProjectRequestParameter,
)
from LOGS.Entity.EntitySortBy import SortDirection

# Connect to LOGS
logs = LOGS()

# For sake of simplicity in this example we use the newest unclaimed dataset
dataset = logs.datasets(
    DatasetRequestParameter(
        isClaimed=False,
        sortBy=[(DatasetSortingOptions.ENTERED_ON, SortDirection.DESC)],
    )
).first()

if not dataset:
    raise Exception("There are no unclaimed datasets in this LOGS instance")

# To claim a data you need to set the claimed property
dataset.claimed = True

# The state of a claimed dataset also implyes that a dataset is assigned to
# at least one project and a sample. The dataset also needs to have at least
# one operator.
# For the sake of simplicity in this example we use the first (with lowest logs-id)
# project and sample.
project = logs.projects().first()
if not project:
    raise Exception("There are no projects in this LOGS instance")

# We only set a project if no project is already assigned to this dataset
if not dataset.projects:
    dataset.projects = [logs.projects(ProjectRequestParameter()).first()]

# As owner we set the currently active user (this is defined by the API-key used)
dataset.owner = logs.currentUser

# We define the dataset as claimed
dataset.claimed = True

# The above modifications a still local. We can push them to the logs instance
# using the logs.update method.
logs.update(dataset)

dataset.printContent(hideNone=True)