- root SKILL.md is her upstream file (body byte-identical to the 5fb8379c mirror; description quoted so YAML parses and Mastra can load the skill) - chat binds the whole SKILL.md plus references/product_runtime_contract.md (safety-only) instead of a ~477-character excerpt - every turn carries her full strict-workflow-router (synced to upstream) and the domain's event-judgment file; product lists follow as an extra layer - import her 10 sub-skills, family router, interpretation status contract, technique ontology and the 54 files her method names - tests/test_upstream_skill_parity.py (in the quick gate) fails whenever her skill and ours drift - 18 frontend guards that locked the excerpt design updated with 原值/新值/原因 notes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
128 lines
4.3 KiB
Python
128 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Market data ingestion helpers for financial astrology research."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import csv
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
SCHEMA = "jyotish.market_astrology_data_ingest.v1"
|
|
|
|
|
|
def _as_dict(value: Any) -> dict[str, Any]:
|
|
return value if isinstance(value, dict) else {}
|
|
|
|
|
|
def _as_list(value: Any) -> list[Any]:
|
|
return value if isinstance(value, list) else []
|
|
|
|
|
|
def _normalize_row(row: dict[str, Any]) -> dict[str, Any] | None:
|
|
date = str(row.get("date") or row.get("timestamp") or "").strip()
|
|
if not date:
|
|
return None
|
|
price_row = {
|
|
"date": date,
|
|
"open": row.get("open"),
|
|
"high": row.get("high"),
|
|
"low": row.get("low"),
|
|
"close": row.get("close"),
|
|
"volume": row.get("volume"),
|
|
"source": str(row.get("source") or ""),
|
|
}
|
|
if price_row["close"] is None:
|
|
return None
|
|
return price_row
|
|
|
|
|
|
def _normalize_label_row(row: dict[str, Any]) -> dict[str, Any] | None:
|
|
date = str(row.get("date") or row.get("timestamp") or "").strip()
|
|
label = str(row.get("label") or row.get("outcome") or row.get("regime") or "").strip()
|
|
if not date or not label:
|
|
return None
|
|
return {
|
|
"date": date,
|
|
"label": label,
|
|
"source": str(row.get("source") or ""),
|
|
}
|
|
|
|
|
|
def _load_json(path: Path) -> Any:
|
|
return json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
|
|
def _load_csv(path: Path) -> list[dict[str, Any]]:
|
|
with path.open(encoding="utf-8") as handle:
|
|
return list(csv.DictReader(handle))
|
|
|
|
|
|
def load_market_rows(path: Path) -> list[dict[str, Any]]:
|
|
if path.suffix.lower() == ".json":
|
|
payload = _load_json(path)
|
|
if isinstance(payload, dict):
|
|
payload = payload.get("rows") or payload.get("price_series") or payload.get("labels") or []
|
|
return [row for row in (_normalize_row(item) for item in _as_list(payload)) if row]
|
|
rows = _load_csv(path)
|
|
return [row for row in (_normalize_row(item) for item in rows) if row]
|
|
|
|
|
|
def load_market_labels(path: Path) -> list[dict[str, Any]]:
|
|
if path.suffix.lower() == ".json":
|
|
payload = _load_json(path)
|
|
if isinstance(payload, dict):
|
|
payload = payload.get("rows") or payload.get("labels") or []
|
|
return [row for row in (_normalize_label_row(item) for item in _as_list(payload)) if row]
|
|
rows = _load_csv(path)
|
|
return [row for row in (_normalize_label_row(item) for item in rows) if row]
|
|
|
|
|
|
def build_market_data_packet(
|
|
*,
|
|
price_path: Path,
|
|
label_path: Path | None = None,
|
|
market_profile: dict[str, Any] | None = None,
|
|
) -> dict[str, Any]:
|
|
market_profile = _as_dict(market_profile)
|
|
prices = load_market_rows(price_path)
|
|
labels = load_market_labels(label_path) if label_path else []
|
|
return {
|
|
"schema": SCHEMA,
|
|
"status": "ready" if prices else "blocked",
|
|
"market_profile": {
|
|
"asset_class": str(market_profile.get("asset_class") or "unknown"),
|
|
"symbol": str(market_profile.get("symbol") or "unknown"),
|
|
"exchange": str(market_profile.get("exchange") or "unspecified"),
|
|
"timeframe": str(market_profile.get("timeframe") or "unspecified"),
|
|
},
|
|
"price_series": prices,
|
|
"labels": labels,
|
|
"audit": {
|
|
"technique_audit": [
|
|
{"technique": "Market price ingestion", "status": "used" if prices else "blocked"},
|
|
{"technique": "Market label ingestion", "status": "used" if labels else "blocked"},
|
|
],
|
|
"claim_boundary": "This packet normalizes external market files only; it does not validate predictive truth.",
|
|
},
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--price-path", type=Path, required=True)
|
|
parser.add_argument("--label-path", type=Path)
|
|
parser.add_argument("--market-profile", type=Path)
|
|
args = parser.parse_args()
|
|
market_profile = _load_json(args.market_profile) if args.market_profile else None
|
|
packet = build_market_data_packet(price_path=args.price_path, label_path=args.label_path, market_profile=market_profile)
|
|
print(json.dumps(packet, ensure_ascii=False, indent=2, sort_keys=True))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|