Skip to content

Commit

Permalink
Merge pull request #89 from stuartcampbell/detector-granularity
Browse files Browse the repository at this point in the history
Add detector directory granularity
  • Loading branch information
nmaytan authored May 23, 2024
2 parents 0aba0a4 + e047d5c commit 9277d1d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
15 changes: 0 additions & 15 deletions src/nsls2api/api/models/beamline_model.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/nsls2api/api/models/proposal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pydantic

from nsls2api.models.proposals import Proposal, User
from nsls2api.api.models.beamline_model import AssetDirectoryGranularity
from nsls2api.models.beamlines import AssetDirectoryGranularity


class UsernamesList(pydantic.BaseModel):
Expand Down Expand Up @@ -69,7 +69,7 @@ class ProposalDirectories(pydantic.BaseModel):
cycle: str | None = None
users: list[dict[str, str]]
groups: list[dict[str, str]]
directory_most_granular_level: AssetDirectoryGranularity | None = None
directory_most_granular_level: AssetDirectoryGranularity | None = AssetDirectoryGranularity.day

model_config = {
"json_schema_extra": {
Expand Down
21 changes: 20 additions & 1 deletion src/nsls2api/models/beamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@
import beanie
import pydantic

from enum import StrEnum


class AssetDirectoryGranularity(StrEnum):
"""
Represents the granularity options for asset directory YYYY/MM/DD/HH tree structure.
The value specifies the most granular level to create directories for. If no date
structure is wanted then the value "flat" is used.
"""

flat = "flat"
year = "year"
month = "month"
day = "day"
hour = "hour"


class Detector(pydantic.BaseModel):
name: str
directory_name: str | None = None
directory_name: str
granularity: AssetDirectoryGranularity | None = AssetDirectoryGranularity.day
description: str | None = None
manufacturer: str | None = None


class DetectorView(pydantic.BaseModel):
Expand Down
7 changes: 4 additions & 3 deletions src/nsls2api/services/beamline_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from beanie.odm.operators.find.comparison import In
from beanie.odm.operators.find.array import ElemMatch

from nsls2api.api.models.beamline_model import AssetDirectoryGranularity
from nsls2api.models.beamlines import AssetDirectoryGranularity
from nsls2api.infrastructure.logging import logger
from nsls2api.models.beamlines import (
Beamline,
Expand Down Expand Up @@ -146,7 +146,7 @@ async def operator_username(name: str) -> str:

if operator_account is None:
raise LookupError(
f"Could not find a the operattor account for the {name} beamline."
f"Could not find a the operator account for the {name} beamline."
)

return operator_account.username
Expand Down Expand Up @@ -228,6 +228,7 @@ async def proposal_directory_skeleton(name: str):
"users": users_acl,
"groups": groups_acl,
"beamline": name.upper(),
"directory_most_granular_level": AssetDirectoryGranularity.flat,
}
directory_list.append(asset_directory)

Expand All @@ -241,7 +242,7 @@ async def proposal_directory_skeleton(name: str):
"users": users_acl,
"groups": groups_acl,
"beamline": name.upper(),
"directory_most_granular_level": AssetDirectoryGranularity.day,
"directory_most_granular_level": detector.granularity,
}
directory_list.append(directory)

Expand Down

0 comments on commit 9277d1d

Please sign in to comment.