每日计划:复用已发布晨版,排除事后重建样本(台账 067)
一、重复全量构建边界 01:50 既有流水线再次触发计划生成,覆盖 10-14 旧格式入口。已有日期直接复用已发布计划,底层发布拒绝替换旧格式,防止新研究倒灌历史。 二、历史真实性 首次截止日期必须对应行情日的下一交易日,晚生成样本排除真实决策统计。保留现存版本,不回填丢失的旧文件。 三、验证与范围 合成输入回归 36 组通过,覆盖旧格式及完整版本不回源、底层拒绝覆盖和晚生成排除。原流水线、排序参数及准入阈值不变。
This commit is contained in:
parent
8549fa8f84
commit
e44f770f52
|
|
@ -671,3 +671,12 @@
|
|||
- **复核日期。** 2026-10-16 07:25 首晨版及后续自然回放;automation-2 已更新,无额外五日观察。详细备份和回退边界见同日四仓同步交接末节。
|
||||
|
||||
本条更新 065 的“历史三项差异仍在”状态;旧记录保留。
|
||||
|
||||
|
||||
## 067 · 2026-10-16 · 全量重跑复用已发布计划,晚生成首版排除历史统计
|
||||
|
||||
- **日期。** 2026-10-16,北京时间。
|
||||
- **改动。** 已发布日期的全量生成直接复用,不再重采集。底层发布拒绝替换旧格式文件。复盘按行情日的下一交易日核对首次截止日期,晚生成样本单列排除。
|
||||
- **依据。** 01:50 既有“量化交易计划任务”流水线调用默认三步。10-14 旧格式入口被 01:51 新采集结果替换。07:10 正常链另行发布 10-15 数据日完整晨版。原旧格式文件未找到备份,不能宣称恢复。新三组回归覆盖双格式重复生成、底层保护和晚生成排除。
|
||||
- **预期。** 晨版冻结后不被重复全量触发改变;盘中仅走评析与区制完整修订。保留原调度、排序和策略阈值。现存完整版本不重写;历史缺失不伪造。
|
||||
- **复核日期。** 10-16 上线后先比对今晨版本字节、核对旧异常排除,再继续自动修订与提议重核的启用判收。
|
||||
|
|
|
|||
10
plan.py
10
plan.py
|
|
@ -1097,6 +1097,16 @@ def generate(date: str | None = None, top: int = 20, obs_top: int = 10,
|
|||
|
||||
def _generate(date, top, obs_top, theme_cap):
|
||||
ds = date or _latest_date('t_factor_akg_score')
|
||||
# 既有夜间流水线也会触发全量构建。已发布日只能由独立 refresh 修订,
|
||||
# 不能重新取研究覆盖晨版或把旧格式快照升级成事后生成的真实历史。
|
||||
try:
|
||||
published = plan_versions.load(config.PLAN_SNAPSHOT_DIR, ds)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
write_published_md(published)
|
||||
print(f"复用已发布计划 {ds},未重新采集输入")
|
||||
return os.path.join(config.PLAN_SNAPSHOT_DIR, f"plan_{ds}.md")
|
||||
bundle = plan_inputs.Bundle(params=plan_inputs.effective_config(config.module))
|
||||
try:
|
||||
with bundle.use():
|
||||
|
|
|
|||
|
|
@ -384,6 +384,8 @@ def _read_review_snapshot(day: str):
|
|||
try:
|
||||
import plan_versions
|
||||
snap = plan_versions.load(config.PLAN_SNAPSHOT_DIR, day, morning=True)
|
||||
if not plan_versions.morning_eligible(snap):
|
||||
return None
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
main = snap.get("main")
|
||||
|
|
@ -411,12 +413,14 @@ def trace_rows(day):
|
|||
import plan_versions as pv
|
||||
rows, versions = [], {}
|
||||
try:
|
||||
for i, p in enumerate(pv.history(config.PLAN_SNAPSHOT_DIR, day)):
|
||||
history = pv.history(config.PLAN_SNAPSHOT_DIR, day)
|
||||
verified = bool(history) and pv.morning_eligible(history[0])
|
||||
for i, p in enumerate(history):
|
||||
d = p['decision']
|
||||
versions[d['id']] = p
|
||||
rows.append({'date': day, 'kind': 'morning' if i == 0 else 'revision',
|
||||
'decision_id': d['id'], 'parent_id': d.get('parent_id'),
|
||||
'at': d['cutoff_at'], 'reason': d['reason'], 'verified': True,
|
||||
'at': d['cutoff_at'], 'reason': d['reason'], 'verified': verified,
|
||||
'order': [r['code'] for r in p['main']], 'params': {}})
|
||||
except (OSError, ValueError):
|
||||
rows.append({'date': day, 'kind': 'missing_archive', 'verified': False})
|
||||
|
|
|
|||
|
|
@ -133,6 +133,20 @@ def health(root, day, **values):
|
|||
return json.loads(path.read_text()) if path.exists() else {}
|
||||
|
||||
|
||||
def morning_eligible(plan):
|
||||
"""行情日后的首个交易日才是其真实晨版决策日;晚生成不能回填历史。"""
|
||||
from zoneinfo import ZoneInfo
|
||||
from chinese_calendar import is_holiday
|
||||
try:
|
||||
day = dt.date.fromisoformat(plan['date']) + dt.timedelta(days=1)
|
||||
while day.weekday() >= 5 or is_holiday(day):
|
||||
day += dt.timedelta(days=1)
|
||||
cutoff = dt.datetime.fromisoformat(plan['decision']['cutoff_at'])
|
||||
return cutoff.tzinfo is not None and cutoff.astimezone(ZoneInfo('Asia/Shanghai')).date() == day
|
||||
except (KeyError, TypeError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def research(cr, previous=None):
|
||||
cr = cr or {}
|
||||
previous = previous or {}
|
||||
|
|
@ -158,6 +172,8 @@ def publish(root, plan, inputs, params, *, cutoff_at, reason):
|
|||
old = load(root, day)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
if old is not None and not old.get('decision'):
|
||||
raise ValueError('旧格式计划只读保留,禁止以当前输入替换历史')
|
||||
ih, ph = digest(inputs), digest(params)
|
||||
prior = (old or {}).get('decision') or {}
|
||||
if (prior.get('input_hash') == ih and prior.get('params_hash') == ph
|
||||
|
|
|
|||
|
|
@ -31,6 +31,17 @@ class ReviewHistoryTest(unittest.TestCase):
|
|||
with self.assertRaises(RuntimeError):
|
||||
review._plan_for_review('2000-01-01')
|
||||
|
||||
def test_late_first_publication_is_not_historical_morning(self):
|
||||
with tempfile.TemporaryDirectory() as root, patch.object(config, 'PLAN_SNAPSHOT_DIR', root):
|
||||
with pv.writer(root):
|
||||
pv.publish(root, fixture.sample(), {'x': 1}, {},
|
||||
cutoff_at='2026-10-16T01:50:00+08:00', reason='晨版生成')
|
||||
with self.assertRaises(RuntimeError):
|
||||
review._plan_for_review(fixture.DAY)
|
||||
with patch.object(review.db, 'read_mysql', return_value=pd.DataFrame()):
|
||||
rows = review.trace_rows(fixture.DAY)
|
||||
self.assertFalse(rows[0]['verified'])
|
||||
|
||||
def test_consumption_uses_saved_order_not_current_tiers(self):
|
||||
meta = {'kind': 'consumed', 'id': 'consumption1', 'decision': {'id': 'v1'},
|
||||
'order': ['600002.SH', '600001.SH'], 'params': {'tiers': ['旧门槛']}}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,30 @@ def sample():
|
|||
|
||||
|
||||
class VersionsTest(unittest.TestCase):
|
||||
def test_generate_reuses_legacy_and_complete_without_sources(self):
|
||||
for complete in (False, True):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
if complete:
|
||||
with pv.writer(root):
|
||||
pv.publish(root, sample(), {'x': 1}, {}, cutoff_at=CUT, reason='晨版')
|
||||
else:
|
||||
pv.atomic(Path(root) / ('plan_' + DAY + '.json'), sample())
|
||||
files = {p: p.read_bytes() for p in Path(root).rglob('*.json')}
|
||||
with patch.object(plan.config, 'PLAN_SNAPSHOT_DIR', root), \
|
||||
patch.object(plan, 'collect', side_effect=AssertionError('禁止重采集')), \
|
||||
patch.object(plan, 'write_published_md'):
|
||||
self.assertTrue(plan.generate(DAY).endswith('plan_' + DAY + '.md'))
|
||||
self.assertEqual(files, {p: p.read_bytes() for p in Path(root).rglob('*.json')})
|
||||
|
||||
def test_publish_cannot_replace_legacy_bytes(self):
|
||||
path = Path(self.root) / ('plan_' + DAY + '.json')
|
||||
path.write_text(json.dumps(sample(), indent=4))
|
||||
original = path.read_bytes()
|
||||
with self.assertRaisesRegex(ValueError, '旧格式计划只读'):
|
||||
self.publish(inputs={'new': 'research'})
|
||||
self.assertEqual(path.read_bytes(), original)
|
||||
self.assertFalse((Path(self.root) / 'versions').exists())
|
||||
|
||||
def test_revision_window_and_no_replacement_morning(self):
|
||||
import plan_refresh as refresh
|
||||
calendar = types.ModuleType('chinese_calendar')
|
||||
|
|
|
|||
Loading…
Reference in New Issue