Files
brewpi/tasks/tracer.py
T
jensandClaude Sonnet 4.6 6c50a819fc Remove the unused tc_trace logging
trace_tc (tasks/tracer.py's TracerTask wired to a generic Tracer instance)
was logging to tc_trace.mat, but its var_list was empty, so it only ever
wrote a bare tick counter - no actual tc data, despite the name. Drop the
dead plumbing and the now-unused tracer.py module entirely; the real,
populated brewpi.mat logging (sensor/heater/tc data, built directly inside
TracerTask) is untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DkkuG48uHFCGKe6dPSERFk
2026-06-22 17:50:46 +02:00

69 lines
2.3 KiB
Python

import time
import asyncio
from tasks import ATask
from ws.message import MsgIo
from components import ATemperatureSensor
from components import AHeater
from components import APid
import numpy as np
import scipy.io
import os
class TracerTask(ATask):
def __init__(self, sensor: ATemperatureSensor, heater: AHeater, temp_ctrl: APid, interval, msg_handler: MsgIo, path= './logs'):
ATask.__init__(self, interval)
if not os.path.exists(path):
os.makedirs(path)
self.msg_handler = msg_handler
msg_handler.set_recv_handler(self.recv)
self.sensor = sensor
self.heater = heater
self.temp_ctrl = temp_ctrl
self.path = path
async def recv(self, data):
pass
async def send(self, data):
await self.msg_handler.send(data)
async def on_process(self):
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
timestamp = 0
_timestamp = np.empty(0)
_sensor_temp = np.empty(0)
_heater_power = np.empty(0)
_tc_temp_ist = np.empty(0)
_tc_dtemp_ist = np.empty(0)
_tc_temp_soll = np.empty(0)
_tc_dtemp_soll = np.empty(0)
_tc_dtemp_commanded = np.empty(0)
name = 'brewpi'
filename = os.path.join(self.path, '') + name + ".mat"
filename_full = os.path.join(self.path, '') + name + "." + time.strftime("%Y%m%d%H%M%S", time.localtime()) + ".mat"
while True:
_timestamp = np.append(_timestamp, timestamp)
_sensor_temp = np.append(_sensor_temp, self.sensor.temperature())
_heater_power = np.append(_heater_power, self.heater.get_power())
_tc_temp_ist = np.append(_tc_temp_ist, self.temp_ctrl.theta_ist)
_tc_dtemp_ist = np.append(_tc_dtemp_ist, max(-1, self.temp_ctrl.heatrate_ist))
_tc_temp_soll = np.append(_tc_temp_soll, self.temp_ctrl.theta_soll_set)
_tc_dtemp_soll = np.append(_tc_dtemp_soll, self.temp_ctrl.heatrate_soll_set)
_tc_dtemp_commanded = np.append(_tc_dtemp_commanded, self.temp_ctrl.heatrate_soll)
data = {'time': _timestamp, 'sensor_temp': _sensor_temp, 'heater_power': _heater_power, 'tc_temp_ist': _tc_temp_ist, 'tc_dtemp_ist': _tc_dtemp_ist, 'tc_temp_soll': _tc_temp_soll, 'tc_dtemp_soll': _tc_dtemp_soll, 'tc_dtemp_commanded': _tc_dtemp_commanded}
scipy.io.savemat(filename, data)
scipy.io.savemat(filename_full, data)
timestamp += 1
await asyncio.sleep(self.interval)