import pandas as pd
import matplotlib.pyplot as plt

# Paths to the cleaned data CSV files
files = [
   'output/rive_droite_2024.csv',
    'output/rive_gauche_2024.csv',
    'output/canoo_2023.csv',
    'output/canoo_2020.csv'
]

sources_files = [
    'output/sources/points_sources_rive_droite.csv',
    'output/sources/points_sources_canoo_2023.csv'
]

colors = ['blue', 'limegreen', 'red', 'purple']  # Colors for each year
labels = ['2024 Canoe Right Bank', '2024 Canoe Left Bank', '2023 Canoe', '2020 Canoe']  # Labels for each dataset

sources_colors = ['blue', 'red']  # Colors for each year


dfs = []  # List to store dataframes
for file in files:
    df = pd.read_csv(file)
    dfs.append(df)


sources_dfs = []  # List to store dataframes
for file in sources_files:
    df = pd.read_csv(file)
    sources_dfs.append(df)
    
plt.figure(figsize=(12, 8))  # Create a figure with a custom size

for df, color, label in zip(dfs, colors, labels):
    plt.scatter(df.iloc[:, 0], df.iloc[:, 1], color=color, label=label, alpha=0.8, s=2)  # Plot each year's data


for df, color in zip(sources_dfs, sources_colors):
    bbox_props = dict(boxstyle="round,pad=0.3", fc="white", ec=color, alpha=0.7)
    for i, row in df.iterrows():
        plt.scatter(row['distance'], row['conductivite'], color='white', alpha=0.8, s=60, edgecolors='black', linewidth=3)
        plt.annotate(row['name'], 
                     (row['distance'], row['conductivite']),
                     weight='bold' , 
                     fontsize=11,
                     xytext=(0, 25),
                    bbox=bbox_props,
                    #  arrowprops=dict(facecolor='black', shrink=0.05), 
                     textcoords='offset points',
                     ha='center')


plt.title('Conductivity by kilometers of river for different year of continuous measurements', y=1 , fontsize = 15, fontweight = 'bold')
plt.xlabel('Distance (kilometers)')
plt.ylabel('Conductivity (us/cm)')
plt.legend(loc='lower right', frameon=True, facecolor='white', edgecolor='black', fancybox=False, framealpha=1)
plt.grid(True)

# Sauvegarder le graphique
plt.savefig('output/my_conductivity_plot2.png', format='png', dpi=300, bbox_inches='tight')

plt.show()