From 79c65c17062f9b400dd9bbd14f57b208b42092c9 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 22 Jun 2024 16:02:59 -0700 Subject: [PATCH] make slog nicely add new rows --- meshtastic/slog/slog.py | 16 ++++++++++++++-- protobufs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/meshtastic/slog/slog.py b/meshtastic/slog/slog.py index 17910e7..951ae86 100644 --- a/meshtastic/slog/slog.py +++ b/meshtastic/slog/slog.py @@ -50,6 +50,7 @@ class StructuredLogger: self.pMeter = pMeter self.columns = ["time", "power"] self.rawData = pd.DataFrame(columns=self.columns) # use time as the index + # self.rawData.set_index("time", inplace=True) # for efficiency reasons we keep new data in a list - only adding to rawData when needed self.newData: list[dict] = [] @@ -64,8 +65,18 @@ class StructuredLogger: ------- pd.DataFrame: The raw data. """ - df = pd.DataFrame(self.newData, columns=self.columns) - self.rawData = pd.concat([self.rawData, df], ignore_index=True) + + df = pd.DataFrame(self.newData) + + # We prefer some columns to be integers + intcols = [ "bitmask" ] + for c in intcols: + if c in df: + df[c] = df[c].astype('Int64') + + # df.set_index("time") + # Add new data, creating new columns as needed (an outer join) + self.rawData = pd.concat([self.rawData, df], axis=0, ignore_index=True) self.newData = [] return self.rawData @@ -97,6 +108,7 @@ class StructuredLogger: if self.pMeter: # if we have a power meter include a fresh power reading di["power"] = self.pMeter.getWatts() self.newData.append(di) + self.getRawData() else: logging.warning(f"Failed to parse slog {ev.message} with {d.format}") else: diff --git a/protobufs b/protobufs index bfde27a..a82df22 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit bfde27a4ea5cfd0f60ffe961b5ce249aaf54c182 +Subproject commit a82df2239a9dc4b9d43debeb4e87135b13784ca5