Skip to content

Commit c2ebb1b

Browse files
authored
Merge pull request #28 from MrClock8163/feature/setmeasurement-update
Set measurement updates
2 parents 3445362 + 6307815 commit c2ebb1b

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ The project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1616
orientation
1717
- Added logging options to `iman` root command
1818
- Added logging to instrument connected commands
19+
- Added aliases to multiple commands and command groups
20+
- Added `dateformat` option to set measurement
21+
- Added `timeformat` option to set measurement
1922

2023
### Changed
2124

2225
- `geocompy` dependency minimum version was bumped to `v0.11.0`
26+
- Updated descriptions in command helps
2327
- Updated file listing to display results in a tree view
2428
- Reworked file listing to be able to run recursively to build full tree view
2529
- Protocol tests now display results in a table
@@ -30,6 +34,8 @@ The project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3034
option, instead of a comma separated string list
3135
- `chunk` option of file download now expects size in bytes, instead of
3236
encoded hex characters
37+
- Second argument (`output`) of set measurement now expects a file path or file
38+
path template instead of a directory
3339

3440
### Fixed
3541

@@ -41,6 +47,7 @@ The project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4147
### Removed
4248

4349
- Removed logging options from set measurement
50+
- Removed `format` option from set measurement
4451

4552
## v0.3.0 (2025-08-01)
4653

docs/commands/sets/measure.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,25 @@ Examples
5353
.. code-block:: shell
5454
:caption: Enabling connection retries and timeout recovery attempts (might be useful with bluetooth connections)
5555
56-
iman measure sets -r 3 --sync-after-timeout COM3 targets.json results
56+
iman measure set -r 3 --sync-after-timeout COM3 targets.json set.json
5757
5858
.. code-block:: shell
5959
:caption: Measuring to just a subset of the targets
6060
61-
iman measure sets -p P1 -p P2 -p P8 COM3 targets.json results
61+
iman measure set -p P1 -p P2 -p P8 COM3 targets.json set.json
6262
6363
.. code-block:: shell
6464
:caption: Measuring in face 1 only
6565
66-
iman measure sets -o ABCD COM3 targets.json results
66+
iman measure set -o ABCD COM3 targets.json set.json
67+
68+
.. code-block:: shell
69+
:caption: Saving results with file name template (useful for scheduled measurements)
70+
71+
iman measure set COM3 targets.json "set_{date}_{time}.json"
6772
6873
Usage
6974
-----
7075

7176
.. click:: instrumentman.setmeasurement:cli_measure
72-
:prog: iman measure sets
77+
:prog: iman measure set

src/instrumentman/setmeasurement/__init__.py

Lines changed: 24 additions & 16 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

@@ -22,7 +21,8 @@
2221
@extra_command(
2322
"sets",
2423
params=None,
25-
context_settings={"auto_envvar_prefix": None}
24+
context_settings={"auto_envvar_prefix": None},
25+
aliases=["set"]
2626
) # type: ignore[misc]
2727
@com_port_argument()
2828
@argument(
@@ -31,20 +31,25 @@
3131
help="JSON file containing target definitions"
3232
)
3333
@argument(
34-
"directory",
35-
type=dir_path(),
36-
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+
)
3740
)
3841
@com_option_group()
3942
@option(
40-
"-f",
41-
"--format",
43+
"--dateformat",
4244
type=str,
43-
default="setmeasurement_{time}.json",
44-
help=(
45-
"Session output file name format with placeholders "
46-
"(`{time}`: timestamp, `{order}`: order, `{cycle}`: cycles)"
47-
)
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"
4853
)
4954
@option(
5055
"-c",
@@ -99,7 +104,8 @@ def cli_measure(**kwargs: Any) -> None:
99104
@extra_command(
100105
"sets",
101106
params=None,
102-
context_settings={"auto_envvar_prefix": None}
107+
context_settings={"auto_envvar_prefix": None},
108+
aliases=["set"]
103109
) # type: ignore[misc]
104110
@argument(
105111
"output",
@@ -137,7 +143,8 @@ def cli_merge(**kwargs: Any) -> None:
137143
@extra_command(
138144
"sets",
139145
params=None,
140-
context_settings={"auto_envvar_prefix": None}
146+
context_settings={"auto_envvar_prefix": None},
147+
aliases=["set"]
141148
) # type: ignore[misc]
142149
@argument(
143150
"inputs",
@@ -172,7 +179,8 @@ def cli_validate(**kwargs: Any) -> None:
172179
@extra_command(
173180
"sets",
174181
params=None,
175-
context_settings={"auto_envvar_prefix": None}
182+
context_settings={"auto_envvar_prefix": None},
183+
aliases=["set"]
176184
) # type: ignore[misc]
177185
@argument(
178186
"input",

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)