Only show the past 24h of locations.

This commit is contained in:
Jason Michalski
2024-06-29 18:08:37 -07:00
parent e937f63322
commit c469cee12b
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -172,7 +172,7 @@ async def get_packets(node_id=None, portnum=None, since=None, limit=500):
return result.scalars()
async def get_packets_from(node_id=None, portnum=None, limit=500):
async def get_packets_from(node_id=None, portnum=None, since=None, limit=500):
async with database.async_session() as session:
q = select(Packet)
@@ -182,6 +182,8 @@ async def get_packets_from(node_id=None, portnum=None, limit=500):
)
if portnum:
q = q.where(Packet.portnum == portnum)
if since:
q = q.where(Packet.import_time > (datetime.datetime.utcnow() - since))
result = await session.execute(q.limit(limit).order_by(Packet.import_time.desc()))
return result.scalars()
+2 -2
View File
@@ -30,7 +30,7 @@ env = Environment(loader=PackageLoader("meshview"), autoescape=select_autoescape
async def build_trace(node_id):
trace = []
for raw_p in await store.get_packets_from(node_id, PortNum.POSITION_APP):
for raw_p in await store.get_packets_from(node_id, PortNum.POSITION_APP, since=datetime.timedelta(hours=24)):
p = Packet.from_model(raw_p)
if not p.raw_payload or not p.raw_payload.latitude_i or not p.raw_payload.longitude_i:
continue
@@ -39,7 +39,7 @@ async def build_trace(node_id):
async def build_neighbors(node_id):
packet = (await store.get_packets_from(node_id, PortNum.NEIGHBORINFO_APP, 1)).first()
packet = (await store.get_packets_from(node_id, PortNum.NEIGHBORINFO_APP, limit=1)).first()
if not packet:
return []
if packet.import_time < datetime.datetime.utcnow() - datetime.timedelta(days=1):