feat: add min hours-to-expiry filter on ops map (8-48h step 2)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""按采样时刻距离到期时长过滤行情样本。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Iterable
|
||||
|
||||
from packages.domain.expiry import expiry_ms_from_ymd
|
||||
|
||||
|
||||
def hours_to_expiry_at(ts_ms: int, expiry_ymd: str) -> float | None:
|
||||
try:
|
||||
ems = expiry_ms_from_ymd(str(expiry_ymd))
|
||||
except ValueError:
|
||||
return None
|
||||
return (ems - int(ts_ms)) / 3_600_000.0
|
||||
|
||||
|
||||
def filter_rows_min_hours_to_expiry(
|
||||
rows: Iterable[dict[str, Any]],
|
||||
*,
|
||||
min_hours: float,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""保留采样时距到期 ≥ min_hours 的样本。"""
|
||||
out: list[dict[str, Any]] = []
|
||||
mh = float(min_hours)
|
||||
for r in rows:
|
||||
h = hours_to_expiry_at(int(r.get("ts_ms") or 0), str(r.get("expiry_ymd") or ""))
|
||||
if h is None:
|
||||
continue
|
||||
if h >= mh:
|
||||
out.append(r)
|
||||
return out
|
||||
Reference in New Issue
Block a user