This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#1017) Move common parts out of store in ispyb and rename
- Loading branch information
1 parent
442ceb6
commit 0173446
Showing
16 changed files
with
114 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import datetime | ||
import os | ||
import re | ||
|
||
from ispyb import NoResult | ||
from ispyb.connector.mysqlsp.main import ISPyBMySQLSPConnector as Connector | ||
from ispyb.sp.core import Core | ||
|
||
from hyperion.parameters.constants import ( | ||
SIM_ISPYB_CONFIG, | ||
) | ||
|
||
VISIT_PATH_REGEX = r".+/([a-zA-Z]{2}\d{4,5}-\d{1,3})(/?$)" | ||
|
||
|
||
def get_current_time_string(): | ||
now = datetime.datetime.now() | ||
return now.strftime("%Y-%m-%d %H:%M:%S") | ||
|
||
|
||
def get_ispyb_config(): | ||
return os.environ.get("ISPYB_CONFIG_PATH", SIM_ISPYB_CONFIG) | ||
|
||
|
||
def get_visit_string_from_path(path) -> str | None: | ||
match = re.search(VISIT_PATH_REGEX, path) if path else None | ||
return str(match.group(1)) if match else None | ||
|
||
|
||
def get_session_id_from_visit(conn: Connector, visit: str): | ||
try: | ||
core: Core = conn.core | ||
return core.retrieve_visit_id(visit) | ||
except NoResult: | ||
raise Exception(f"Not found - session ID for visit {visit}") | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import re | ||
|
||
import pytest | ||
|
||
from hyperion.external_interaction.ispyb.ispyb_utils import ( | ||
get_current_time_string, | ||
get_visit_string_from_path, | ||
) | ||
|
||
TIME_FORMAT_REGEX = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}" | ||
|
||
|
||
def test_get_current_time_string(): | ||
current_time = get_current_time_string() | ||
|
||
assert isinstance(current_time, str) | ||
assert re.match(TIME_FORMAT_REGEX, current_time) is not None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"visit_path, expected_match", | ||
[ | ||
("/dls/i03/data/2022/cm6477-45/", "cm6477-45"), | ||
("/dls/i03/data/2022/cm6477-45", "cm6477-45"), | ||
("/dls/i03/data/2022/mx54663-1/", "mx54663-1"), | ||
("/dls/i03/data/2022/mx54663-1", "mx54663-1"), | ||
("/dls/i03/data/2022/mx53-1/", None), | ||
("/dls/i03/data/2022/mx53-1", None), | ||
("/dls/i03/data/2022/mx5563-1565/", None), | ||
("/dls/i03/data/2022/mx5563-1565", None), | ||
], | ||
) | ||
def test_find_visit_in_visit_path(visit_path: str, expected_match: str): | ||
test_visit_path = get_visit_string_from_path(visit_path) | ||
assert test_visit_path == expected_match |
Oops, something went wrong.