feat: re-add per-run sud log alongside the continuous server log

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
This commit is contained in:
2026-07-01 09:06:39 +02:00
co-authored by Claude Sonnet 5
parent 0736f76ca3
commit 0b2a2be035
4 changed files with 81 additions and 18 deletions
+16 -6
View File
@@ -15,7 +15,7 @@ from components.plant import PlantFactory
from components.actor import StirrerFactory
from components.sud import Sud
from components.sud_forecast import SudForecastEstimator
from tasks import TaskManager, TempSensorTask, HeaterTask, PotTask, TcTask, StirrerTask, SudTask, ServerLogTask
from tasks import TaskManager, TempSensorTask, HeaterTask, PotTask, TcTask, StirrerTask, SudTask, ServerLogTask, SudLogTask
import argparse as ap
@@ -133,21 +133,31 @@ if __name__ == '__main__':
# Continuous server-session log - records from startup to shutdown
# regardless of Sud state; written to logs/log_{date_time}.json on exit.
server_log_task = ServerLogTask(tc, heater, heater_task, DT_TASK, args.logdir, config=config, dt=DT)
sud_task.set_on_plant_params(server_log_task.log_plant_params)
if startup_params is not None:
server_log_task.log_plant_params(0, startup_params)
taskmgr.add(server_log_task)
# Per-run log - only records while a Sud is actually playing; written to
# logs/log_{date_time}_{sud_name}.log on Stop (or natural completion).
sud_log_task = SudLogTask(tc, heater, heater_task, sud, DT_TASK, args.logdir, config=config, dt=DT)
taskmgr.add(sud_log_task)
sud_task.set_on_plant_params(lambda elapsed, params: (
server_log_task.log_plant_params(elapsed, params),
sud_log_task.log_plant_params(elapsed, params)))
# Assign data flow
# Assign tc control value to heater
tc.set_on_changed("y", heater_task.actor)
# HeaterTask owns TC enable: enabled in closed-loop mode, disabled in open-loop.
heater_task.set_on_closed_loop_changed(tc.set_enabled)
# Brew start: switch heater to closed-loop so the TC drives it regardless
# of which client (browser, PyQt GUI, …) started the brew.
sud_task.set_on_start(heater_task.start_closed_loop)
# Brew end (DONE/IDLE): shut heater off and broadcast open-loop/power-0 to clients.
sud_task.set_on_end(heater_task.shutdown)
# of which client (browser, PyQt GUI, …) started the brew; also (re)starts
# the per-run sud log (a Pause->resume Start is a no-op for the log).
sud_task.set_on_start(lambda: (heater_task.start_closed_loop(), sud_log_task.start_run()))
# Brew end (DONE/IDLE): shut heater off, broadcast open-loop/power-0 to
# clients, and write out the per-run sud log.
sud_task.set_on_end(lambda: (heater_task.shutdown(), sud_log_task.stop_run()))
# Assign temp. sensor readings to tc
sensor_task.set_on_changed("temp", ChangedFloat(tc.set_theta_ist, prec=2).set)