Skip to content

Commit 4c32f06

Browse files
committed
setup cli
1 parent c56bbdf commit 4c32f06

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies = [
2222
"pygments",
2323
"plotly",
2424
"holoviews",
25+
"kaleido",
2526
]
2627
dynamic = ["version"]
2728

waveform_editor/cli.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from rich.table import Table
77

88
import waveform_editor
9+
from waveform_editor.waveform_exporter import WaveformExporter
10+
from waveform_editor.yaml_parser import YamlParser
911

1012
logger = logging.getLogger(__name__)
1113

@@ -52,5 +54,52 @@ def print_version():
5254
console.Console().print(grid)
5355

5456

57+
@cli.command("export-csv")
58+
@click.argument("yaml", type=click.Path(exists=True))
59+
@click.argument("output", type=str)
60+
def export_csv(yaml, output):
61+
"""Export waveform data to a CSV file."""
62+
waveform = load_waveform_from_yaml(yaml)
63+
exporter = WaveformExporter(waveform)
64+
exporter.to_csv(output)
65+
66+
67+
@cli.command("export-png")
68+
@click.argument("yaml", type=click.Path(exists=True))
69+
@click.argument("output", type=str)
70+
def export_png(yaml, output):
71+
"""Export waveform data to a CSV file."""
72+
waveform = load_waveform_from_yaml(yaml)
73+
exporter = WaveformExporter(waveform)
74+
exporter.to_png(output)
75+
76+
77+
# # TODO:
78+
# @cli.command("export-ids")
79+
# @click.argument("yaml", type=str)
80+
# @click.argument("uri", type=str)
81+
# @click.option("--dd-version", type=str)
82+
# def export_ids(yaml, uri, path):
83+
# """Export waveform data to an IDS."""
84+
# # waveform = load_waveform_from_yaml(yaml)
85+
# # exporter = WaveformExporter(waveform)
86+
# # exporter.to_ids(uri, path)
87+
88+
89+
def load_waveform_from_yaml(yaml_file):
90+
with open(yaml_file) as file:
91+
yaml_str = file.read()
92+
yaml_parser = YamlParser()
93+
yaml_parser.parse_waveforms(yaml_str)
94+
annotations = yaml_parser.waveform.annotations
95+
if annotations:
96+
click.secho(
97+
"The following errors and warnings were detected in the YAML file:\n"
98+
f"{annotations}",
99+
fg="red",
100+
)
101+
return yaml_parser.waveform
102+
103+
55104
if __name__ == "__main__":
56105
cli()

waveform_editor/waveform.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ def calc_length(self):
129129
"""Returns the length of the waveform."""
130130
return self.tendencies[-1].end - self.tendencies[0].start
131131

132+
def get_start(self):
133+
"""Returns the start time of the first tendency in the waveform."""
134+
return self.tendencies[0].start
135+
136+
def get_end(self):
137+
"""Returns the end time of the last tendency in the waveform."""
138+
return self.tendencies[-1].end
139+
132140
def _process_waveform(self, waveform):
133141
"""Processes the waveform YAML and populates the tendencies list.
134142

waveform_editor/waveform_exporter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def __init__(self, waveform, times=None):
2828
self.time_label = "Time [s]"
2929
self.value_label = "Value [unit]"
3030

31-
def to_ids(self, uri, path):
32-
# TODO:
33-
pass
31+
# # TODO: implement export to XML format
32+
# def to_ids(self, uri):
33+
# pass
3434

3535
def to_csv(self, file_path):
3636
with open(file_path, mode="w", newline="") as file:
@@ -53,3 +53,7 @@ def to_png(self, file_path):
5353
yaxis_title=self.value_label,
5454
)
5555
fig.write_image(file_path, format="png")
56+
57+
# TODO: implement export to XML format
58+
# def to_pcssp(self, file_path)
59+
# pass

0 commit comments

Comments
 (0)