import pandas as pd

# jahr-monat-tag
# monat/tag/jahr  (us-schreibweise)

beverages_by_date = pd.read_csv("../../data/beverages_by_date.csv",
                                index_col=0)

# zum datum konvertiert
beverages_by_date.index = pd.to_datetime(
    beverages_by_date.index,
    format="%Y-%m-%d"  # normalerweise nicht
)

print(beverages_by_date)
print(beverages_by_date.index.dtype)
print()
sampler = beverages_by_date.resample("2W")
for el in sampler:
    print(el)
print(sampler)

print(beverages_by_date.loc["2024-02-8":"2024-02-14"])

by_weekly = beverages_by_date.resample("2W").agg({
    'coffee': ["sum", "mean", "std", "count"]
})
print(by_weekly)

# bfill und ffill
# interploate  = linear
#
daily = beverages_by_date.resample("8h").bfill()
print(daily.loc["2024-02-8":"2024-02-14"])

# übung mit zeiten
solar_df = pd.read_csv("../../data/Balkonkraftwerk.csv",
                       index_col=0)
solar_df.index = pd.to_datetime(solar_df.index)
print(solar_df)
print(solar_df.columns)

print(solar_df.index)

# 1) Wie sieht es im Durchschnitt jeden Tag aus (D)
daily = solar_df.resample("d").mean()
print(daily)
print(daily[daily["efficiency_percent"] > 37])
# 2) An welchen Tagen war die durchschnittliche effizientz > 35%
# 2)                          maximum              > 70%
# 3) Stündliche Werte interpolieren  (h)  (1h), (3h)

hourly = solar_df.resample("h").ffill()
print(hourly)

#    - Komisch

print(hourly.loc["2024-05-02"])

print()
daily = beverages_by_date.resample("8h").bfill()
print(daily.loc["2024-02-8":"2024-02-14"])

values = pd.DataFrame({
    "times": ["2025-08-01 05:00:00", "2025-08-01 09:00:00", "2025-08-01 11:00:00"],
    "values": [1, 2, 10]
})
values.set_index("times", inplace=True)
values.index = pd.to_datetime(values.index)
print("-"*100)
print(values)
values = values.resample("h").interpolate()
print(values)
values.index = values.index.tz_localize('Europe/Berlin')
print(values)
values.index = values.index.tz_convert("Us/Central")
print(values)
