Neighbors ui update add filters

This commit is contained in:
Lloyd
2025-12-08 22:30:00 +00:00
parent 377f3961dd
commit 3de7dfefa6
5 changed files with 166 additions and 118 deletions

View File

@@ -15,6 +15,7 @@ class SQLiteHandler:
self.storage_dir = storage_dir
self.sqlite_path = self.storage_dir / "repeater.db"
self._init_database()
self._run_migrations()
def _init_database(self):
try:
@@ -63,7 +64,8 @@ class SQLiteHandler:
rssi INTEGER,
snr REAL,
advert_count INTEGER NOT NULL DEFAULT 1,
is_new_neighbor BOOLEAN NOT NULL
is_new_neighbor BOOLEAN NOT NULL,
zero_hop BOOLEAN NOT NULL DEFAULT FALSE
)
""")
@@ -105,6 +107,47 @@ class SQLiteHandler:
except Exception as e:
logger.error(f"Failed to initialize SQLite: {e}")
def _run_migrations(self):
"""Run database migrations"""
try:
with sqlite3.connect(self.sqlite_path) as conn:
# Create migrations table if it doesn't exist
conn.execute("""
CREATE TABLE IF NOT EXISTS migrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
migration_name TEXT NOT NULL UNIQUE,
applied_at REAL NOT NULL
)
""")
# Migration 1: Add zero_hop column to adverts table
migration_name = "add_zero_hop_to_adverts"
existing = conn.execute(
"SELECT migration_name FROM migrations WHERE migration_name = ?",
(migration_name,)
).fetchone()
if not existing:
# Check if zero_hop column already exists
cursor = conn.execute("PRAGMA table_info(adverts)")
columns = [column[1] for column in cursor.fetchall()]
if "zero_hop" not in columns:
conn.execute("ALTER TABLE adverts ADD COLUMN zero_hop BOOLEAN NOT NULL DEFAULT FALSE")
logger.info("Added zero_hop column to adverts table")
# Mark migration as applied
conn.execute(
"INSERT INTO migrations (migration_name, applied_at) VALUES (?, ?)",
(migration_name, time.time())
)
logger.info(f"Migration '{migration_name}' applied successfully")
conn.commit()
except Exception as e:
logger.error(f"Failed to run migrations: {e}")
def store_packet(self, record: dict):
try:
with sqlite3.connect(self.sqlite_path) as conn:
@@ -169,7 +212,8 @@ class SQLiteHandler:
UPDATE adverts
SET timestamp = ?, node_name = ?, is_repeater = ?, route_type = ?,
contact_type = ?, latitude = ?, longitude = ?, last_seen = ?,
rssi = ?, snr = ?, advert_count = advert_count + 1, is_new_neighbor = 0
rssi = ?, snr = ?, advert_count = advert_count + 1, is_new_neighbor = 0,
zero_hop = ?
WHERE pubkey = ?
""", (
current_time,
@@ -182,14 +226,16 @@ class SQLiteHandler:
current_time,
record.get("rssi"),
record.get("snr"),
record.get("zero_hop", False),
record.get("pubkey", "")
))
else:
conn.execute("""
INSERT INTO adverts (
timestamp, pubkey, node_name, is_repeater, route_type, contact_type,
latitude, longitude, first_seen, last_seen, rssi, snr, advert_count, is_new_neighbor
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
latitude, longitude, first_seen, last_seen, rssi, snr, advert_count,
is_new_neighbor, zero_hop
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", (
current_time,
record.get("pubkey", ""),
@@ -204,7 +250,8 @@ class SQLiteHandler:
record.get("rssi"),
record.get("snr"),
1,
True
True,
record.get("zero_hop", False)
))
except Exception as e:
@@ -619,7 +666,7 @@ class SQLiteHandler:
query = """
SELECT id, timestamp, pubkey, node_name, is_repeater, route_type,
contact_type, latitude, longitude, first_seen, last_seen,
rssi, snr, advert_count, is_new_neighbor
rssi, snr, advert_count, is_new_neighbor, zero_hop
FROM adverts
WHERE contact_type = ?
"""
@@ -655,7 +702,8 @@ class SQLiteHandler:
"rssi": row["rssi"],
"snr": row["snr"],
"advert_count": row["advert_count"],
"is_new_neighbor": bool(row["is_new_neighbor"])
"is_new_neighbor": bool(row["is_new_neighbor"]),
"zero_hop": bool(row["zero_hop"])
}
adverts.append(advert)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,8 +8,8 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<script type="module" crossorigin src="/assets/index-Dd2v807Z.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-D0MhMeIG.css">
<script type="module" crossorigin src="/assets/index-DYqcF5Pe.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BsJox_xF.css">
</head>
<body>
<div id="app"></div>