File size: 2,842 Bytes
0399906
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pandas as pd


    
def get_all_heating_systems() -> list[str]:
    """

    Returns a list of available heating systems.

    Currently returns a static list. Will be loaded from CSV in the future.

    """
    return [
        "Luft-Wasser Wärmepumpe",
        "Wasser-Wasser Wärmepumpe",
        "Sole-Wasser Wärmepumpe",
        "Pelletheizung",
        "Holzhackschnitzelheizung",
        "Wasserstoffheizung",
        "Gasheizung",
        "Ölheizung"
    ]

COLUMN_MAP_INPUT = {
    "Objekt-ID": "object_id",
    "Object-ID": "object_id",
          
    "Wohnflaeche": "floor_area",
    "Wohnfläche": "floor_area",
    "Living area": "floor_area",
            
    "Baujahr": "year_built",
    "Year built": "year_built",
            
    "Gesamtwaermebedarf": "heat_demand",
    "Gesamtwärmebedarf": "heat_demand",
    "Total heat demand": "heat_demand",
            
    "spezifischer Waermebedarf": "specific_demand",
    "spezifischer Wärmebedarf": "specific_demand",
    "Specific heat demand": "specific_demand",
    
    "Heizlast" : "heat_load",
    "Heat load": "heat_load",
}



def map_input_columns(df, column_map):
    df_ = df.copy()
    df_.rename(columns=column_map, inplace = True)
    return df_



def get_multilang_scenario_choices(df, lang="de"):
    """

    Gibt Liste von (Anzeigename, ID) für Radio/Selectbox.

    """
    col = f"Szenario_{lang.upper()}"
    return [(row[col], row["Szenario_ID"]) for _, row in df.iterrows()]



def get_scenario_row(df, szenario_id):
    """

    Gibt vollständigen Szenario-Row als Series (oder None) für gegebene ID zurück.

    """
    matches = df[df["Szenario_ID"] == szenario_id]
    return matches.iloc[0] if not matches.empty else None



def get_selected_scenario(scenario_df, lang, scenario):
    scenario_row = scenario_df[scenario_df[f"Szenario_{lang.upper()}"] == scenario]
    if not scenario_row.empty:
        scen_values = scenario_row.iloc[0].to_dict()
        scen_id = scen_values.get("Szenario_ID", "A")
    else:
        scen_values = {}
        scen_id = "A"
    return scen_values, scen_id



def parsefloat(cell):
    try:
        if pd.isnull(cell) or (isinstance(cell, str) and not cell.strip()):
            return None
        return float(str(cell).replace(",", "."))
    except Exception:
        return None



def float_to_comma(value):
    try:
        if value is None:
            return ""
        return str(value).replace(".", ",")
    except Exception:
        return ""



def apply_technology_name_language(df, ui):
    if df is None or "Name" not in df.columns:
        return df
    name_map = ui["technology_names"]
    df = df.copy()
    df["Name"] = df["Name"].map(lambda n: name_map.get(n, n))
    return df