-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview_parser.py
More file actions
35 lines (25 loc) · 1.24 KB
/
preview_parser.py
File metadata and controls
35 lines (25 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import re
def parse_duration_to_seconds(duration_text):
"""Convert a preview duration string into a total number of seconds."""
parts = [int(part) for part in duration_text.split(':')]
if len(parts) == 3:
hours, minutes, seconds = parts
return (hours * 3600) + (minutes * 60) + seconds
if len(parts) == 2:
minutes, seconds = parts
return (minutes * 60) + seconds
if len(parts) == 1:
return parts[0]
raise ValueError(f'Unsupported duration format: {duration_text}')
def parse_preview_output(preview_output):
"""Extract timing and distance metrics from AxiDraw preview console output."""
duration_match = re.search(r'Estimated print time:\s*([0-9:]+)', preview_output)
path_match = re.search(r'Length of path to draw:\s*([0-9]+(?:\.[0-9]+)?)\s*m', preview_output)
travel_match = re.search(r'Pen-up travel distance:\s*([0-9]+(?:\.[0-9]+)?)\s*m', preview_output)
if not duration_match or not path_match or not travel_match:
raise ValueError('Could not parse preview output')
return {
'plot_duration': parse_duration_to_seconds(duration_match.group(1)),
'plot_path': float(path_match.group(1)),
'plot_travel': float(travel_match.group(1)),
}