42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import csv, json, sys
|
|
|
|
RAW = "/root/.hermes/wizard-outputs/ledger/crypto-top250-fresh.json"
|
|
CSV = "/root/.hermes/wizard-outputs/ledger/crypto-top250.csv"
|
|
EXPECTED_HEADER = ["rank", "name", "symbol", "price_usd", "market_cap_usd",
|
|
"mcap_24h_pct", "volume_24h_usd", "circulating_supply", "last_updated"]
|
|
|
|
def fmt_pct(v):
|
|
return (f'{v:,.2f}%' if v is not None else "-")
|
|
|
|
def main():
|
|
with open(RAW) as f:
|
|
rows = json.load(f)["rows"]
|
|
if len(rows) != 250:
|
|
print("FAIL: expected 250 raw rows, got", len(rows)); return 1
|
|
|
|
with open(CSV, newline="") as f:
|
|
rd = list(csv.reader(f))
|
|
if rd[0] != EXPECTED_HEADER:
|
|
print("FAIL: header mismatch ->", rd[0]); return 1
|
|
data = rd[1:]
|
|
if len(data) != 250:
|
|
print("FAIL: expected 250 data rows, got", len(data)); return 1
|
|
|
|
by_rank = {int(r[0]): r for r in data}
|
|
for i, c in enumerate(rows, start=1):
|
|
exp = [str(i),
|
|
c["name"], c["symbol"],
|
|
f'{c["current_price"]:,.2f}', f'{c["market_cap"]:,.0f}',
|
|
fmt_pct(c.get("market_cap_change_percentage_24h")),
|
|
f'{c["total_volume"]:,.0f}', f'{c["circulating_supply"]:,.0f}',
|
|
c.get("last_updated", "")]
|
|
if by_rank.get(i) != exp:
|
|
print(f"FAIL: rank {i} mismatch\n csv={by_rank.get(i)}\n exp={exp}"); return 1
|
|
|
|
anchors = {1: "Bitcoin", 2: "Ethereum", 250: rows[249]["name"]}
|
|
print(f"PASS: {len(data)} rows, header OK, ranks 1/2/250 in raw == CSV (computed from raw JSON)")
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|