From 60582c055ae7f1ebe87da4235508050eac3dc2e7 Mon Sep 17 00:00:00 2001 From: baobao Date: Mon, 16 Nov 2026 15:41:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=B5=84=E9=87=91=E7=9B=91?= =?UTF-8?q?=E6=B5=8B=E4=B8=8D=E5=8F=AF=E7=94=A8=E4=B8=8E=E6=9C=AA=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEVLOG.md | 5 ++ app/core/signal_health.py | 35 +++++++++++++ app/services/upstream_signals.py | 8 +++ app/web/static/index.html | 1 + docs/信号运行巡检与名称刷新修复_2026-11-16.md | 5 ++ scripts/run_tests.py | 1 + scripts/test_signal_health.py | 51 +++++++++++++++++++ 7 files changed, 106 insertions(+) create mode 100644 app/core/signal_health.py create mode 100644 scripts/test_signal_health.py diff --git a/DEVLOG.md b/DEVLOG.md index 47240e5..7d26a10 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -3214,3 +3214,8 @@ a44c994于10:53:29仅发布155的web,镜像pms:proposal-copy-a44c994。开发 ### 15:18 Redis对照与页面发布结论 按用户明确的214:36379/db0核验,239个当日分钟键已到15:00,五时点15只关注持仓均存在;需纠正“资金源停更”的泛化表述。问题在现有ITD资金告警仍读取滞后Mongo,当前129只池内全部落后,其他114只同样受影响。Redis只缺3个分钟键,抽查发现一条完全相同重复;历史日期22日还不能证明满足30日标定。原始消费和Redis事实均保留,未改188取数路径。名称页面39f9989于15:12:20仅发布155 web;最终88组候选断网回归和真实响应隔离浏览器通过,29个其他容器不变,15:12:51对账与连续确认正常。详情见本日[接续](docs/信号运行巡检与名称刷新修复_2026-11-16.md)。 + + +## 2026-11-16 资金监测可用性 + +信号流沿用现有异常提示样式,读取上游独立资金监测状态,避免服务正常被误解为资金监测正常。详见docs/信号运行巡检与名称刷新修复_2026-11-16.md。 diff --git a/app/core/signal_health.py b/app/core/signal_health.py new file mode 100644 index 0000000..0fb0f7f --- /dev/null +++ b/app/core/signal_health.py @@ -0,0 +1,35 @@ +"""把资金监测的数据状态译成交易员提示;不生成交易信号。""" +from datetime import datetime +from zoneinfo import ZoneInfo + + +def funds_warning(doc, codes, now=None, *, trade_day=True): + now = now or datetime.now(ZoneInfo('Asia/Shanghai')) + hm = now.strftime('%H:%M') + active = trade_day and ('09:45' <= hm <= '11:31' or '13:01' <= hm <= '15:01') + unavailable = '资金监测状态暂不可用,不能据此判断持仓和关注股票没有资金异动。' + try: + at = datetime.fromisoformat(doc['at']) + as_of = datetime.fromisoformat(doc['as_of']) + if at.tzinfo is None or as_of.tzinfo is None: + raise ValueError('missing timezone') + if not 0 <= (now-at).total_seconds() <= 180 or as_of.date() != now.date(): + return unavailable if active else '' + if active and not 0 <= (now-as_of).total_seconds() <= 180: + return unavailable + rows = doc['priority'] + if not isinstance(rows, dict) or doc.get('source') != 'redis_stock_flow_realtime': + raise ValueError('invalid health report') + wanted = set(codes) | set(rows) + if not wanted: + return '' + bad = sum(rows.get(c, {}).get('state') != 'available' for c in wanted) + incomplete = sum(rows.get(c, {}).get('money_flow_baseline_ready') is False for c in wanted) + messages = [] + if bad: + messages.append(f'持仓及关注中有{bad}只股票资金数据暂不可用,暂无提示不代表没有资金异动。') + if incomplete: + messages.append('部分股票的资金流强度仍缺历史数据,该类提示暂不可用;其他信号继续监测。') + return ''.join(messages) + except (KeyError, TypeError, ValueError): + return unavailable if active else '' diff --git a/app/services/upstream_signals.py b/app/services/upstream_signals.py index 733742c..3917370 100644 --- a/app/services/upstream_signals.py +++ b/app/services/upstream_signals.py @@ -347,6 +347,14 @@ def snapshot(force: bool = False) -> dict: _try("metrics", lambda: _read_metrics(_c208(dbi))) _try("sell_actions", lambda: _read_sell_actions(_c208(dba))) _try("mr", lambda: _read_mr(_c214())) + # 数据健康与信号流分开:缺失或停更不能解释为没有风险信号。 + from app.core.signal_health import funds_warning + from app.core import tradedays + try: + health = json.loads(_c208(dbi).get('intraday_alerts:fund_health') or 'null') + except Exception: + health = None + out['fund_warning'] = funds_warning(health, _focus_codes(), trade_day=tradedays.is_trade_day()) out['coverage'] = {key[0]: {k: v[k] for k in ('truncated', 'scanned', 'eligible')} for key, v in _focused_streams.items() if key[1] == _today_start_ms()} diff --git a/app/web/static/index.html b/app/web/static/index.html index 462c93f..ad47667 100644 --- a/app/web/static/index.html +++ b/app/web/static/index.html @@ -865,6 +865,7 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;} +