Skip to content

Commit 6ecf4a3

Browse files
committed
[sets] reworked output options
1 parent 6eb93f9 commit 6ecf4a3

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/instrumentman/setmeasurement/__init__.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
constraint,
88
Choice,
99
IntRange,
10-
file_path,
11-
dir_path
10+
file_path
1211
)
1312
from cloup.constraints import all_or_none
1413

@@ -32,20 +31,25 @@
3231
help="JSON file containing target definitions"
3332
)
3433
@argument(
35-
"directory",
36-
type=dir_path(),
37-
help="Directory to save measurement output to"
34+
"output",
35+
type=str,
36+
help=(
37+
"Output file path or path template with placeholders "
38+
"('{date}', '{time}', '{order}', '{cycles}')"
39+
)
3840
)
3941
@com_option_group()
4042
@option(
41-
"-f",
42-
"--format",
43+
"--dateformat",
4344
type=str,
44-
default="setmeasurement_{time}.json",
45-
help=(
46-
"Session output file name format with placeholders "
47-
"(`{time}`: timestamp, `{order}`: order, `{cycle}`: cycles)"
48-
)
45+
default="%Y%m%d",
46+
help="Date format as accepted by strftime"
47+
)
48+
@option(
49+
"--timeformat",
50+
type=str,
51+
default="%H%M%S",
52+
help="Time format as accepted by strftime"
4953
)
5054
@option(
5155
"-c",

src/instrumentman/setmeasurement/measure.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from datetime import datetime
32
from logging import Logger, getLogger
43
from typing import Iterator, Literal
@@ -177,12 +176,13 @@ def measure_set(
177176
def main(
178177
port: str,
179178
targets: pathlib.Path,
180-
directory: pathlib.Path,
179+
output: str,
181180
baud: int = 9600,
182181
timeout: int = 15,
183182
retry: int = 1,
184183
sync_after_timeout: bool = False,
185-
format: str = "setmeasurement_{time}.json",
184+
dateformat: str = "%Y%m%d",
185+
timeformat: str = "%H%M%S",
186186
cycles: int = 1,
187187
order: Literal['AaBb', 'AabB', 'ABab', 'ABba', 'ABCD'] = "ABba",
188188
sync_time: bool = True,
@@ -211,10 +211,14 @@ def main(
211211
points
212212
)
213213

214-
timestamp = session.cycles[0].time.strftime("%Y%m%d_%H%M%S")
215-
filename = os.path.join(
216-
directory,
217-
format.format(time=timestamp, order=order, cycle=cycles)
214+
epoch = session.cycles[0].time
215+
date = epoch.strftime(dateformat)
216+
time = epoch.strftime(timeformat)
217+
filename = output.format(
218+
date=date,
219+
time=time,
220+
order=order,
221+
cycles=cycles
218222
)
219223
session.export_to_json(filename)
220224
logger.info(f"Saved measurement results to '{filename}'")

0 commit comments

Comments
 (0)