Add opt-in diff mode for network transmission (--diff / Diff mode checkbox)
Server (collect.py --diff): - History burst: first record sent full, subsequent as jay_diff_full diffs - Live broadcast: each snapshot diffed against the previous one - Diff payloads tagged with "_diff": true Client (client.py --diff): - Reconstructs full state via jay_merge_full before printing GUI (Connector tab "Diff mode" checkbox): - TcpReader.connect_to() accepts diff_mode; maintains _state dict - Merges incoming diffs before emitting to Dashboard/Plot - Checkbox state persisted to plot_settings.json Both sides default to off; must be enabled consistently on server and client. utils/__init__.py added so utils.jay_diff is importable as a package. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+15
-1
@@ -55,6 +55,7 @@ from pathlib import Path
|
||||
from server import log_config, network, we_connect
|
||||
from server.data_model import ALL_DOMAINS, collect_snapshot
|
||||
from server.storage_helpers import auto_out_path, load_last_24h_records, load_store, save_store
|
||||
from utils.jay_diff import jay_diff_full
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -92,6 +93,7 @@ def run(args: argparse.Namespace) -> None:
|
||||
out = auto_out_path(logs_dir, vin)
|
||||
|
||||
push_clients, push_lock, push_store_ref = network.start_push_server(args.host, args.port)
|
||||
push_store_ref["diff_mode"] = args.diff
|
||||
push_store_ref["preloaded"] = load_last_24h_records(logs_dir, vin)
|
||||
if push_store_ref["preloaded"]:
|
||||
log.info("Pre-loaded %d record(s) from the last 24 h", len(push_store_ref["preloaded"]))
|
||||
@@ -99,6 +101,7 @@ def run(args: argparse.Namespace) -> None:
|
||||
current_day = datetime.now(timezone.utc).date()
|
||||
store = load_store(out, vin, args.interval)
|
||||
push_store_ref["current"] = store
|
||||
last_broadcast: dict = {}
|
||||
|
||||
if args.dry:
|
||||
log.info("Push server running on %s:%d — no live collection (Ctrl-C to stop)", args.host, args.port)
|
||||
@@ -126,7 +129,13 @@ def run(args: argparse.Namespace) -> None:
|
||||
snapshot = collect_snapshot(vehicle, domains)
|
||||
store["records"].append(snapshot)
|
||||
save_store(out, store, args.max_records)
|
||||
network.broadcast(snapshot, push_clients, push_lock)
|
||||
if args.diff and last_broadcast:
|
||||
payload = jay_diff_full(last_broadcast, snapshot, combine_upd_add=True)
|
||||
payload["_diff"] = True
|
||||
else:
|
||||
payload = snapshot
|
||||
network.broadcast(payload, push_clients, push_lock)
|
||||
last_broadcast = snapshot
|
||||
log.info("Record #%d saved at %s", len(store["records"]), snapshot["ts"])
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
@@ -184,6 +193,11 @@ def main() -> None:
|
||||
help="Keep only the last N records per file (default: unlimited)",
|
||||
)
|
||||
p.add_argument("-v", "--verbose", action="store_true", help="Enable debug logging")
|
||||
p.add_argument(
|
||||
"--diff",
|
||||
action="store_true",
|
||||
help="Send diffs instead of full snapshots over the push server (default: off)",
|
||||
)
|
||||
p.add_argument(
|
||||
"--dry",
|
||||
action="store_true",
|
||||
|
||||
Reference in New Issue
Block a user