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:
@@ -9,6 +9,7 @@ Usage
|
||||
-----
|
||||
python client.py
|
||||
python client.py --host 192.168.1.10 --port 9999
|
||||
python client.py --diff # reconstruct from diff stream
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -16,6 +17,8 @@ import json
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from utils.jay_diff import jay_merge_full
|
||||
|
||||
|
||||
def main() -> None:
|
||||
p = argparse.ArgumentParser(
|
||||
@@ -24,6 +27,7 @@ def main() -> None:
|
||||
)
|
||||
p.add_argument("--host", default="127.0.0.1", help="Server host (default: 127.0.0.1)")
|
||||
p.add_argument("--port", type=int, default=9999, help="Server port (default: 9999)")
|
||||
p.add_argument("--diff", action="store_true", help="Reconstruct full snapshots from diff stream")
|
||||
args = p.parse_args()
|
||||
|
||||
print(f"Connecting to {args.host}:{args.port} …", flush=True)
|
||||
@@ -36,6 +40,7 @@ def main() -> None:
|
||||
print("Connected. Waiting for data (Ctrl-C to quit).\n", flush=True)
|
||||
buf = ""
|
||||
count = 0
|
||||
state: dict = {}
|
||||
try:
|
||||
with sock:
|
||||
while True:
|
||||
@@ -51,8 +56,17 @@ def main() -> None:
|
||||
continue
|
||||
try:
|
||||
data = json.loads(line)
|
||||
if args.diff:
|
||||
if data.get("_diff"):
|
||||
diff = {k: v for k, v in data.items() if k != "_diff"}
|
||||
state = jay_merge_full(state, diff)
|
||||
else:
|
||||
state = data
|
||||
display = state
|
||||
else:
|
||||
display = data
|
||||
count += 1
|
||||
print(json.dumps(data, indent=2))
|
||||
print(json.dumps(display, indent=2))
|
||||
print(f"--- #{count} ", "-" * 50, flush=True)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"[invalid JSON] {e}: {line!r}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user