import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import glob
import os

# Pfad zu deinem Ordner mit den CSVs
pfad = "../data/tageswerte_pro_Jahr/*.csv"   # z.B. "data/*.csv" oder "C:/Users/du/fahrrad/*.csv"

# Liste aller Dateinamen
dateien = glob.glob(pfad)
dfs = []
for datei in dateien:
    df_temp = pd.read_csv(datei)
    jahr = os.path.basename(datei).split("_")[2]
    df_temp["jahr_datei"] = jahr
    dfs.append(df_temp)

# Alle Teil-DataFrames untereinander hängen
df = pd.concat(dfs, ignore_index=True)

print(df.shape)
      operator_name     domain_name  domain_id  \
0  Eco Counter GmbH  Stadt Tübingen        667   
1  Eco Counter GmbH  Stadt Tübingen        667   
2  Eco Counter GmbH  Stadt Tübingen        667   
3  Eco Counter GmbH  Stadt Tübingen        667   
4  Eco Counter GmbH  Stadt Tübingen        667   

                                     counter_site  counter_site_id  \
0  Fuß- & Radtunnel Südportal - Derendinger Allee        100003358   
1  Fuß- & Radtunnel Südportal - Derendinger Allee        100003358   
2  Fuß- & Radtunnel Südportal - Derendinger Allee        100003358   
3  Fuß- & Radtunnel Südportal - Derendinger Allee        100003358   
4  Fuß- & Radtunnel Südportal - Derendinger Allee        100003358   

  counter_serial  longitude  latitude                      timezone  \
0    YAH24052174    9.04806    48.518  (UTC+01:00) Europe/Paris DST   
1    YAH24052174    9.04806    48.518  (UTC+01:00) Europe/Paris DST   
2    YAH24052174    9.04806    48.518  (UTC+01:00) Europe/Paris DST   
3    YAH24052174    9.04806    48.518  (UTC+01:00) Europe/Paris DST   
4    YAH24052174    9.04806    48.518  (UTC+01:00) Europe/Paris DST   

               iso_timestamp channels_in channels_out channels_unknown  \
0  2013-06-21T00:00:00+02:00        2844         2647               na   
1  2013-06-22T00:00:00+02:00        2412         2233               na   
2  2013-06-23T00:00:00+02:00        1884         1808               na   
3  2013-06-24T00:00:00+02:00        2072         1878               na   
4  2013-06-25T00:00:00+02:00        2426         2419               na   

   channels_all site_temperature site_rain_accumulation  \
0          5491             17.5                    1.5   
1          4645             16.5                    0.2   
2          3692             14.5                    0.0   
3          3950             12.5                    5.4   
4          4845             11.5                    6.0   

  site_snow_accumulation jahr_datei  
0                    0.0   2013.csv  
1                    0.0   2013.csv  
2                    0.0   2013.csv  
3                    0.0   2013.csv  
4                    0.0   2013.csv  
(247598, 18)
C:\Users\nikol\AppData\Local\Temp\ipykernel_6688\409510964.py:12: DtypeWarning: Columns (10,11,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.
  df_temp = pd.read_csv(datei)  # evtl. sep anpassen: "," oder ";"
C:\Users\nikol\AppData\Local\Temp\ipykernel_6688\409510964.py:12: DtypeWarning: Columns (10,11,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.
  df_temp = pd.read_csv(datei)  # evtl. sep anpassen: "," oder ";"
yearly_avg_ma = []
years=[]
for year in range(14,25):
    dfyear = pd.read_csv(f'../data/tageswerte_pro_Jahr/fahrradzaehler_tageswerten_20{year}.csv', delimiter=',')
    dfyear_ma = dfyear[dfyear["domain_name"] == 'Stadt Mannheim']
    yearly_avg_ma.append(np.mean(dfyear_ma["channels_all"]))
    years.append(f"20{year}")

plot_data = pd.DataFrame({
    'Year': years,
    'Average': yearly_avg_ma
})
C:\Users\nikol\AppData\Local\Temp\ipykernel_6688\1595929334.py:4: DtypeWarning: Columns (10,11,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.
  dfyear = pd.read_csv(f'../data/tageswerte_pro_Jahr/fahrradzaehler_tageswerten_20{year}.csv', delimiter=',')
C:\Users\nikol\AppData\Local\Temp\ipykernel_6688\1595929334.py:4: DtypeWarning: Columns (10,11,14,15,16) have mixed types. Specify dtype option on import or set low_memory=False.
  dfyear = pd.read_csv(f'../data/tageswerte_pro_Jahr/fahrradzaehler_tageswerten_20{year}.csv', delimiter=',')
# WICHTIG Hier kommt der Absturz des Mittelwerts dadurch, dass mehr Zählstationen hinzugefügt wurden, die nicht an einem Hotspot standen, also Mittelwert sinkt.
sns.set(style="whitegrid")

# Create a line plot or bar plot
plt.figure(figsize=(10, 6))
sns.lineplot(x='Year', y='Average', data=plot_data, marker='o')

# Optional: Customize the plot further
plt.title("Yearly Average of Tracked Bikes in Mannheim", fontsize=16)
plt.xlabel("Year", fontsize=12)
plt.ylabel("Average Number of bikes", fontsize=12)

# Show the plot
plt.tight_layout()
plt.show()

# getrackte Räder nach channel site, also Standort der Zählstation im Jahr 2014
df15 = pd.read_csv(f'../data/tageswerte_pro_Jahr/fahrradzaehler_tageswerten_2019.csv', delimiter=',')
df15_ma = df15[df15["domain_name"] == 'Stadt Mannheim']
print(df15_ma)
          operator_name     domain_name  domain_id    counter_site  \
3285   Eco Counter GmbH  Stadt Mannheim       4197      Renzstraße   
3286   Eco Counter GmbH  Stadt Mannheim       4197      Renzstraße   
3287   Eco Counter GmbH  Stadt Mannheim       4197      Renzstraße   
3288   Eco Counter GmbH  Stadt Mannheim       4197      Renzstraße   
3289   Eco Counter GmbH  Stadt Mannheim       4197      Renzstraße   
...                 ...             ...        ...             ...   
10945  Eco Counter GmbH  Stadt Mannheim       4197  Kurpfalzbrücke   
10946  Eco Counter GmbH  Stadt Mannheim       4197  Kurpfalzbrücke   
10947  Eco Counter GmbH  Stadt Mannheim       4197  Kurpfalzbrücke   
10948  Eco Counter GmbH  Stadt Mannheim       4197  Kurpfalzbrücke   
10949  Eco Counter GmbH  Stadt Mannheim       4197  Kurpfalzbrücke   

       counter_site_id counter_serial  longitude   latitude  \
3285         100013246    YTH21025244   8.481114  49.490270   
3286         100013246    YTH21025244   8.481114  49.490270   
3287         100013246    YTH21025244   8.481114  49.490270   
3288         100013246    YTH21025244   8.481114  49.490270   
3289         100013246    YTH21025244   8.481114  49.490270   
...                ...            ...        ...        ...   
10945        100043761    YTH18116954   8.472163  49.494099   
10946        100043761    YTH18116954   8.472163  49.494099   
10947        100043761    YTH18116954   8.472163  49.494099   
10948        100043761    YTH18116954   8.472163  49.494099   
10949        100043761    YTH18116954   8.472163  49.494099   

                           timezone              iso_timestamp channels_in  \
3285   (UTC+01:00) Europe/Paris DST  2019-01-01T00:00:00+01:00         318   
3286   (UTC+01:00) Europe/Paris DST  2019-01-02T00:00:00+01:00        1050   
3287   (UTC+01:00) Europe/Paris DST  2019-01-03T00:00:00+01:00         931   
3288   (UTC+01:00) Europe/Paris DST  2019-01-04T00:00:00+01:00        1036   
3289   (UTC+01:00) Europe/Paris DST  2019-01-05T00:00:00+01:00         509   
...                             ...                        ...         ...   
10945  (UTC+01:00) Europe/Paris DST  2019-12-27T00:00:00+01:00        1180   
10946  (UTC+01:00) Europe/Paris DST  2019-12-28T00:00:00+01:00        1232   
10947  (UTC+01:00) Europe/Paris DST  2019-12-29T00:00:00+01:00         715   
10948  (UTC+01:00) Europe/Paris DST  2019-12-30T00:00:00+01:00        1362   
10949  (UTC+01:00) Europe/Paris DST  2019-12-31T00:00:00+01:00         925   

      channels_out channels_unknown  channels_all site_temperature  \
3285           348               na           666              4.5   
3286          1002               na          2052              3.5   
3287           866               na          1797              2.5   
3288           954               na          1990              2.5   
3289           506               na          1015              5.0   
...            ...              ...           ...              ...   
10945         1282               na          2462              5.5   
10946         1325               na          2557              3.5   
10947          786               na          1501              2.0   
10948         1534               na          2896              1.5   
10949         1029               na          1954              2.5   

      site_rain_accumulation site_snow_accumulation  
3285                     0.8                    0.0  
3286                     0.8                    0.0  
3287                     0.1                    0.1  
3288                     0.3                    0.0  
3289                    11.1                    0.0  
...                      ...                    ...  
10945                    1.4                    0.0  
10946                    0.0                    0.0  
10947                    0.0                    0.0  
10948                    0.0                    0.0  
10949                    0.0                    0.0  

[2555 rows x 17 columns]