Skip to content

Commit 26771bf

Browse files
committed
Added logic to 'suggest_path' API endpoint to check for the current visit under the previous year in the event the year rolls over during a data collection session
1 parent 208f4fb commit 26771bf

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/murfey/server/api/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,31 @@ def suggest_path(
12851285
raise ValueError(
12861286
"No machine configuration set when suggesting destination path"
12871287
)
1288+
1289+
# Construct the full path to where the dataset is to be saved
12881290
check_path = machine_config.rsync_basepath / base_path
1291+
1292+
# Check previous year to account for the year rolling over during data collection
1293+
if not check_path.exists():
1294+
base_path_parts = base_path.split("/")
1295+
for part in base_path_parts:
1296+
# Find the path part corresponding to the year
1297+
if len(part) == 4 and part.isdigit():
1298+
year_idx = base_path_parts.index(part)
1299+
base_path_parts[year_idx] = str(int(part) - 1)
1300+
base_path = "/".join(base_path_parts)
1301+
check_path_prev = check_path
1302+
check_path = machine_config.rsync_basepath / base_path
1303+
1304+
# If it's not in the previous year either, it's a genuine error
1305+
if not check_path.exists():
1306+
log_message = (
1307+
"Unable to find current visit folder under "
1308+
f"{str(check_path_prev)!r} or {str(check_path)!r}"
1309+
)
1310+
log.error(log_message)
1311+
raise FileNotFoundError(log_message)
1312+
12891313
check_path_name = check_path.name
12901314
while check_path.exists():
12911315
count = count + 1 if count else 2

src/murfey/server/demo_api.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,33 @@ def suggest_path(
12961296
else Path(f"/dls/{get_microscope()}") / params.base_path
12971297
)
12981298
check_path = check_path.parent / f"{check_path.stem}{count}{check_path.suffix}"
1299+
1300+
# Check previous year to account for the year rolling over during data collection
1301+
if not sanitise_path(check_path).exists():
1302+
base_path_parts = list(params.base_path.parts)
1303+
for part in base_path_parts:
1304+
# Find the path part corresponding to the year
1305+
if len(part) == 4 and part.isdigit():
1306+
year_idx = base_path_parts.index(part)
1307+
base_path_parts[year_idx] = str(int(part) - 1)
1308+
base_path = "/".join(base_path_parts)
1309+
check_path_prev = check_path
1310+
check_path = (
1311+
machine_config[instrument_name].rsync_basepath / base_path
1312+
if machine_config
1313+
else Path(f"/dls/{get_microscope()}") / base_path
1314+
)
1315+
check_path = check_path.parent / f"{check_path.stem}{count}{check_path.suffix}"
1316+
1317+
# If visit is not in the previous year either, it's a genuine error
1318+
if not check_path.exists():
1319+
log_message = (
1320+
"Unable to find current visit folder under "
1321+
f"{str(check_path_prev)!r} or {str(check_path)!r}"
1322+
)
1323+
log.error(log_message)
1324+
raise FileNotFoundError(log_message)
1325+
12991326
check_path_name = check_path.name
13001327
while sanitise_path(check_path).exists():
13011328
count = count + 1 if count else 2

0 commit comments

Comments
 (0)