Skip to content

Commit

Permalink
Added metadata to the investigations
Browse files Browse the repository at this point in the history
  • Loading branch information
antolinos committed Feb 21, 2025
1 parent 0f6a55a commit e543119
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 25 additions & 7 deletions mxcubecore/HardwareObjects/ICATLIMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,16 @@ def _get_user_portal_url(self, investigation):
except Exception:
return ""

def __get_investigation_parameter_by_name(
self, investigation: dict, parameter_name: str
) -> str:
"""
Gets the metadata of the parameters in an investigation
Returns the value of the specified parameter if it exists,
otherwise returns an empty string.
"""
return investigation.get("parameters", {}).get(parameter_name, None)

def __to_session(self, investigation) -> Session:
"""This methods converts a ICAT investigation into a session"""

Expand All @@ -432,6 +442,9 @@ def __to_session(self, investigation) -> Session:
if "__actualEndDate" in investigation["parameters"]
else investigation.get("endDate", None)
)

instrument_name = investigation["instrument"]["name"]

# If session has been rescheduled new date is overwritten
return Session(
code=investigation["type"]["name"],
Expand All @@ -440,7 +453,7 @@ def __to_session(self, investigation) -> Session:
session_id=investigation["id"],
proposal_id=investigation["id"],
proposal_name=investigation["name"],
beamline_name=investigation["instrument"]["name"],
beamline_name=instrument_name,
comments="",
start_datetime=investigation.get(
"startDate", None
Expand All @@ -457,19 +470,24 @@ def __to_session(self, investigation) -> Session:
actual_end_date=self._string_to_date(actual_end_date),
actual_end_time=self._string_to_time(actual_end_date),
nb_shifts=3,
scheduled=self.is_scheduled_on_host_beamline(
investigation["instrument"]["name"]
),
scheduled=self.is_scheduled_on_host_beamline(instrument_name),
is_scheduled_time=self.is_scheduled_now(actual_start_date, actual_end_date),
is_scheduled_beamline=self.is_scheduled_on_host_beamline(
investigation["instrument"]["name"]
),
is_scheduled_beamline=self.is_scheduled_on_host_beamline(instrument_name),
data_portal_URL=self._get_data_portal_url(investigation),
user_portal_URL=self._get_user_portal_url(investigation),
logbook_URL=self._get_logbook_url(investigation),
is_rescheduled=(
True if "__actualEndDate" in investigation["parameters"] else False
),
volume=self.__get_investigation_parameter_by_name(
investigation, "__volume"
),
sample_count=self.__get_investigation_parameter_by_name(
investigation, "__sampleCount"
),
dataset_count=self.__get_investigation_parameter_by_name(
investigation, "__datasetCount"
),
)

def get_full_user_name(self):
Expand Down
4 changes: 4 additions & 0 deletions mxcubecore/model/lims_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Session(BaseModel):
data_portal_URL: Optional[str] = None
logbook_URL: Optional[str] = None

volume: Optional[str] = None
dataset_count: Optional[str] = None
sample_count: Optional[str] = None


class LimsUser(BaseModel):
user_name: str = ""
Expand Down

0 comments on commit e543119

Please sign in to comment.