From ede9cf278a5d97215c262929d4b9f29c3a928db3 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 23 Jun 2025 12:02:36 +0200 Subject: [PATCH 1/4] Generazione grafico da dataframe concentrato in una funzione --- Fotovoltaico.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Fotovoltaico.py b/Fotovoltaico.py index 5f4127b..845865d 100644 --- a/Fotovoltaico.py +++ b/Fotovoltaico.py @@ -54,17 +54,18 @@ print("Valore massimo:",max(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # prin print("Somma totale:",sum(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the total sum of the generated energy result_ac_energies_to_csv_df.to_csv(path_export, encoding='utf-8') -# GENERAZIONE GRAFICO -import plotly.express as px -# Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' -fig = px.line( - result_ac_energies_to_csv_df, - x=result_ac_energies_to_csv_df.index, - y='gen_pv_100_kWp', - title='Produttività Fotovoltaica nel Tempo', - labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} -) -fig.show() +def generate_grafico_df(dataframe): + # GENERAZIONE GRAFICO + import plotly.express as px + # Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' + fig = px.line( + dataframe, + x=dataframe.index, + y='gen_pv_100_kWp', + title='Produttività Fotovoltaica nel Tempo', + labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} + ) + fig.show() def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly): """ @@ -75,17 +76,6 @@ def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hour df_hourly.to_csv(path_export_hourly, encoding='utf-8') print(f"File CSV orario salvato in: {path_export_hourly}") - fig = px.line( - df_hourly, - x=df_hourly.index, - y='gen_pv_100_kWp', - title='Produttività Fotovoltaica su Base Oraria', - labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} - ) - fig.show() - -# --- USO DELLA FUNZIONE DOPO L'EXPORT ORIGINALE --- - # Scegli il percorso per il nuovo file orario path_export_hourly = path_export.replace('.csv', '_hourly.csv') From cfa5f1c5687571b11775a49718b85ead95eb3f59 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 23 Jun 2025 12:04:42 +0200 Subject: [PATCH 2/4] Chiamata funzioni generazione grafico (delta 15min e base oraria) --- Fotovoltaico.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Fotovoltaico.py b/Fotovoltaico.py index 845865d..b9153eb 100644 --- a/Fotovoltaico.py +++ b/Fotovoltaico.py @@ -75,13 +75,17 @@ def export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hour df_hourly = result_ac_energies_to_csv_df.resample('H').sum() df_hourly.to_csv(path_export_hourly, encoding='utf-8') print(f"File CSV orario salvato in: {path_export_hourly}") + return df_hourly # Scegli il percorso per il nuovo file orario path_export_hourly = path_export.replace('.csv', '_hourly.csv') # Esporta il file orario -export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly) +df_hourly = export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly) +# GENERAZIONE GRAFICI +generate_grafico_df(result_ac_energies_to_csv_df) +generate_grafico_df(df_hourly) if joePlaying: joe.terminate() From d23ca2127efcc771ba495442e4addebe417a1eaa Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 23 Jun 2025 12:06:36 +0200 Subject: [PATCH 3/4] fix titoli grafici --- Fotovoltaico.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Fotovoltaico.py b/Fotovoltaico.py index b9153eb..fef41f6 100644 --- a/Fotovoltaico.py +++ b/Fotovoltaico.py @@ -54,7 +54,7 @@ print("Valore massimo:",max(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # prin print("Somma totale:",sum(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the total sum of the generated energy result_ac_energies_to_csv_df.to_csv(path_export, encoding='utf-8') -def generate_grafico_df(dataframe): +def generate_grafico_df(dataframe, graphTitle): # GENERAZIONE GRAFICO import plotly.express as px # Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' @@ -62,7 +62,7 @@ def generate_grafico_df(dataframe): dataframe, x=dataframe.index, y='gen_pv_100_kWp', - title='Produttività Fotovoltaica nel Tempo', + title=graphTitle, labels={'gen_pv_100_kWp': 'Energia [kWh]', 'index': 'Data/Ora'} ) fig.show() @@ -84,8 +84,8 @@ path_export_hourly = path_export.replace('.csv', '_hourly.csv') df_hourly = export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly) # GENERAZIONE GRAFICI -generate_grafico_df(result_ac_energies_to_csv_df) -generate_grafico_df(df_hourly) +generate_grafico_df(result_ac_energies_to_csv_df, 'Produttività Fotovoltaica nel Tempo') +generate_grafico_df(df_hourly, 'Produttività Fotovoltaica a Base Oraria') if joePlaying: joe.terminate() From 0d40d3730f0ffa115039b3330b8c5cd8e4a090f8 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Mon, 23 Jun 2025 12:09:48 +0200 Subject: [PATCH 4/4] bisogna specificare la tipologia di grafico --- Fotovoltaico.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Fotovoltaico.py b/Fotovoltaico.py index fef41f6..8a83062 100644 --- a/Fotovoltaico.py +++ b/Fotovoltaico.py @@ -54,7 +54,7 @@ print("Valore massimo:",max(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # prin print("Somma totale:",sum(result_ac_energies_to_csv_df.gen_pv_100_kWp)) # print the total sum of the generated energy result_ac_energies_to_csv_df.to_csv(path_export, encoding='utf-8') -def generate_grafico_df(dataframe, graphTitle): +def generate_grafico_torri_df(dataframe, graphTitle): # GENERAZIONE GRAFICO import plotly.express as px # Supponendo che la colonna di interesse sia 'gen_pv_100_kWp' @@ -84,8 +84,8 @@ path_export_hourly = path_export.replace('.csv', '_hourly.csv') df_hourly = export_hourly_pv_productivity(result_ac_energies_to_csv_df, path_export_hourly) # GENERAZIONE GRAFICI -generate_grafico_df(result_ac_energies_to_csv_df, 'Produttività Fotovoltaica nel Tempo') -generate_grafico_df(df_hourly, 'Produttività Fotovoltaica a Base Oraria') +generate_grafico_torri_df(result_ac_energies_to_csv_df, 'Produttività Fotovoltaica nel Tempo') +generate_grafico_torri_df(df_hourly, 'Produttività Fotovoltaica a Base Oraria') if joePlaying: joe.terminate()