nexusLIMS.harvesters.nemo.utils#
Various utility functions used by the NEMO harvester.
Module Contents#
Functions#
Return a list of enabled connectors based off the environment. |
|
Add all usage events to database for enabled NEMO connectors. |
|
Get all usage events for enabled NEMO connectors as Sessions. |
|
Get the appropriate NEMO connector for a given Session. |
|
Get an enabled NemoConnector by inspecting the |
|
Process sample information from reservation questions. |
|
Check if usage event has valid question data in specified field. |
|
Get the value of the id query parameter stored in URL string. |
API#
- nexusLIMS.harvesters.nemo.utils.get_harvesters_enabled() List[NemoConnector][source]#
Return a list of enabled connectors based off the environment.
- Returns:
harvesters_enabled – A list of NemoConnector objects representing the NEMO APIs enabled via environment settings
- Return type:
List[NemoConnector]
- nexusLIMS.harvesters.nemo.utils.add_all_usage_events_to_db(user: Union[str, int] | None = None, dt_from: datetime | None = None, dt_to: datetime | None = None, tool_id: Union[int, List[int]] | None = None)[source]#
Add all usage events to database for enabled NEMO connectors.
Loop through enabled NEMO connectors and add each one’s usage events to the NexusLIMS
session_logdatabase table (if required).- Parameters:
user – The user(s) for which to add usage events. If
None, events will not be filtered by user at alldt_from – The point in time after which usage events will be added. If
None, no date filtering will be performeddt_to – The point in time before which usage events will be added. If
None, no date filtering will be performedtool_id – The tools(s) for which to add usage events. If
'None'(default), the tool IDs for each instrument in the NexusLIMS DB will be extracted and used to limit the API response
- nexusLIMS.harvesters.nemo.utils.get_usage_events_as_sessions(user: Union[str, int] | None = None, dt_from: datetime | None = None, dt_to: datetime | None = None, tool_id: Union[int, List[int]] | None = None) List[Session][source]#
Get all usage events for enabled NEMO connectors as Sessions.
Loop through enabled NEMO connectors and return each one’s usage events to as
Sessionobjects without writing logs to thesession_logtable. Mostly used for doing dry runs of the record builder.- Parameters:
user – The user(s) for which to fetch usage events. If
None, events will not be filtered by user at alldt_from – The point in time after which usage events will be fetched. If
None, no date filtering will be performeddt_to – The point in time before which usage events will be fetched. If
None, no date filtering will be performedtool_id – The tools(s) for which to fetch usage events. If
None, events will only be filtered by tools known in the NexusLIMS DB for each connector
- nexusLIMS.harvesters.nemo.utils.get_connector_for_session(session: Session) NemoConnector[source]#
Get the appropriate NEMO connector for a given Session.
Given a
Session, find the matchingNemoConnectorfrom the enabled list of NEMO harvesters.- Parameters:
session – The session for which a NemoConnector is needed
- Returns:
n – The connector object that allows for querying the NEMO API for the instrument contained in
session- Return type:
- Raises:
LookupError – Raised if a matching connector is not found
- nexusLIMS.harvesters.nemo.utils.get_connector_by_base_url(base_url: str) NemoConnector[source]#
Get an enabled NemoConnector by inspecting the
base_url.- Parameters:
base_url – A portion of the API url to search for
- Returns:
n – The enabled NemoConnector instance
- Return type:
- Raises:
LookupError – Raised if a matching connector is not found
- nexusLIMS.harvesters.nemo.utils.process_res_question_samples(res_dict: Dict) Tuple[List[str | None] | None, List[str | None] | None, List[str | None] | None, List[str | None] | None][source]#
Process sample information from reservation questions.
- Parameters:
res_dict – The reservation dictionary (i.e. the response from the
reservationsapi endpoint)
- nexusLIMS.harvesters.nemo.utils.has_valid_question_data(event_dict: Dict, field: str = 'run_data') bool[source]#
Check if usage event has valid question data in specified field.
Works for both run_data and pre_run_data fields, which use identical structure.
A usage event has valid question data if:
It has the specified field
Field value is not None or empty string
Field value can be parsed as JSON
Parsed data is not empty
Parsed data has data_consent field (required)
- Parameters:
event_dict – The usage event dictionary from NEMO API
field – Field name to check (“run_data” or “pre_run_data”)
- Returns:
True if usage event has valid question data in the specified field, False otherwise
- Return type:
- nexusLIMS.harvesters.nemo.utils.id_from_url(url: str) int | None[source]#
Get the value of the id query parameter stored in URL string.
This is used to extract the value as needed from API strings.
- Parameters:
url – The URL to parse, such as
https://nemo.example.com/api/usage_events/?id=9- Returns:
this_id – The id value if one is present, otherwise
None- Return type:
None or int