SudLogTask reuses ServerLogTask's sample format but only records while
a Sud run is active: starts on Play (fresh start only, not a Pause
resume) and writes logs/log_{date_time}_{sud_name}.log on Stop or
natural completion.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TvgC7oy9MxaA4ZQxXqkNdS
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import time
|
|
from tasks.server_log import ServerLogTask
|
|
from components import APid, AHeater
|
|
|
|
|
|
def _safe_filename_part(text):
|
|
return "".join(c if c.isalnum() or c in "-_" else "_" for c in text) or "Sud"
|
|
|
|
|
|
class SudLogTask(ServerLogTask):
|
|
"""Records temp/power samples for a single Sud run - same sample format
|
|
as ServerLogTask, but only while a run is active: recording starts on
|
|
Play and is written out on Stop (or natural completion), to
|
|
logs/log_{date_time}_{sud_name}.log. A Pause/resume doesn't start a new
|
|
file - only a fresh Play (from IDLE/DONE) does."""
|
|
|
|
def __init__(self, tc: APid, heater: AHeater, heater_task, sud, interval, path='./logs', config=None, dt=None):
|
|
ServerLogTask.__init__(self, tc, heater, heater_task, interval, path, config, dt)
|
|
self.sud = sud
|
|
self._active = False
|
|
|
|
def _should_sample(self):
|
|
return self._active
|
|
|
|
def _filename(self):
|
|
name_part = _safe_filename_part(self.sud.name or 'Sud')
|
|
return 'log_{}_{}.log'.format(self._run_id, name_part)
|
|
|
|
def start_run(self):
|
|
if self._active:
|
|
return
|
|
self._samples = []
|
|
self._t0 = time.monotonic()
|
|
self._run_id = time.strftime("%Y%m%dT%H%M%S", time.localtime())
|
|
self._active = True
|
|
|
|
def stop_run(self):
|
|
if not self._active:
|
|
return
|
|
self._active = False
|
|
self.write()
|
|
self._param_events = []
|