터치 패널 그래프 현재값 표시 정리

This commit is contained in:
seo committed 2026-07-30 22:16:26 +09:00
1 parent 1f894bcde1
commit 49a3349a1d
2 files changed
+28 -14

No files matched your search

+27 -13
View File
@@ -29,6 +29,9 @@ NET_GROUPS = {
PC_IP = "192.168.50.73"
PC_MAC = "74:56:3C:CD:CD:79"
SAMPLE_INTERVAL_MS = 50
GRAPH_SECONDS = 5
GRAPH_POINTS = GRAPH_SECONDS * 1000 // SAMPLE_INTERVAL_MS
def byte_rate_unit(values):
@@ -44,11 +47,13 @@ def byte_rate_unit(values):
return 1, "B/s"
def format_byte_rate(value, factor=None, unit=None):
def format_byte_rate(value, factor=None, unit=None, fixed=False):
if factor is None or unit is None:
factor, unit = byte_rate_unit([value])
scaled = float(value) / factor
if abs(scaled) >= 100:
if fixed:
text = f"{scaled:6.2f}"
elif abs(scaled) >= 100:
text = f"{scaled:.0f}"
elif abs(scaled) >= 10:
text = f"{scaled:.1f}"
@@ -57,6 +62,15 @@ def format_byte_rate(value, factor=None, unit=None):
return f"{text} {unit}"
def format_wan_caption(rx_rate, tx_rate):
factor, unit = byte_rate_unit([rx_rate, tx_rate])
return f"{format_byte_rate(rx_rate, factor, unit, True)} / {format_byte_rate(tx_rate, factor, unit, True)}"
def format_temp_rpm_caption(temp, rpm):
return f"{temp:5.1f} C / {int(rpm):5d} rpm"
def read_text(path, default=""):
try:
return Path(path).read_text(encoding="utf-8").strip()
@@ -393,8 +407,8 @@ class Sparkline(QFrame):
layout.addWidget(self.canvas, 1)
def set_values(self, values, caption, second_values=None):
self.values = list(values)[-80:]
self.second_values = list(second_values or [])[-80:]
self.values = list(values)[-GRAPH_POINTS:]
self.second_values = list(second_values or [])[-GRAPH_POINTS:]
self.caption.setText(caption)
self.canvas.update()
@@ -480,9 +494,9 @@ class TouchPanel(QMainWindow):
self.latest_rpm = 0
self.latest_pwm = self.current_pwm
self.latest_percent = 0.0
self.temp_history = deque(maxlen=80)
self.rpm_history = deque(maxlen=80)
self.net_history = {"wan": {"rx": deque(maxlen=80), "tx": deque(maxlen=80)}}
self.temp_history = deque(maxlen=GRAPH_POINTS)
self.rpm_history = deque(maxlen=GRAPH_POINTS)
self.net_history = {"wan": {"rx": deque(maxlen=GRAPH_POINTS), "tx": deque(maxlen=GRAPH_POINTS)}}
self.setWindowTitle("Standalone Touch Dashboard")
self.setCursor(Qt.BlankCursor)
@@ -491,11 +505,11 @@ class TouchPanel(QMainWindow):
self.sample_timer = QTimer(self)
self.sample_timer.timeout.connect(self.sample)
self.sample_timer.start(50)
self.sample_timer.start(SAMPLE_INTERVAL_MS)
self.dashboard_timer = QTimer(self)
self.dashboard_timer.timeout.connect(self.update_dashboard)
self.dashboard_timer.start(50)
self.dashboard_timer.start(SAMPLE_INTERVAL_MS)
self.pc_ping = QProcess(self)
self.pc_ping.finished.connect(self.pc_ping_finished)
@@ -663,7 +677,7 @@ class TouchPanel(QMainWindow):
self.metrics["rpm"].set_value(f"{rpm:,}")
self.metrics["temp"].set_value(f"{temp:.1f} C")
self.metrics["pwm"].set_value(f"{pwm} / {percent:.1f}%")
self.metrics["pwm"].set_value(f"{percent:.1f}%")
self.metrics["mem"].set_value(f"{mem_percent:.1f}%")
self.slider.blockSignals(True)
@@ -703,14 +717,14 @@ class TouchPanel(QMainWindow):
rpm = getattr(self, "latest_rpm", read_int(self.fan["rpm"]))
self.temp_history.append(temp)
self.rpm_history.append(rpm)
self.charts["temp"].set_values(self.temp_history, "C / RPM", self.rpm_history)
self.charts["temp"].set_values(self.temp_history, format_temp_rpm_caption(temp, rpm), self.rpm_history)
wan = self.current_rates.get("wan", {"rx": 0.0, "tx": 0.0})
self.net_history["wan"]["rx"].append(wan["rx"])
self.net_history["wan"]["tx"].append(wan["tx"])
self.charts["wan"].set_values(
self.net_history["wan"]["rx"],
f"{format_byte_rate(wan['rx'])}/{format_byte_rate(wan['tx'])}",
format_wan_caption(wan["rx"], wan["tx"]),
self.net_history["wan"]["tx"],
)
@@ -747,7 +761,7 @@ def main():
#metricTitle { color: #8fa7c5; font-size: 13px; background: transparent; }
#metricValue { color: #f8fafc; font-size: 24px; font-weight: 800; background: transparent; }
#chartTitle { color: #dce8f8; font-size: 14px; font-weight: 700; background: transparent; }
#chartCaption { color: #93a4bd; font-size: 11px; background: transparent; }
#chartCaption { color: #93a4bd; font-size: 11px; background: transparent; font-family: "DejaVu Sans Mono", monospace; }
#clock { font-size: 18px; color: #8fb3ff; font-weight: 700; }
#statusText { color: #93a4bd; font-size: 13px; background: transparent; }
QSlider::groove:horizontal { height: 10px; background: #263650; border-radius: 5px; }