tools.limbic_chart module
Chart Stargazer’s limbic vectors over time.
Reads from the mementropic limbic ledger (Redis ZSETs in DB0) and produces Plotly line charts of NCM node values with datetime axes.
Supports per-channel scoping and global heart history.
- async tools.limbic_chart.run(scope='channel', channel_id='', nodes='', hours=24.0, chart_type='line', ctx=None)[source]
Chart Stargazer’s NCM limbic vectors over time and save the image to disk.
The
limbic_charttool handler. It reads the mementropic limbic ledger for the requested scope (this channel, or the global__heart__history) over a time window, selects which NCM nodes to plot (an explicit list, or the top five most volatile by standard deviation), renders a dark-themed Plotly line/area chart, exports it to a PNG file in a temp directory, and returns that path plus plotting metadata. The hours window is clamped to[0.5, 168].Interactions: obtains the DB0 client via
_get_db0_client()and reads the ledger ZSET withZRANGEBYSCOREkeyed byredis_ledger_key; importscanonical_ncm_keys/redis_ledger_key/_parse_ledger_memberfrommementropic.limbic_ledgerto decode each ledger member into a (timestamp, vector) pair; builds the figure with Plotlygraph_objectsand rasterizes it viafig.to_imageoffloaded withasyncio.to_thread(); writes the PNG to atempfile.mkdtemp()directory; serializes its result withjson.dumps. Missing Plotly/kaleido or any render error is caught and logged. Dispatched by name throughtool_loaderfrom this module’sTOOL_NAME/runsingle-tool definition; no direct Python callers.- Parameters:
scope (
str) –"channel"for this channel’s shard history, or"heart"for the global heart history. Defaults to"channel".channel_id (
str) – Override channel id; defaults toctx.channel_id.nodes (
str) – Comma-separated NCM node names to plot; when empty, the top five most volatile nodes are auto-selected.hours (
float) – Time window in hours (clamped to[0.5, 168]); defaults to 24.chart_type (
str) –"line"(default),"area", or"radar".ctx (
ToolContext|None) – The tool context supplying Redis (DB0) and the channel id;Noneyields an error JSON.
- Returns:
JSON; on success includes
chart_path,scope,channel_id,nodes_plotted,data_points, and atime_range; otherwise{"success": False, "error": ...}(no context/channel/Redis, no ledger data, unknown node names, missing dependency, or render failure).- Return type: