fix: Stellenanteil in Prozentangabe und jeweiliges Monatsende als Datum eintragen
This commit is contained in:
1 parent
0d390f79b4
commit
b05849e673
4 files changed
+38
-19
No files matched your search
+25
-11
@@ -17,16 +17,6 @@ def _to_text(value: Any) -> str:
|
||||
return str(value).strip()
|
||||
|
||||
|
||||
def _to_float(value: Any, field_name: str) -> float:
|
||||
if value is None or str(value).strip() == "":
|
||||
return 0.0
|
||||
text = str(value).strip().replace(",", ".")
|
||||
try:
|
||||
return float(text)
|
||||
except ValueError:
|
||||
return 0.0
|
||||
|
||||
|
||||
def _to_int_or_none(value: Any) -> Optional[int]:
|
||||
if value is None or str(value).strip() == "":
|
||||
return None
|
||||
@@ -36,6 +26,29 @@ def _to_int_or_none(value: Any) -> Optional[int]:
|
||||
return None
|
||||
|
||||
|
||||
def _to_percent_string(value: Any) -> str:
|
||||
"""Wandelt einen Prozentwert in einen String ohne %-Zeichen um.
|
||||
|
||||
Excel speichert Prozentwerte als Dezimalbruch (50 % = 0.5).
|
||||
Falls der Rohwert eine Zahl ≤ 1 ist, wird er als Excel-Prozentwert
|
||||
interpretiert und mit 100 multipliziert.
|
||||
"""
|
||||
if value is None or str(value).strip() == "":
|
||||
return ""
|
||||
# Falls es bereits ein String mit %-Zeichen ist
|
||||
if isinstance(value, str):
|
||||
return value.strip().rstrip("% ")
|
||||
# Numerischer Wert: Excel-Prozentwert (0.5 = 50 %) oder Ganzzahl (50 = 50 %)
|
||||
if isinstance(value, (int, float)):
|
||||
if 0 < value <= 1:
|
||||
return str(int(value * 100))
|
||||
if value == 0:
|
||||
return "0"
|
||||
# Wert > 1: bereits als Ganzzahl gemeint (z. B. 50)
|
||||
return str(int(value))
|
||||
return str(value).strip()
|
||||
|
||||
|
||||
def _build_column_map(schema: list[FieldSchema]) -> dict[str, int]:
|
||||
"""Baut ein Mapping von field_name → 0-basierter Spaltenindex."""
|
||||
col_map: dict[str, int] = {}
|
||||
@@ -78,7 +91,8 @@ def parse_input_file(
|
||||
|
||||
qualifikation = _to_text(row[col_map.get("Qualifikation", 0)]) if len(row) > col_map.get("Qualifikation", 0) else ""
|
||||
funktion = _to_text(row[col_map.get("Funktion", 0)]) if len(row) > col_map.get("Funktion", 0) else ""
|
||||
stellenanteil = _to_float(row[col_map.get("Stellenanteil in %", 0)], "Stellenanteil in %") if len(row) > col_map.get("Stellenanteil in %", 0) else 0.0
|
||||
stellenanteil_raw = row[col_map.get("Stellenanteil in %", 0)] if len(row) > col_map.get("Stellenanteil in %", 0) else None
|
||||
stellenanteil = _to_percent_string(stellenanteil_raw)
|
||||
monat = _to_text(row[col_map.get("Monat (MM.JJ)", 0)]) if len(row) > col_map.get("Monat (MM.JJ)", 0) else ""
|
||||
taetigkeit = _to_text(row[col_map.get("Tätigkeit", 0)]) if len(row) > col_map.get("Tätigkeit", 0) else ""
|
||||
record_id = _to_int_or_none(row[col_map.get("ID", 0)]) if len(row) > col_map.get("ID", 0) else None
|
||||
|
||||
Reference in new issue
Block a user