Query based on start and end time of observations.

This commit is contained in:
Yaro Kasear 2025-04-10 08:50:56 -05:00
parent 05e4d6bf6c
commit a46ed79d3d

View file

@ -18,11 +18,11 @@ def convert_timestamp_to_epoch(ts_string):
print(f"[!] Invalid timestamp format: {ts_string}")
return None
def get_rf_metrics(cursor, bssid, channel, timestamp):
def get_rf_metrics(cursor, bssid, channel, start_time, end_time):
cursor.execute("""
SELECT COUNT(*) FROM devicelink
WHERE type = 'Wi-Fi Client' AND mac = ? AND last_time BETWEEN ? AND ?
""", (bssid.lower(), timestamp - 10, timestamp + 10))
""", (bssid.lower(), start_time, end_time))
clients_on_ap = cursor.fetchone()[0]
cursor.execute("""
@ -32,14 +32,14 @@ def get_rf_metrics(cursor, bssid, channel, timestamp):
WHERE devicelink.type = 'Wi-Fi Client'
AND devices.channel = ?
AND devicelink.last_time BETWEEN ? AND ?
""", (channel, timestamp - 10, timestamp + 10))
""", (channel, start_time, end_time))
clients_on_channel = cursor.fetchone()[0]
cursor.execute("""
SELECT COUNT(*) FROM devices
WHERE type = 'Wi-Fi AP' AND channel = ?
AND last_time BETWEEN ? AND ?
""", (channel, timestamp - 10, timestamp + 10))
""", (channel, start_time, end_time))
aps_on_channel = cursor.fetchone()[0]
congestion_score = round(clients_on_channel / aps_on_channel, 2) if aps_on_channel else 0.0
@ -60,7 +60,8 @@ def main():
writer.writeheader()
for row in reader:
ts = convert_timestamp_to_epoch(row["Timestamp"])
tstart = convert_timestamp_to_epoch(row["StartTimestamp"])
tend = convert_timestamp_to_epoch(row["EndTimestamp"])
try:
bssid = row["BSSID"].strip().lower()
channel = int(row["Channel"])
@ -73,7 +74,7 @@ def main():
writer.writerow(row)
continue
clients_ap, clients_chan, aps_chan, congestion = get_rf_metrics(cursor, bssid, channel, ts)
clients_ap, clients_chan, aps_chan, congestion = get_rf_metrics(cursor, bssid, channel, tstart, tend)
row["ClientsOnAP"] = clients_ap
row["ClientsOnChannel"] = clients_chan