Skip to content

160-tool MCP server for real-time global intelligence from free public APIs: markets, liquidity, prediction markets, SEC filings, conflict, military, aircraft-cohort early warning, migration and border flows, cyber, climate, news and more. Dated observation history, 29 research prompts, cited briefs, geofences, SSE dashboard. MIT, no paid API keys.

Dashboard: show uncomputed Trends counts as unknown and list their gaps

Phoenix Agent (mac-studio)66a9f488b7c8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e09f179..3ef8b25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,14 +37,16 @@
anomaly detection's own gaps, and flags a baseline created by the same
call or with no metric at the 5 observations volatility needs. Reading
the baselines no longer creates an empty database file.
+- The dashboard's Trends panel shows a count that could not be computed as
+ `?` instead of 0, stays visible when weekly trends report an error or
+ time out, and lists the data gaps, or the error when there are none.
- Apply per-source request spacing to every HTTP retry, including JSON,
text, XML and binary fetches.
- Known open: each retry now waits out its source's spacing and the
breaker is still checked only before the first attempt, so a full outage
of a rate-limited source takes longer than before to fall back to its
- stale copy. The dashboard's Trends panel shows a `null` anomaly count as
- 0 (it hides the panel only on `error`). The registry tests' temp-cache
- premise still depends on test order.
+ stale copy. The registry tests' temp-cache premise still depends on test
+ order.
## 0.11.0 - 2026-10-12
diff --git a/src/world_intel_mcp/dashboard/index.html b/src/world_intel_mcp/dashboard/index.html
index 02dfa72..8043468 100644
--- a/src/world_intel_mcp/dashboard/index.html
+++ b/src/world_intel_mcp/dashboard/index.html
@@ -837,6 +837,7 @@ function fmtNum(n, d) { d = d != null ? d : 2; return n == null ? '\u2014' : Num
function fmtPct(n) { return n == null ? '\u2014' : (n >= 0 ? '+' : '') + fmtNum(n); }
function fmtBig(n) { if (n == null) return '\u2014'; var a = Math.abs(n); if (a >= 1e12) return '$'+(n/1e12).toFixed(1)+'T'; if (a >= 1e9) return '$'+(n/1e9).toFixed(1)+'B'; if (a >= 1e6) return '$'+(n/1e6).toFixed(1)+'M'; return '$'+fmtNum(n,0); }
function fmtBigPlain(n) { if (n == null) return '\u2014'; var a = Math.abs(n); if (a >= 1e9) return (n/1e9).toFixed(1)+'B'; if (a >= 1e6) return (n/1e6).toFixed(1)+'M'; if (a >= 1e3) return (n/1e3).toFixed(1)+'K'; return String(n); }
+function countOrUnknown(n) { return typeof n === 'number' ? String(n) : '?'; }
function cls(n) { return n == null ? '' : n >= 0 ? 'up' : 'down'; }
function esc(s) { var d = document.createElement('div'); d.textContent = s || ''; return d.innerHTML; }
function trunc(s, n) { n = n || 50; s = s || ''; return s.length > n ? s.slice(0, n) + '\u2026' : s; }
@@ -2841,13 +2842,24 @@ function updateDrawer(data) {
}
// ── TRENDS ──
- if (data.weekly_trends && !data.weekly_trends.error) {
+ // A count the analysis could not compute arrives as null, and a failed
+ // fetch carries none: show those as unknown, never as 0, and list what
+ // failed (the data gaps, or the fetch error when there are none).
+ if (data.weekly_trends) {
var wt = data.weekly_trends;
h += '<div class="sh">TRENDS</div>';
h += '<div class="mini-row">';
- h += '<div class="mini-box"><div class="v">' + (wt.trend_count || 0) + '</div><div class="l">Metrics</div></div>';
- h += '<div class="mini-box"><div class="v' + ((wt.current_anomaly_count || 0) > 0 ? ' warn' : '') + '">' + (wt.current_anomaly_count || 0) + '</div><div class="l">Anomalies</div></div>';
+ h += '<div class="mini-box"><div class="v">' + countOrUnknown(wt.trend_count) + '</div><div class="l">Metrics</div></div>';
+ h += '<div class="mini-box"><div class="v' + (wt.current_anomaly_count > 0 ? ' warn' : '') + '">' + countOrUnknown(wt.current_anomaly_count) + '</div><div class="l">Anomalies</div></div>';
h += '</div>';
+ var wtGaps = (Array.isArray(wt.data_gaps) && wt.data_gaps.length) ? wt.data_gaps : (wt.error ? [wt.error] : []);
+ if (wtGaps.length) {
+ h += '<div class="sub">Data Gaps</div><table class="dtable"><tbody>';
+ wtGaps.forEach(function(g) {
+ h += '<tr><td class="warn">' + esc(String(g)) + '</td></tr>';
+ });
+ h += '</tbody></table>';
+ }
var anomalies = wt.current_anomalies || [];
if (anomalies.length) {
h += '<div class="sub">Active Anomalies</div><table class="dtable"><thead><tr><th>Metric</th><th>Region</th><th>Dev</th></tr></thead><tbody>';
diff --git a/src/world_intel_mcp/tests/test_dashboard_trends_unknown.py b/src/world_intel_mcp/tests/test_dashboard_trends_unknown.py
new file mode 100644
index 0000000..edb9097
--- /dev/null
+++ b/src/world_intel_mcp/tests/test_dashboard_trends_unknown.py
@@ -0,0 +1,70 @@
+"""Static check: the dashboard's Trends panel never shows an unknown count as 0.
+
+``fetch_weekly_trends`` reports ``trend_count`` as None when the baseline
+database is missing or unreadable and ``current_anomaly_count`` as None
+when anomaly detection fails, naming each failure in ``data_gaps`` (and in
+``error`` when the baselines could not be read). The dashboard turns a
+fetch that timed out or raised into ``{"error": ...}`` with no counts at
+all. The Trends panel rendered both counts as ``(x || 0)``, so a failed
+anomaly check read as "0 anomalies", and it hid itself whenever ``error``
+was set, so a missing baseline database left no trace on the page.
+
+These tests read index.html as text and assert the panel's contract: both
+counts go through ``countOrUnknown`` (the number, else "?"), the panel is
+not hidden on error, and it lists the data gaps (or the error when there
+are none) through ``esc``.
+
+Gaps / not covered:
+- Static text analysis, not execution: it proves the block is written this
+ way, not that a browser renders it so. The block was executed in node
+ against five payloads (healthy, failed anomaly detection, missing
+ baselines, a dashboard timeout, a gap containing markup) before and after
+ the change, outside this suite; it was not exercised in a browser.
+- Only the Trends panel is checked. Other panels that render a missing
+ count are not.
+"""
+
+import re
+from pathlib import Path
+
+_INDEX = Path(__file__).resolve().parents[1] / "dashboard" / "index.html"
+_SECTION = "// ── "
+
+
+def _trends_block(src: str) -> str:
+ start = src.index(_SECTION + "TRENDS ──")
+ end = src.index(_SECTION, start + len(_SECTION))
+ return src[start:end]
+
+
+def test_trends_counts_render_unknown_instead_of_zero() -> None:
+ block = _trends_block(_INDEX.read_text())
+ for field in ("trend_count", "current_anomaly_count"):
+ assert re.search(rf"wt\.{field}\s*\|\|", block) is None, (
+ f"{field} still falls back with ||, so null reads as 0"
+ )
+ assert f"countOrUnknown(wt.{field})" in block, f"{field} is not rendered through countOrUnknown"
+
+
+def test_count_or_unknown_shows_only_numbers() -> None:
+ match = re.search(r"^function countOrUnknown\(n\) \{(.*)\}$", _INDEX.read_text(), re.M)
+ assert match, "countOrUnknown is not defined"
+ body = match.group(1)
+ assert "typeof n === 'number'" in body
+ assert re.search(r":\s*'\?'", body), "a non-number does not render as '?'"
+
+
+def test_trends_panel_shows_when_the_fetch_failed() -> None:
+ block = _trends_block(_INDEX.read_text())
+ gate = re.search(r"^\s*if \((.+)\) \{\s*$", block, re.M)
+ assert gate, "the Trends block has no opening if"
+ assert "weekly_trends" in gate.group(1)
+ assert "error" not in gate.group(1), "the panel is hidden when the fetch reports an error"
+
+
+def test_trends_panel_lists_gaps_or_error_escaped() -> None:
+ block = _trends_block(_INDEX.read_text())
+ assert "wt.data_gaps" in block, "the panel never reads data_gaps"
+ assert "wt.error" in block, "a fetch error with no data_gaps is not shown"
+ assert "Data Gaps" in block
+ assert "esc(String(g))" in block, "gap text is not escaped"