fix(hypotheses): only count successful discovery days in picks_log

This commit is contained in:
Youssef Aitousarrah 2026-04-10 09:50:37 -07:00
parent 1b782b1cd6
commit fe5b8886c0
1 changed files with 39 additions and 23 deletions

View File

@ -64,15 +64,17 @@ def extract_picks(worktree: str, scanner: str) -> list:
data = json.load(f) data = json.load(f)
for item in data.get("final_ranking", []): for item in data.get("final_ranking", []):
if item.get("strategy_match") == scanner: if item.get("strategy_match") == scanner:
picks.append({ picks.append(
"date": TODAY, {
"ticker": item["ticker"], "date": TODAY,
"score": item.get("final_score"), "ticker": item["ticker"],
"confidence": item.get("confidence"), "score": item.get("final_score"),
"scanner": scanner, "confidence": item.get("confidence"),
"return_7d": None, "scanner": scanner,
"win_7d": None, "return_7d": None,
}) "win_7d": None,
}
)
except Exception as e: except Exception as e:
print(f" Warning: could not read {result_file}: {e}", flush=True) print(f" Warning: could not read {result_file}: {e}", flush=True)
return picks return picks
@ -125,7 +127,13 @@ def run_hypothesis(hyp: dict) -> bool:
try: try:
result = subprocess.run( result = subprocess.run(
[sys.executable, "scripts/run_daily_discovery.py", "--date", TODAY, "--no-update-positions"], [
sys.executable,
"scripts/run_daily_discovery.py",
"--date",
TODAY,
"--no-update-positions",
],
cwd=worktree, cwd=worktree,
check=False, check=False,
) )
@ -139,12 +147,12 @@ def run_hypothesis(hyp: dict) -> bool:
save_picks_to_worktree(worktree, hid, scanner, merged) save_picks_to_worktree(worktree, hid, scanner, merged)
run(["git", "push", "origin", f"HEAD:{branch}"], cwd=worktree) run(["git", "push", "origin", f"HEAD:{branch}"], cwd=worktree)
if TODAY not in hyp.get("picks_log", []): if TODAY not in hyp.get("picks_log", []):
hyp.setdefault("picks_log", []).append(TODAY) hyp.setdefault("picks_log", []).append(TODAY)
hyp["days_elapsed"] = len(hyp["picks_log"]) hyp["days_elapsed"] = len(hyp["picks_log"])
if hyp["days_elapsed"] >= hyp["min_days"]: if hyp["days_elapsed"] >= hyp["min_days"]:
return conclude_hypothesis(hyp) return conclude_hypothesis(hyp)
finally: finally:
run(["git", "worktree", "remove", "--force", worktree], check=False) run(["git", "worktree", "remove", "--force", worktree], check=False)
@ -171,11 +179,16 @@ def conclude_hypothesis(hyp: dict) -> bool:
else: else:
result = subprocess.run( result = subprocess.run(
[ [
sys.executable, "scripts/compare_hypothesis.py", sys.executable,
"--hypothesis-id", hid, "scripts/compare_hypothesis.py",
"--picks-json", json.dumps(picks), "--hypothesis-id",
"--scanner", scanner, hid,
"--db-path", str(DB_PATH), "--picks-json",
json.dumps(picks),
"--scanner",
scanner,
"--db-path",
str(DB_PATH),
], ],
cwd=str(ROOT), cwd=str(ROOT),
capture_output=True, capture_output=True,
@ -221,12 +234,14 @@ def conclude_hypothesis(hyp: dict) -> bool:
if decision == "accepted": if decision == "accepted":
subprocess.run( subprocess.run(
["gh", "pr", "merge", str(pr), "--squash", "--delete-branch"], ["gh", "pr", "merge", str(pr), "--squash", "--delete-branch"],
cwd=str(ROOT), check=False, cwd=str(ROOT),
check=False,
) )
else: else:
subprocess.run( subprocess.run(
["gh", "pr", "close", str(pr), "--delete-branch"], ["gh", "pr", "close", str(pr), "--delete-branch"],
cwd=str(ROOT), check=False, cwd=str(ROOT),
check=False,
) )
hyp["status"] = "concluded" hyp["status"] = "concluded"
@ -264,7 +279,8 @@ def main():
hypotheses = registry.get("hypotheses", []) hypotheses = registry.get("hypotheses", [])
running = [ running = [
h for h in hypotheses h
for h in hypotheses
if h["status"] == "running" and (not filter_id or h["id"] == filter_id) if h["status"] == "running" and (not filter_id or h["id"] == filter_id)
] ]