Klaudiusz ugotował

This commit is contained in:
2026-07-05 17:40:45 +02:00
parent d78926f440
commit ca83d1e549
10 changed files with 2312 additions and 144 deletions
+35 -10
View File
@@ -1,27 +1,52 @@
#!/usr/bin/env python3
"""Render a sensor dump (one bracketed row of numbers per line) as a heatmap.
"""Render a sensor dump as a heatmap.
Usage:
python heatmap.py [input.txt] [-o out.png] [--cmap inferno]
Each line is expected to look like:
[55, 192, 131, ..., 138]
Brackets/commas are optional, so plain whitespace-separated rows also work.
Accepts either:
- Raw device log lines as printed by the firmware, e.g.:
5.464019 [INFO ] row 0: [71.6, 75.2, ..., 82.1] (tts_test tts-test/src/main.rs:212)
Only the "row N: [...]" part of each line is used; everything else
(timestamps, log level, source location, other info! lines like the
ambient temperature/heatmap range) is ignored. You can paste the whole
console log as-is.
- Plain rows of numbers, one row per line, brackets/commas optional:
[55, 192, 131, ..., 138]
"""
import argparse
import re
import sys
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
_ROW_RE = re.compile(r"row\s*(\d+)\s*:\s*\[([^\]]*)\]", re.IGNORECASE)
def parse_grid(text):
"""Parse lines of numbers into a 2D list of floats."""
grid = []
for line in text.splitlines():
# strip brackets and split on commas/whitespace
nums = re.findall(r"-?\d+(?:\.\d+)?", line)
"""Parse a device log or a plain number dump into a 2D list of floats."""
text = _ANSI_RE.sub("", text)
# Prefer explicit "row N: [...]" entries (as printed by the firmware's
# info! logs) so that timestamps, log levels and source locations on the
# same line don't get mistaken for pixel data.
rows = {}
for match in _ROW_RE.finditer(text):
idx = int(match.group(1))
nums = re.findall(r"-?\d+(?:\.\d+)?", match.group(2))
if nums:
grid.append([float(n) for n in nums])
rows[idx] = [float(n) for n in nums]
if rows:
grid = [rows[i] for i in sorted(rows)]
else:
# fall back: one row of numbers per line
grid = []
for line in text.splitlines():
nums = re.findall(r"-?\d+(?:\.\d+)?", line)
if nums:
grid.append([float(n) for n in nums])
if not grid:
raise ValueError("No numeric data found in input")
width = len(grid[0])