feat: embed config in server log; replay_sim takes a single log path
ServerLogTask now embeds the full config in its JSON output, matching SudLogTask — so replay_sim and analyze_log work on server logs without needing a separate config file. replay_sim.py switches from two positional args (date_time, sud_name) to a single log file path, with config and plant params resolved from the log's embedded "Config"/"PlantParams" sections when present and falling back to config.json / hardcoded defaults for older logs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+7
-2
@@ -16,12 +16,13 @@ class ServerLogTask(ATask):
|
||||
Sud state — useful for verifying controller and heater behaviour
|
||||
outside of a scheduled brew."""
|
||||
|
||||
def __init__(self, tc: APid, heater: AHeater, heater_task, interval, path='./logs'):
|
||||
def __init__(self, tc: APid, heater: AHeater, heater_task, interval, path='./logs', config=None):
|
||||
ATask.__init__(self, interval)
|
||||
self.tc = tc
|
||||
self.heater = heater
|
||||
self.heater_task = heater_task
|
||||
self.path = path
|
||||
self.config = config
|
||||
self._samples = []
|
||||
self._t0 = time.monotonic()
|
||||
self._run_id = time.strftime("%Y%m%dT%H%M%S", time.localtime())
|
||||
@@ -47,6 +48,10 @@ class ServerLogTask(ATask):
|
||||
os.makedirs(self.path, exist_ok=True)
|
||||
filename = 'log_{}.json'.format(self._run_id)
|
||||
path = os.path.join(self.path, filename)
|
||||
log_data = {'Name': ''}
|
||||
if self.config is not None:
|
||||
log_data['Config'] = self.config
|
||||
log_data['Samples'] = self._samples
|
||||
with open(path, 'w') as f:
|
||||
json.dump({'Name': '', 'Samples': self._samples}, f, indent='\t')
|
||||
json.dump(log_data, f, indent='\t')
|
||||
print('Server log: wrote {} samples to {}'.format(len(self._samples), filename))
|
||||
|
||||
Reference in New Issue
Block a user