Promotion: fix(export): HTML-Export robust gegen Netzwerkpfade überarbeitet
This commit is contained in:
@ -1,8 +1,33 @@
|
||||
|
||||
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)
|
||||
remote_path = "johajo@sternenflottenakademie.local:/mnt/deep-space-nine/public/plot/promotion/"
|
||||
|
||||
if export_flag_html:
|
||||
export_path_html = f"/tmp/{safe_filename}.html"
|
||||
fig.write_html(export_path_html, full_html=True, include_plotlyjs="cdn")
|
||||
try:
|
||||
subprocess.run(["scp", export_path_html, remote_path], check=True)
|
||||
print(f"✅ HTML-Datei '{export_path_html}' erfolgreich übertragen.")
|
||||
os.remove(export_path_html)
|
||||
print(f"🗑️ Lokale HTML-Datei '{export_path_html}' wurde gelöscht.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("❌ Fehler beim HTML-Übertragen:")
|
||||
print(e.stderr)
|
||||
|
||||
if export_flag_png:
|
||||
export_path_png = 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}'")
|
||||
except Exception as e:
|
||||
print("❌ Fehler beim PNG-Export:", str(e))
|
||||
|
||||
# Import theme and all export_fig_... variables from central config before any use
|
||||
from ci_template.plotly_template import export_figure
|
||||
from config_korrelation import (
|
||||
theme,
|
||||
export_fig_visual,
|
||||
@ -19,7 +44,8 @@ from config_korrelation import (
|
||||
export_fig_correlation_kategorien_kategorien,
|
||||
export_fig_correlation_indizes_indizes,
|
||||
export_fig_summary_plot,
|
||||
bib_filename
|
||||
bib_filename,
|
||||
export_path_html
|
||||
)
|
||||
|
||||
# Terminal leeren
|
||||
@ -61,7 +87,12 @@ def prepare_figure_export(fig, name):
|
||||
return f"{safe_filename}.html"
|
||||
|
||||
def export_and_transfer_figure(fig, function_name, export_flag):
|
||||
export_figure(fig, function_name, export_flag, export_fig_png)
|
||||
export_figure(
|
||||
fig,
|
||||
function_name,
|
||||
export_flag,
|
||||
export_fig_png
|
||||
)
|
||||
fig.show()
|
||||
|
||||
# BibTeX-Datei laden
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
|
||||
from config_netzwerk import theme, export_fig_visual, bib_filename
|
||||
|
||||
from ci_template.plotly_template import export_figure as export_figure_ci
|
||||
|
||||
import os
|
||||
|
||||
@ -66,7 +65,24 @@ from config_netzwerk import (
|
||||
from config_netzwerk import export_fig_png
|
||||
|
||||
def export_figure_local(fig, name, flag, bib_filename=None):
|
||||
export_figure_ci(fig, name, flag, export_fig_png)
|
||||
from config_netzwerk import export_path_html, export_path_png
|
||||
if flag:
|
||||
local_tmp_path = f"/tmp/{slugify(name)}.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)
|
||||
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")
|
||||
try:
|
||||
fig.write_image(png_path, width=1200, height=800, scale=2)
|
||||
print(f"✅ PNG-Datei exportiert nach: {png_path}")
|
||||
except Exception as e:
|
||||
print("❌ Fehler beim PNG-Export:", str(e))
|
||||
|
||||
from ci_template.plotly_template import get_colors, get_plot_styles, get_standard_layout
|
||||
|
||||
|
||||
@ -3,13 +3,14 @@
|
||||
# ===============================
|
||||
|
||||
# --- System- und Modul-Imports ---
|
||||
import os
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import plotly.graph_objects as go
|
||||
from datetime import date
|
||||
from scipy.stats.mstats import winsorize
|
||||
from scipy.stats import iqr
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
# --- CI-Template & Konfiguration ---
|
||||
from ci_template.plotly_template import (
|
||||
@ -17,9 +18,14 @@ from ci_template.plotly_template import (
|
||||
get_colors,
|
||||
set_theme
|
||||
)
|
||||
from ci_template.plotly_template import export_figure
|
||||
from config_deskriptive_literaturauswahl import theme, export_fig_visual
|
||||
from config_deskriptive_literaturauswahl import export_fig_png, export_fig_silhouette_plot
|
||||
from config_deskriptive_literaturauswahl import (
|
||||
theme,
|
||||
export_fig_visual,
|
||||
export_fig_png,
|
||||
export_fig_silhouette_plot,
|
||||
export_path_html,
|
||||
export_path_png
|
||||
)
|
||||
|
||||
# --- Initialisierung ---
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
@ -143,9 +149,30 @@ layout["legend"] = dict(
|
||||
)
|
||||
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()
|
||||
html_path = f"/tmp/{safe_name}.html"
|
||||
if export_flag_html:
|
||||
fig.write_html(html_path, include_plotlyjs='cdn', config={"responsive": True})
|
||||
try:
|
||||
subprocess.run(["scp", html_path, export_path_html], check=True)
|
||||
print(f"✅ HTML-Datei '{html_path}' erfolgreich übertragen.")
|
||||
os.remove(html_path)
|
||||
print(f"🗑️ Lokale HTML-Datei '{html_path}' wurde gelöscht.")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("❌ Fehler beim HTML-Übertragen:")
|
||||
print(e.stderr)
|
||||
if export_flag_png:
|
||||
png_path = os.path.join(export_path_png, f"{safe_name}.png")
|
||||
try:
|
||||
fig.write_image(png_path, scale=2)
|
||||
print(f"✅ PNG-Datei lokal gespeichert: '{png_path}'")
|
||||
except Exception as e:
|
||||
print("❌ Fehler beim PNG-Export:", str(e))
|
||||
|
||||
# --- Export ---
|
||||
export_figure(fig, "silhouette_scores_und_fallzahlen", export_fig_silhouette_plot, export_fig_png)
|
||||
|
||||
# (Hinweis: Balkenfarbe wird direkt im Bar-Trace gesetzt)
|
||||
|
||||
fig.show(config={"responsive": True})
|
||||
fig.show()
|
||||
|
||||
Reference in New Issue
Block a user