1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-01-13 17:17:26 -05:00

Ensure stats are serialized when requested

The seen_list, tracker and aprsdthreadlist wasn't
serializing it's data when requested during stats() time..
This commit is contained in:
Walter Boring 2026-01-07 14:57:28 -05:00
parent 3eade4eb8b
commit 34017bedfe
3 changed files with 17 additions and 2 deletions

View File

@ -27,7 +27,20 @@ class SeenList(objectstore.ObjectStoreMixin):
def stats(self, serializable=False):
"""Return the stats for the PacketTrack class."""
with self.lock:
return self.data
if serializable:
# Convert datetime objects to strings for JSON serialization
serializable_data = {}
for callsign, data in self.data.items():
serializable_data[callsign] = data.copy()
if 'last' in serializable_data[callsign] and isinstance(
serializable_data[callsign]['last'], datetime.datetime
):
serializable_data[callsign]['last'] = serializable_data[
callsign
]['last'].isoformat()
return serializable_data
else:
return self.data
def rx(self, packet: type[core.Packet]):
"""When we get a packet from the network, update the seen list."""

View File

@ -66,6 +66,8 @@ class PacketTrack(objectstore.ObjectStoreMixin):
pkts = {}
for key in self.data:
last_send_time = self.data[key].last_send_time
if serializable and isinstance(last_send_time, datetime.datetime):
last_send_time = last_send_time.isoformat()
pkts[key] = {
'last_send_time': last_send_time,
'send_count': self.data[key].send_count,

View File

@ -107,7 +107,7 @@ class APRSDThreadList:
'name': th.name,
'class': th.__class__.__name__,
'alive': th.is_alive(),
'age': th.loop_age(),
'age': age,
'loop_count': th.loop_count,
}
return stats