Promotion: Exportfunktion für scp-Export in export_figure_local integriert
This commit is contained in:
@ -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
|
||||
|
||||
@ -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}")
|
||||
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user