Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -498,9 +498,10 @@ elif modus == "Upload csv-Datei":
|
|
| 498 |
st.session_state.batch_user_values = batch_user_values
|
| 499 |
else:
|
| 500 |
st.session_state.batch_user_values = None
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
|
|
|
| 504 |
df_out = df_input.copy()
|
| 505 |
max_count = 8
|
| 506 |
annuität_colnames = [f"Heizsystem_{i+1}" for i in range(max_count)]
|
|
@@ -508,7 +509,7 @@ elif modus == "Upload csv-Datei":
|
|
| 508 |
for name, hname in zip(annuität_colnames, hsystem_colnames):
|
| 509 |
df_out[name] = ""
|
| 510 |
df_out[hname] = ""
|
| 511 |
-
|
| 512 |
for idx, row in df_input.iterrows():
|
| 513 |
try:
|
| 514 |
nutzflaeche = row["Wohnflaeche"]
|
|
@@ -531,13 +532,17 @@ elif modus == "Upload csv-Datei":
|
|
| 531 |
df[col] = df[col].astype(str).str.replace(",", ".").str.replace("|", ".")
|
| 532 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
| 533 |
# Wenn Batch-global-Werte gesetzt sind, anwenden:
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
energiebedarf = energiebedarf_spezifisch
|
| 542 |
df["Energiebedarf"] = df.apply(lambda rowh: calculate_energiebedarf(
|
| 543 |
energiebedarf, nutzflaeche, rowh["Effizienz"]), axis=1)
|
|
@@ -561,7 +566,7 @@ elif modus == "Upload csv-Datei":
|
|
| 561 |
df_out.at[idx, hsystem_colnames[j]] = df.iloc[j]["Name"]
|
| 562 |
except Exception as e:
|
| 563 |
st.warning(f"Objekt-ID {row.get('Objekt-ID', idx)}: {e}")
|
| 564 |
-
|
| 565 |
st.success("Berechnung abgeschlossen!")
|
| 566 |
csv_buffer = io.StringIO()
|
| 567 |
df_out.to_csv(csv_buffer, sep=";", index=False)
|
|
@@ -572,8 +577,8 @@ elif modus == "Upload csv-Datei":
|
|
| 572 |
file_name="heizsysteme_batch_ergebnis.csv",
|
| 573 |
mime="text/csv"
|
| 574 |
)
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
st.markdown("---")
|
| 579 |
-
st.caption("Berechnung nach VDI 2067, Heizsystemauswahl gemäß DIN EN 15378.")
|
|
|
|
| 498 |
st.session_state.batch_user_values = batch_user_values
|
| 499 |
else:
|
| 500 |
st.session_state.batch_user_values = None
|
| 501 |
+
|
| 502 |
+
do_calc = st.button("Batch-Berechnung starten")
|
| 503 |
+
if do_calc:
|
| 504 |
+
try:
|
| 505 |
df_out = df_input.copy()
|
| 506 |
max_count = 8
|
| 507 |
annuität_colnames = [f"Heizsystem_{i+1}" for i in range(max_count)]
|
|
|
|
| 509 |
for name, hname in zip(annuität_colnames, hsystem_colnames):
|
| 510 |
df_out[name] = ""
|
| 511 |
df_out[hname] = ""
|
| 512 |
+
|
| 513 |
for idx, row in df_input.iterrows():
|
| 514 |
try:
|
| 515 |
nutzflaeche = row["Wohnflaeche"]
|
|
|
|
| 532 |
df[col] = df[col].astype(str).str.replace(",", ".").str.replace("|", ".")
|
| 533 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
| 534 |
# Wenn Batch-global-Werte gesetzt sind, anwenden:
|
| 535 |
+
batch_user_vals = st.session_state.get("batch_user_values")
|
| 536 |
+
if batch_user_vals is not None:
|
| 537 |
+
# Mapping via Name zur Sicherheit
|
| 538 |
+
preview_heizsys_names = {preview_df.loc[x, "Name"]: x for x in preview_df.index}
|
| 539 |
+
for pidx in batch_user_vals:
|
| 540 |
+
sysname = preview_df.loc[pidx, "Name"]
|
| 541 |
+
# Suche nach dem Namen im aktuellen DF
|
| 542 |
+
df_idx = df[df["Name"] == sysname].index
|
| 543 |
+
if not df_idx.empty:
|
| 544 |
+
for key in batch_user_vals[pidx]:
|
| 545 |
+
df.at[df_idx[0], key] = batch_user_vals[pidx][key]
|
| 546 |
energiebedarf = energiebedarf_spezifisch
|
| 547 |
df["Energiebedarf"] = df.apply(lambda rowh: calculate_energiebedarf(
|
| 548 |
energiebedarf, nutzflaeche, rowh["Effizienz"]), axis=1)
|
|
|
|
| 566 |
df_out.at[idx, hsystem_colnames[j]] = df.iloc[j]["Name"]
|
| 567 |
except Exception as e:
|
| 568 |
st.warning(f"Objekt-ID {row.get('Objekt-ID', idx)}: {e}")
|
| 569 |
+
|
| 570 |
st.success("Berechnung abgeschlossen!")
|
| 571 |
csv_buffer = io.StringIO()
|
| 572 |
df_out.to_csv(csv_buffer, sep=";", index=False)
|
|
|
|
| 577 |
file_name="heizsysteme_batch_ergebnis.csv",
|
| 578 |
mime="text/csv"
|
| 579 |
)
|
| 580 |
+
except Exception as e:
|
| 581 |
+
st.error(f"Fehler beim Einlesen/Berechnen: {e}")
|
| 582 |
+
|
| 583 |
+
st.markdown("---")
|
| 584 |
+
st.caption("Berechnung nach VDI 2067, Heizsystemauswahl gemäß DIN EN 15378.")
|