From 6830dd4531cc5b2ad4ad40c2dc329ebc0f77de93 Mon Sep 17 00:00:00 2001 From: Jochen Hanisch-Johannsen Date: Tue, 29 Jul 2025 19:37:43 +0200 Subject: [PATCH] =?UTF-8?q?Promotion:=20Exportfunktion=20f=C3=BCr=20scp-Ex?= =?UTF-8?q?port=20in=20export=5Ffigure=5Flocal=20integriert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyse_korrelation.py | 29 ++++++++++++++++++++++------- analyse_netzwerk.py | 8 +++++--- deskriptive-literaturauswahl.py | 5 +++-- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/analyse_korrelation.py b/analyse_korrelation.py index 3af7997..9f0c6b9 100644 --- a/analyse_korrelation.py +++ b/analyse_korrelation.py @@ -3,10 +3,18 @@ import os # Neue Exportfunktion: HTML in /tmp speichern, per SCP übertragen, PNG lokal speichern def export_figure(fig, name, export_flag_html, export_flag_png): - from config_korrelation import export_path_png - safe_filename = slugify(name) + # Lokale Implementierung der Exportlogik inkl. Bib-Quelle im Titel und Dateinamen + from config_korrelation import export_path_png, bib_filename + from slugify import slugify remote_path = "johajo@sternenflottenakademie.local:/mnt/deep-space-nine/public/plot/promotion/" + # Titel ggf. um Quelle ergänzen + if fig.layout.title and fig.layout.title.text: + if f"| Quelle: {bib_filename.replace('.bib', '')}" not in fig.layout.title.text: + fig.update_layout(title_text=f"{fig.layout.title.text} | Quelle: {bib_filename.replace('.bib', '')}") + + safe_filename = slugify(f"{name}_{bib_filename.replace('.bib', '')}") + if export_flag_html: export_path_html = f"/tmp/{safe_filename}.html" fig.write_html(export_path_html, full_html=True, include_plotlyjs="cdn") @@ -20,10 +28,10 @@ def export_figure(fig, name, export_flag_html, export_flag_png): print(e.stderr) if export_flag_png: - export_path_png = os.path.join(export_path_png, f"{safe_filename}.png") + export_path_png_full = os.path.join(export_path_png, f"{safe_filename}.png") try: - fig.write_image(export_path_png, width=1200, height=800, scale=2) - print(f"✅ PNG-Datei lokal gespeichert: '{export_path_png}'") + fig.write_image(export_path_png_full, width=1200, height=800, scale=2) + print(f"✅ PNG-Datei lokal gespeichert: '{export_path_png_full}'") except Exception as e: print("❌ Fehler beim PNG-Export:", str(e)) @@ -702,11 +710,14 @@ summary_df = pd.DataFrame({ # Plotly-Version für interaktive Darstellung def plot_average_correlation_plotly(summary_df): + from config_korrelation import export_path_png + from config_korrelation import bib_filename as global_bib_filename + from slugify import slugify fig = px.bar( summary_df, x="Korrelationstyp", y="Durchschnittliche Korrelation", - title=f"Durchschnittliche Korrelationen pro Korrelationstyp (n={len(summary_df)}, Stand: {current_date}) | Quelle: {bib_filename.replace('.bib', '')}", + title=f"Durchschnittliche Korrelationen pro Korrelationstyp (n={len(summary_df)}, Stand: {current_date}) | Quelle: {global_bib_filename.replace('.bib', '')}", labels={"Korrelationstyp": "Korrelationstyp", "Durchschnittliche Korrelation": "Durchschnittliche Korrelation"}, color="Durchschnittliche Korrelation", color_continuous_scale=[ @@ -718,7 +729,7 @@ def plot_average_correlation_plotly(summary_df): fig.update_layout( get_standard_layout( - title=f"Durchschnittliche Korrelationen pro Korrelationstyp (n={len(summary_df)}, Stand: {current_date}) | Quelle: {bib_filename.replace('.bib', '')}", + title=f"Durchschnittliche Korrelationen pro Korrelationstyp (n={len(summary_df)}, Stand: {current_date}) | Quelle: {global_bib_filename.replace('.bib', '')}", x_title="Korrelationstyp", y_title="Durchschnittliche Korrelation" ), @@ -740,6 +751,10 @@ def plot_average_correlation_plotly(summary_df): "summary_plot", export_fig_summary_plot ) + # PNG-Export ergänzen + png_path = os.path.join(export_path_png, f"{slugify('summary_plot_' + global_bib_filename.replace('.bib', ''))}.png") + fig.write_image(png_path, width=1200, height=800, scale=2) + print(f"✅ PNG-Summary-Datei gespeichert unter: {png_path}") #============================ # Aufruf Alle möglichen bivariaten Korrelationen visualisieren diff --git a/analyse_netzwerk.py b/analyse_netzwerk.py index 8077293..8817e9f 100644 --- a/analyse_netzwerk.py +++ b/analyse_netzwerk.py @@ -66,18 +66,20 @@ from config_netzwerk import export_fig_png def export_figure_local(fig, name, flag, bib_filename=None): from config_netzwerk import export_path_html, export_path_png + # Einmalige Definition von safe_filename am Anfang der Funktion + safe_filename = prepare_figure_export(fig, name).replace(".html", "") if flag: - local_tmp_path = f"/tmp/{slugify(name)}.html" + local_tmp_path = f"/tmp/{safe_filename}.html" fig.write_html(local_tmp_path, full_html=True, include_plotlyjs="cdn") try: - subprocess.run(["scp", local_tmp_path, f"{export_path_html}/{slugify(name)}.html"], check=True) + subprocess.run(["scp", local_tmp_path, f"{export_path_html}/{safe_filename}.html"], check=True) print(f"✅ HTML-Datei erfolgreich übertragen.") os.remove(local_tmp_path) print(f"🗑️ Lokale HTML-Datei '{local_tmp_path}' wurde gelöscht.") except subprocess.CalledProcessError as e: print("❌ Fehler bei der Übertragung via SCP:", e) if export_fig_png: - png_path = os.path.join(export_path_png, f"{slugify(name)}.png") + png_path = os.path.join(export_path_png, f"{safe_filename}.png") try: fig.write_image(png_path, width=1200, height=800, scale=2) print(f"✅ PNG-Datei exportiert nach: {png_path}") diff --git a/deskriptive-literaturauswahl.py b/deskriptive-literaturauswahl.py index f7f0308..d942ea3 100644 --- a/deskriptive-literaturauswahl.py +++ b/deskriptive-literaturauswahl.py @@ -152,8 +152,8 @@ fig.update_layout(**layout) # --- Export-Funktion --- def export_figure(fig, name, export_flag_html, export_flag_png): - from config_deskriptive_literaturauswahl import export_path_png, export_path_html - safe_name = name.replace(" ", "_").replace("/", "_").lower() + from slugify import slugify + safe_name = slugify(name) html_path = f"/tmp/{safe_name}.html" if export_flag_html: fig.write_html(html_path, include_plotlyjs='cdn', config={"responsive": True}) @@ -175,4 +175,5 @@ def export_figure(fig, name, export_flag_html, export_flag_png): # --- Export --- export_figure(fig, "silhouette_scores_und_fallzahlen", export_fig_silhouette_plot, export_fig_png) + fig.show()