# -*- coding: ansi -*-
import csv

seen = []

fieldnames = ["Name", "Bundesland", "Flaeche", "Maximale Seetiefe", "Seevolumen", "Anzahl"]

with open("seen.csv", newline="", encoding="ansi") as csvfile:
    reader = csv.DictReader(csvfile, delimiter=';', fieldnames=fieldnames)
    for row in reader:
        row['Flaeche'] = float(row['Flaeche'].replace(',', '.'))
        row['Maximale Seetiefe'] = float(row['Maximale Seetiefe'].replace(',', '.'))
        row['Seevolumen'] = float(row['Seevolufmen'].replace(',', '.')) if row['Seevolumen'] else 0
        seen.append(row)

anzahl_seen = len(seen)
gesamtflaeche = sum(s['Flaeche'] for s in seen)
tiefster_see = max(seen, key=lambda s: s['Maximale Seetiefe'])
durchschnittstiefe = sum(s['Maximale Seetiefe'] for s in seen) / anzahl_seen

print(f"Anzahl der Seen: {anzahl_seen}")
print(f"Gesamtfläche: {gesamtflaeche:.2f} km²")
print(f"Tiefster See: {tiefster_see['Name']} mit {tiefster_see['Maximale Seetiefe']} m")
print(f"Durchschnittliche Tiefe: {durchschnittstiefe:.2f} m\n")

print("Liste aller Seen mit Bundesland:")
for s in seen:
    print(f"{s['Name']} ({s['Bundesland']})")
