import sqlite3, datetime, re DB = r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\attendancehub_v2.db" LOG = r"G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\logs\attendancehub_sync.log" con = sqlite3.connect(f"file:{DB}?mode=ro", uri=True, timeout=15) print("=== E2E proof: the LIVE event seen at 13:02:44 -> did it land? ===") for r in con.execute( "SELECT personnel_code, device_id, punch_time, first_seen_at, source, upload_state, acked_at " "FROM punches WHERE personnel_code='96670' ORDER BY first_seen_at DESC LIMIT 3"): print(f" pin={r[0]} dev={r[1]}\n punch_time={r[2]}\n first_seen={r[3]}\n" f" source={r[4]} state={r[5]} acked={r[6]}") print("\n=== all LIVE-channel events in log (last 15) with their result ===") ev = [] with open(LOG, "r", encoding="utf-8", errors="replace") as f: for ln in f: if "channel=LIVE" in ln and " src=OnAttTransaction" in ln: ev.append(ln.rstrip()) print(f" total LIVE OnAttTransaction events logged: {len(ev)}") for e in ev[-15:]: m = re.search(r"^(\S+ \S+) .*pin=(\S+) state=(\S+) time=(\S+ \S+)", e) d = re.search(r"device=(\S+)", e) if m and d: print(f" log={m.group(1):<21} dev={d.group(1):<16} pin={m.group(2):<8} " f"deviceTime={m.group(4)}") print("\n=== last 10 punches in DB (source + latency) ===") def parse(s): if not s: return None s = s.rstrip("Z") w, _, fr = s.partition(".") fr = (fr + "0000000")[:7] return (datetime.datetime.fromisoformat(w).replace(tzinfo=datetime.timezone.utc) + datetime.timedelta(microseconds=int(fr) / 10)) for r in con.execute( "SELECT personnel_code, device_id, punch_time, first_seen_at, source, upload_state " "FROM punches ORDER BY first_seen_at DESC LIMIT 10"): p, f = parse(r[3]), parse(r[3]) try: pl = datetime.datetime.fromisoformat(r[2].rstrip("Z").partition(".")[0]) # label is site-local; log/local comparison: raw label vs first_seen(UTC) raw = (parse(r[3]) - datetime.datetime.fromisoformat( r[2].rstrip("Z").partition(".")[0]).replace(tzinfo=datetime.timezone.utc)).total_seconds() lat = raw + 12600 - 84 t = f"{lat:6.1f}s" except Exception as ex: t = f"err" print(f" {r[3][11:19]} pin={r[0]:<8} {r[1]:<16} {r[4]:<14} {r[5]:<8} dev->db={t}") print("\n=== totals ===") for r in con.execute("SELECT source, COUNT(*) FROM punches WHERE first_seen_at >= ? GROUP BY source", (datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d") + "T00:00:00.0000000Z",)): print(f" {r[0]}: {r[1]}") for r in con.execute("SELECT upload_state, COUNT(*) FROM punches GROUP BY upload_state"): print(f" {r[0]}: {r[1]}") import os print(f" db size: {os.path.getsize(DB)/1024/1024:.1f} MB") con.close()