mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-07-30 13:33:25 +02:00
Only show the past 24h of locations.
This commit is contained in:
+3
-1
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user