TOOLS/stats-conv: typing fixes

To make mypy happy. PyQtGraph doesn't define types, so ignore those.
PyQt6 has types, but we use only one function from it, so to avoid
installing it, ignore it too.
This commit is contained in:
Kacper Michajłow committed 2025-01-25 02:35:54 +01:00
1 parent 59afdf2ef8
commit 2d5c5030e5
1 file changed
+22 -25
+22 -25
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import re import re
import sys import sys
from typing import Any
import pyqtgraph as pg import pyqtgraph as pg # type: ignore
from PyQt6 import QtWidgets from PyQt6 import QtWidgets # type: ignore
filename = sys.argv[1] filename = sys.argv[1]
@@ -37,12 +38,18 @@ Currently, the following event types are supported:
""" """
class Event:
name: str
vals: list[tuple[float, float]] = []
type: str
marker = ""
class G: class G:
events = {} events: dict[str, Event] = {}
start = 0.0 start = 0.0
markers = ["o", "s", "t", "d"] markers = ["o", "s", "t", "d"]
curveno = {} curveno: dict[Any, int] = {}
sevents = [] sevents: list[Event] = []
def find_marker(): def find_marker():
if len(G.markers) == 0: if len(G.markers) == 0:
@@ -51,12 +58,6 @@ def find_marker():
G.markers = G.markers[1:] G.markers = G.markers[1:]
return m return m
class Event:
name = None
vals = []
type = None
marker = ""
def get_event(event, evtype): def get_event(event, evtype):
if event not in G.events: if event not in G.events:
e = Event() e = Event()
@@ -91,8 +92,8 @@ with open(filename) as file:
line = line.split("#")[0].strip() line = line.split("#")[0].strip()
if not line: if not line:
continue continue
ts, event = line.split(" ", 1) ts_str, event = line.split(" ", 1)
ts = int(ts) / SCALE ts = int(ts_str) / SCALE
if G.start is None: if G.start is None:
G.start = ts G.start = ts
ts -= G.start ts -= G.start
@@ -108,18 +109,16 @@ with open(filename) as file:
e.vals.append((ts, 0)) e.vals.append((ts, 0))
case ["value", rest]: case ["value", rest]:
val, name = rest.split(" ", 1) val, name = rest.split(" ", 1)
val = float(val)
e = get_event(name, "value") e = get_event(name, "value")
e.vals.append((ts, val)) e.vals.append((ts, float(val)))
case ["event-timed", rest]: case ["event-timed", rest]:
val, name = rest.split(" ", 1) val, name = rest.split(" ", 1)
val = int(val) / SCALE - G.start
e = get_event(name, "event-signal") e = get_event(name, "event-signal")
e.vals.append((val, 1)) e.vals.append((int(val) / SCALE - G.start, 1))
case ["range-timed", rest]: case ["range-timed", rest]:
ts1, ts2, name = rest.split(" ", 2) ts1_str, ts2_str, name = rest.split(" ", 2)
ts1 = int(ts1) / SCALE - G.start ts1 = int(ts1_str) / SCALE - G.start
ts2 = int(ts2) / SCALE - G.start ts2 = int(ts2_str) / SCALE - G.start
e = get_event(name, "event") e = get_event(name, "event")
e.vals.append((ts1, 0)) e.vals.append((ts1, 0))
e.vals.append((ts1, 1)) e.vals.append((ts1, 1))
@@ -127,10 +126,8 @@ with open(filename) as file:
e.vals.append((ts2, 0)) e.vals.append((ts2, 0))
case ["value-timed", rest]: case ["value-timed", rest]:
tsval, val, name = rest.split(" ", 2) tsval, val, name = rest.split(" ", 2)
tsval = int(tsval) / SCALE - G.start
val = float(val)
e = get_event(name, "value") e = get_event(name, "value")
e.vals.append((tsval, val)) e.vals.append((int(tsval) / SCALE - G.start, float(val)))
case ["signal", name]: case ["signal", name]:
e = get_event(name, "event-signal") e = get_event(name, "event-signal")
e.vals.append((ts, 1)) e.vals.append((ts, 1))
@@ -163,7 +160,7 @@ ax[0] = win.addPlot()
if hasval: if hasval:
win.nextRow() win.nextRow()
ax[1] = win.addPlot() ax[1] = win.addPlot()
ax[1].setXLink(ax[0]) ax[1].setXLink(ax[0]) # type: ignore
for cur in ax: for cur in ax:
if cur is not None: if cur is not None:
@@ -181,6 +178,6 @@ for e in G.sevents:
else: else:
args["pen"] = pg.mkPen(color, width=0) args["pen"] = pg.mkPen(color, width=0)
G.curveno[cur] += 1 G.curveno[cur] += 1
cur.plot(*zip(*e.vals), **args) cur.plot(*zip(*e.vals), **args) # type: ignore
app.exec() app.exec()