"""Cikarim sonuclarini filtrele ve farkli formatlarda kaydet.

Kullanim:
    python 03_result_export.py
"""

from evren_sdk import EvrenClient

client = EvrenClient(api_key="evren_xxxxx")

result = client.predict("kullanici/model", "sahne.jpg", confidence=0.1)
print(f"Ham sonuc: {result.count} tespit\n")

# --- filtrele ---
yuksek = result.filter(min_confidence=0.7)
print(f"Guven >= 0.7 : {yuksek.count} tespit")

sadece_araba = result.filter(classes=["araba"])
print(f"Sadece araba : {sadece_araba.count} tespit")

combo = result.filter(min_confidence=0.5, max_confidence=0.9, classes=["insan"])
print(f"insan 0.5-0.9: {combo.count} tespit")

# --- export ---
print("\n--- YOLO (normalized cx cy w h) ---")
print(result.to_yolo()[:200])

print("\n--- COCO (bbox + area + category_id) ---")
coco = result.to_coco()
for ann in coco[:3]:
    print(f"  cat={ann['category_id']}  bbox={ann['bbox']}  area={ann['area']:.0f}")

print("\n--- CSV ---")
print(result.to_csv()[:300])

# --- dosyaya kaydet ---
result.save("output/sonuc.json")
result.save("output/sonuc.csv")
result.save("output/labels.txt")     # YOLO format
print("\nDosyalar kaydedildi: output/")
