diff --git a/README.md b/README.md index 9ef4d7d..c7781f5 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,6 @@ tools/ Pluggable "menu options"; each self-registers and gets logging for services/ Background algorithms (monitor, trace, tx search, courier, watchtower) — no UI persistence/ SQLite schema, repository, structured logging ui/ Rich theme/widgets + the full-screen TUI (screens, dialogs, map, chat) -viz/ Plotly renderers -> interactive HTML ``` Adding a feature means subclassing `Tool`, decorating it with `@register`, and @@ -260,7 +259,6 @@ respective project for the authoritative terms): | [Typer](https://typer.tiangolo.com/) | Scripted CLI (subcommands mirror the menu) | MIT | | [Rich](https://github.com/Textualize/rich) | Console rendering | MIT | | [prompt_toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit) | Full-screen interactive TUI | BSD-3-Clause | -| [Plotly](https://plotly.com/python/) | Self-contained interactive HTML charts | MIT | | [Segno](https://github.com/heuer/segno) | Pure-Python QR codes (channel share links) | BSD-3-Clause | | [tomli](https://github.com/hukkin/tomli) / [tomli-w](https://github.com/hukkin/tomli-w) | TOML config read/write | MIT | diff --git a/config.example.toml b/config.example.toml index cb0fb95..8cb4ee0 100644 --- a/config.example.toml +++ b/config.example.toml @@ -18,7 +18,6 @@ direct_message_soft_retries = 2 # once per session start (0 = keep everything forever). history_days = 365 # db_path = "C:/Users/you/meshterm/meshterm.db" -# output_dir = "C:/Users/you/meshterm/output" # One [profiles.] block per physical companion device. [profiles.s3] diff --git a/meshterm/core/config.py b/meshterm/core/config.py index 754de30..1b978a2 100644 --- a/meshterm/core/config.py +++ b/meshterm/core/config.py @@ -100,7 +100,6 @@ class Settings: Attributes: config_dir: Directory holding the config file and database. db_path: SQLite database location. - output_dir: Where generated visualizations are written. default_profile: Profile used when ``--profile`` is omitted. profiles: Mapping of profile name to :class:`DeviceProfile`. trace_cooldown_s: Minimum delay between transmit bursts (duty-cycle safety). @@ -129,7 +128,6 @@ class Settings: config_dir: Path = field(default_factory=default_config_dir) db_path: Optional[Path] = None - output_dir: Optional[Path] = None default_profile: Optional[str] = None profiles: dict[str, DeviceProfile] = field(default_factory=dict) trace_cooldown_s: float = 1.0 @@ -143,8 +141,6 @@ class Settings: """Derive dependent paths that were not explicitly provided.""" if self.db_path is None: self.db_path = self.config_dir / "meshterm.db" - if self.output_dir is None: - self.output_dir = self.config_dir / "output" def resolve_profile(self, name: Optional[str]) -> Optional[DeviceProfile]: """Look up a profile by name, falling back to the default profile. @@ -205,7 +201,6 @@ class Settings: return cls( config_dir=config_dir, db_path=Path(data["db_path"]) if data.get("db_path") else None, - output_dir=Path(data["output_dir"]) if data.get("output_dir") else None, default_profile=data.get("default_profile"), profiles=profiles, trace_cooldown_s=float(data.get("trace_cooldown_s", 1.0)), diff --git a/meshterm/tools/tx_optimize.py b/meshterm/tools/tx_optimize.py index 3a3e34f..bbe4b13 100644 --- a/meshterm/tools/tx_optimize.py +++ b/meshterm/tools/tx_optimize.py @@ -11,8 +11,8 @@ and the live sweep screen (:mod:`meshterm.ui.tx_screen`) takes it from there, ar idle: route, range, step, and samples are adjusted in place, nothing transmits until Sweep is committed, levels land in a bar chart as they are measured, and the apply decision is made *after* the sweep, over the evidence. On the CLI it stays a scriptable -one-shot with the full flag set (``--path``, range, step, samples, ``--apply``, the HTML -chart), and progress streams like a trace. +one-shot with the full flag set (``--path``, range, step, samples, ``--apply``), and +progress streams like a trace. """ from __future__ import annotations @@ -26,7 +26,6 @@ from ..core.connection import DeviceCommandError from ..core.models import Contact from ..services import trace_runner, tx_optimizer from ..ui.widgets import tx_opt_summary, tx_opt_table -from ..viz.tx_plot import render_tx_optimization from .base import Tool, ToolResult, register #: Trace count per TX level — kept to single digits so the radio's duty cycle stays sane @@ -246,12 +245,6 @@ class TxOptimizeTool(Tool): ctx.ui.show(tx_opt_table(result)) ctx.ui.show(tx_opt_summary(result)) - artifacts: list[str] = [] - if params.get("viz", True): - assert ctx.settings.output_dir is not None - path_out = render_tx_optimization(result, ctx.settings.output_dir) - artifacts.append(str(path_out)) - if no_result: restored = ( f" Restored TX to {result.original_tx}." if result.original_tx is not None else "" @@ -281,7 +274,6 @@ class TxOptimizeTool(Tool): "levels_measured": len(result.levels), }, message=message, - artifacts=artifacts, ) async def _resolve_password( @@ -337,11 +329,10 @@ class TxOptimizeTool(Tool): None, "--password", help="Admin password (else remembered/prompted)" ), apply: bool = typer.Option(True, "--apply/--no-apply", help="Set the winner"), - viz: bool = typer.Option(True, "--viz/--no-viz", help="Generate HTML chart"), ) -> None: tool_params: dict[str, Any] = { "path": path, "samples": samples, "step": step, - "apply": apply, "viz": viz, + "apply": apply, } if tx_min is not None: tool_params["tx_min"] = tx_min diff --git a/meshterm/viz/__init__.py b/meshterm/viz/__init__.py deleted file mode 100644 index 8b9413a..0000000 --- a/meshterm/viz/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Visualization layer: Plotly renderers producing interactive, self-contained HTML. - -* ``tx_plot`` — SNR-vs-TX-power curve for an optimization sweep, with the chosen - optimum highlighted. -""" diff --git a/meshterm/viz/tx_plot.py b/meshterm/viz/tx_plot.py deleted file mode 100644 index 49dae8c..0000000 --- a/meshterm/viz/tx_plot.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Plotly renderer for remote-admin TX-power optimization sweeps. - -Produces a self-contained, interactive HTML chart: median SNR measured *at the target* -and trace success rate versus the admin node's TX power, with the chosen optimum marked. -""" - -from __future__ import annotations - -from datetime import datetime -from pathlib import Path - -import plotly.graph_objects as go - -from ..core.models import TxOptResult - -_TEMPLATE = "plotly_dark" -_BRAND = "#5eead4" -_MUTED = "#94a3b8" - - -def render_tx_optimization(result: TxOptResult, output_dir: Path) -> Path: - """Render a TX-power optimization sweep to an interactive HTML file. - - Args: - result: The optimization result to visualize. - output_dir: Directory the HTML file is written to (created if needed). - - Returns: - Path to the written HTML file. - """ - levels = result.sorted_by_tx() - tx = [lv.tx_power for lv in levels] - snr = [lv.target_snr for lv in levels] - success = [lv.success_rate * 100 for lv in levels] - - fig = go.Figure() - fig.add_trace( - go.Scatter( - x=tx, y=snr, name="target SNR (dB)", mode="lines+markers", - line=dict(color=_BRAND, width=3), marker=dict(size=8), - connectgaps=False, - hovertemplate="TX %{x}
SNR %{y:+.1f} dB", - ) - ) - fig.add_trace( - go.Bar( - x=tx, y=success, name="success rate (%)", yaxis="y2", - marker=dict(color=_MUTED), opacity=0.25, - hovertemplate="TX %{x}
%{y:.0f}% success", - ) - ) - - if result.best_snr is not None: - fig.add_vline(x=result.best_tx, line=dict(color="#4ade80", width=2, dash="dash")) - fig.add_trace( - go.Scatter( - x=[result.best_tx], y=[result.best_snr], - name=f"optimum (TX {result.best_tx})", mode="markers", - marker=dict(color="#4ade80", size=16, symbol="star"), - hovertemplate=f"optimum
TX {result.best_tx}" - "
%{y:+.1f} dB", - ) - ) - - fig.update_layout( - template=_TEMPLATE, - title=dict( - text=f"TX-power optimization — {result.admin_node} → {result.target}" - f" · optimum TX {result.best_tx}", - font=dict(color=_BRAND), - ), - xaxis=dict(title="admin-node TX power", dtick=1), - yaxis=dict(title="target SNR (dB)"), - yaxis2=dict( - title="success rate (%)", overlaying="y", side="right", - range=[0, 105], showgrid=False, - ), - legend=dict(orientation="h", yanchor="bottom", y=1.02), - bargap=0.4, - ) - - output_dir.mkdir(parents=True, exist_ok=True) - stamp = datetime.now().strftime("%Y%m%d-%H%M%S") - path = output_dir / f"tx-optimize_{_slug(result.target)}_{stamp}.html" - fig.write_html(path, include_plotlyjs=True) # fully self-contained / offline - return path - - -def _slug(value: str) -> str: - """Make a filesystem-safe slug from a node name. - - Args: - value: Arbitrary node name or key prefix. - - Returns: - A lowercase slug containing only alphanumerics, dashes, and underscores. - """ - return "".join(c if c.isalnum() or c in "-_" else "-" for c in value).strip("-").lower() diff --git a/pyproject.toml b/pyproject.toml index 0cb7dc9..b5f9fcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ dependencies = [ "typer>=0.12", # scripted CLI; subcommands mirror the menu "rich>=13.7", # modern console rendering (progress, tables, panels) "prompt_toolkit>=3.0", # full-screen interactive TUI (terminal, input, resize) - "plotly>=5.20", # interactive self-contained HTML charts "segno>=1.6", # pure-Python QR codes (channel share links) "tomli>=2.0; python_version < '3.11'", # TOML config reader on 3.10 "tomli-w>=1.0", # TOML writer for device-config backups diff --git a/tests/test_skeleton.py b/tests/test_skeleton.py index cc3db94..a1d45ed 100644 --- a/tests/test_skeleton.py +++ b/tests/test_skeleton.py @@ -523,27 +523,6 @@ def test_trace_target_snr_matches_target_hop_not_position() -> None: assert trace_target_snr(TraceResult(target="f2", success=False), "f2") is None -def test_tx_plot_writes_html(tmp_path: Path) -> None: - """The Plotly renderer produces a self-contained HTML file.""" - import asyncio - - from meshterm.services import tx_optimizer - from meshterm.viz.tx_plot import render_tx_optimization - - async def _build(): - device, admin, target, path = await _setup_link() - return await tx_optimizer.optimize_tx_power( - device, target.name, admin, path, - samples_per_level=4, coarse_step=4, refine=False, verify=False, cooldown_s=0, - ) - - result = asyncio.run(_build()) - path = render_tx_optimization(result, tmp_path) - assert path.exists() - assert path.suffix == ".html" - assert path.stat().st_size > 1000 # plotly.js inlined → non-trivial size - - class _Event: def __init__(self, payload: dict) -> None: self.payload = payload