import json

def analyze():
    def get_bars(filename):
        with open(f"/home/aryy/.hermes/profiles/finance/backtests/xauusd_2026/hybrid/data/{filename}.json") as f:
            data = json.load(f)
            return data["bars"] if "bars" in data else data

    m30 = get_bars("ohlcv_M30")
    m15 = get_bars("ohlcv_M15")
    m5 = get_bars("ohlcv_M5")
    h1 = get_bars("ohlcv_H1")
    h4 = get_bars("ohlcv_H4")

    print("=== HTF Context (H4 & H1) leading to Feb 13 17:15 ===")
    for b in h4:
        if "2026-02-13" in b["time"]:
            print("H4:", b)
    for b in h1:
        if "2026-02-13" in b["time"] and b["time"] >= "2026-02-13T12:00:00Z":
            print("H1:", b)

    print("\n=== M30 around Feb 13 17:15 & 18:00 ===")
    for b in m30:
        if "2026-02-13" in b["time"] and b["time"] >= "2026-02-13T15:00:00Z":
            print("M30:", b)

    print("\n=== M15 around Feb 13 17:15 & 18:00 ===")
    for b in m15:
        if "2026-02-13" in b["time"] and b["time"] >= "2026-02-13T16:30:00Z" and b["time"] <= "2026-02-13T19:00:00Z":
            print("M15:", b)

    print("\n=== M5 around Feb 13 17:15 (207) ===")
    for b in m5:
        if b["time"] >= "2026-02-13T17:00:00Z" and b["time"] <= "2026-02-13T17:45:00Z":
            print("M5:", b)

    print("\n=== M5 around Feb 13 18:00 (208) ===")
    for b in m5:
        if b["time"] >= "2026-02-13T17:50:00Z" and b["time"] <= "2026-02-13T18:45:00Z":
            print("M5:", b)

    print("\n=== HTF Context leading to Feb 16 00:00 ===")
    for b in h4:
        if "2026-02-15" in b["time"] or ("2026-02-16" in b["time"] and b["time"] <= "2026-02-16T04:00:00Z"):
            print("H4:", b)

    print("\n=== M15 around Feb 16 00:00 (209) ===")
    for b in m15:
        if ("2026-02-15" in b["time"] and b["time"] >= "2026-02-15T22:00:00Z") or ("2026-02-16" in b["time"] and b["time"] <= "2026-02-16T02:00:00Z"):
            print("M15:", b)

    print("\n=== M5 around Feb 16 00:00 (209) ===")
    for b in m5:
        if ("2026-02-15" in b["time"] and b["time"] >= "2026-02-15T23:30:00Z") or ("2026-02-16" in b["time"] and b["time"] <= "2026-02-16T01:00:00Z"):
            print("M5:", b)

if __name__ == "__main__":
    analyze()
