This commit is contained in:
2024-06-02 19:38:39 +03:00
parent c4244e86e6
commit 2048f9c57d
3 changed files with 222 additions and 128 deletions

View File

@ -36,6 +36,7 @@ class Database:
name TEXT,
ip TEXT,
latency TEXT,
link_latency TEXT,
FOREIGN KEY(trace_id) REFERENCES Traces(id)
);
@ -59,7 +60,12 @@ class Database:
trace = dict(t)
self.cursor.execute(
"SELECT number, name, ip, latency FROM Hops WHERE trace_id = ? ORDER BY number ASC",
"""
SELECT number, name, ip, latency, link_latency
FROM Hops
WHERE trace_id = ?
ORDER BY number ASC
""",
(trace["id"],),
)
hops = self.cursor.fetchall()
@ -78,7 +84,7 @@ class Database:
for hop in trace["hops"]:
self.cursor.execute(
"INSERT OR IGNORE INTO Hops (trace_id, created, number, name, ip, latency) VALUES (?, ?, ?, ?, ?, ?)",
"INSERT OR IGNORE INTO Hops (trace_id, created, number, name, ip, latency, link_latency) VALUES (?, ?, ?, ?, ?, ?, ?)",
(
trace_id,
hop["created"],
@ -86,6 +92,7 @@ class Database:
hop["name"],
hop["ip"],
hop["latency"],
hop["link_latency"],
),
)
@ -97,18 +104,6 @@ class Database:
(name, ip, latency),
)
def create_latency(self, link_id, timestamp, link_latency):
self.cursor.execute(
"INSERT INTO Latency (link_id, timestamp, latency_ms) VALUES (?, ?, ?)",
(link_id, timestamp, link_latency),
)
def create_path(self, node, target, json):
self.cursor.execute(
"INSERT OR IGNORE INTO Paths (node, target, hops_json) VALUES (?, ?, ?)",
(node, target, json),
)
def ensure_table_setup():
db = Database()