Skip to content

Commit 3afe331

Browse files
esmith1729github-actionsPasarus
authored
Changing FIA-API vesuvio script to allow summing multiple runs (#596)
* Changing FIA-API vesuvio script to allow summing multiple runs * Formatting and linting commit * adding type ignore so that mypy doesn't get confused * Formatting and linting commit * test cases for vesuvio summing of runs * add back in removed comments * fix for runno_str input --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Samuel Jones <samjones714@gmail.com>
1 parent 55818c9 commit 3afe331

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

fia_api/scripts/transforms/vesuvio_transform.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,28 @@ def apply(self, script: PreScript, job: Job) -> None: # type: ignore
2727
lines = script.value.splitlines()
2828
# MyPY does not believe ColumnElement[JSONB] is indexable, despite JSONB implementing the Indexable mixin
2929
# If you get here in the future, try removing the type ignore and see if it passes with newer mypy
30+
31+
runno = job.inputs["runno"] # type: ignore
32+
if isinstance(runno, list):
33+
if len(runno) > 1:
34+
# Convert list to range string if contiguous, otherwise comma-separated
35+
if all(runno[i] == runno[i - 1] + 1 for i in range(1, len(runno))):
36+
runno_str = f"{runno[0]}-{runno[-1]}"
37+
else:
38+
runno_str = ",".join(map(str, runno))
39+
else:
40+
runno_str = str(runno[0])
41+
else:
42+
runno_str = str(runno)
43+
3044
for index, line in enumerate(lines):
3145
if self._replace_input(line, lines, index, "ip", f'"{job.inputs["ip_file"]}"'):
3246
continue
3347
if self._replace_input(
3448
line, lines, index, "diff_ip", f'"{job.inputs.get("diff_ip_file", job.inputs["ip_file"])}"'
3549
):
3650
continue
37-
if self._replace_input(line, lines, index, "runno", f'"{job.inputs["runno"]}"'):
51+
if self._replace_input(line, lines, index, "runno", f'"{runno_str}"'): # type: ignore
3852
continue
3953
if self._replace_input(line, lines, index, "empty_runs", f'"{job.inputs["empty_runs"]}"'):
4054
continue

test/scripts/transforms/test_vesuvio_transforms.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,42 @@ def test_vesuvio_transform_apply(script, reduction):
6969
assert line == 'diff_ip_file = "IP0001.par"'
7070
else:
7171
assert line == original_lines[index]
72+
73+
74+
def test_vesuvio_transform_multi_contiguous(script, reduction):
75+
"""
76+
Test vesuvio transform with contiguous runs
77+
"""
78+
transform = VesuvioTransform()
79+
reduction.inputs["runno"] = [55956, 55957, 55958]
80+
transform.apply(script, reduction)
81+
updated_lines = script.value.splitlines()
82+
for line in updated_lines:
83+
if line.startswith("runno"):
84+
assert line == 'runno = "55956-55958"'
85+
86+
87+
def test_vesuvio_transform_multi_non_contiguous(script, reduction):
88+
"""
89+
Test vesuvio transform with non-contiguous runs
90+
"""
91+
transform = VesuvioTransform()
92+
reduction.inputs["runno"] = [55956, 55958, 55960]
93+
transform.apply(script, reduction)
94+
updated_lines = script.value.splitlines()
95+
for line in updated_lines:
96+
if line.startswith("runno"):
97+
assert line == 'runno = "55956,55958,55960"'
98+
99+
100+
def test_vesuvio_transform_single_list(script, reduction):
101+
"""
102+
Test vesuvio transform with a single run in a list
103+
"""
104+
transform = VesuvioTransform()
105+
reduction.inputs["runno"] = [55956]
106+
transform.apply(script, reduction)
107+
updated_lines = script.value.splitlines()
108+
for line in updated_lines:
109+
if line.startswith("runno"):
110+
assert line == 'runno = "55956"'

0 commit comments

Comments
 (0)