feat(csv-import): Refactor CSV import logic and enhance data handling
Deploy Development / deploy (push) Successful in 48s
Build Test / pytest-backend-csv (push) Failing after 3s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s

- Updated the CSV import architecture to clarify the distinction between import and data layer responsibilities, as outlined in the new section of ARCHITECTURE.md.
- Enhanced the build_row_after_mapping function to include module-specific context for improved data processing.
- Introduced source unit options in the admin CSV template editor to facilitate user-defined conversions, improving flexibility in handling various data formats.
- Added new tests to validate the handling of source units and ensure accurate conversions during CSV imports.
- Updated module definitions to include unit specifications for nutritional and activity data fields, enhancing data integrity.
This commit is contained in:
Lars committed 2026-04-10 09:54:32 +02:00
1 parent 41cc0ed2a8
commit d6d7e738a5
10 files changed
+324 -27

No files matched your search

+5 -5
View File
@@ -200,7 +200,7 @@ def _import_nutrition(
rows_total = 0
for csv_row in iter_csv_dict_rows(text, delim, has_header=has_header):
rows_total += 1
mapped = build_row_after_mapping(csv_row, fm, tc)
mapped = build_row_after_mapping(csv_row, fm, tc, module="nutrition")
d = coerce_date(mapped.get("date"))
if d is None:
error_details.append({"row": rows_total, "error": "Datum fehlt oder ungültig"})
@@ -283,7 +283,7 @@ def _import_weight(
new_entries = 0
for csv_row in iter_csv_dict_rows(text, delim, has_header=has_header):
rows_total += 1
mapped = build_row_after_mapping(csv_row, fm, tc)
mapped = build_row_after_mapping(csv_row, fm, tc, module="weight")
d = coerce_date(mapped.get("date"))
w = mapped.get("weight")
note = mapped.get("note")
@@ -356,7 +356,7 @@ def _import_blood_pressure(
skipped = 0
for csv_row in iter_csv_dict_rows(text, delim, has_header=has_header):
rows_total += 1
mapped = build_row_after_mapping(csv_row, fm, tc)
mapped = build_row_after_mapping(csv_row, fm, tc, module="blood_pressure")
md = coerce_date(mapped.get("measured_date"))
mt = mapped.get("measured_time")
if md is None:
@@ -483,7 +483,7 @@ def _import_vitals_baseline(
skipped = 0
for csv_row in iter_csv_dict_rows(text, delim, has_header=has_header):
rows_total += 1
mapped = build_row_after_mapping(csv_row, fm, tc)
mapped = build_row_after_mapping(csv_row, fm, tc, module="vitals_baseline")
d = coerce_date(mapped.get("date"))
if d is None:
error_details.append({"row": rows_total, "error": "Datum fehlt"})
@@ -581,7 +581,7 @@ def _import_activity(
for csv_row in iter_csv_dict_rows(text, delim, has_header=has_header):
rows_total += 1
mapped = build_row_after_mapping(csv_row, fm, tc)
mapped = build_row_after_mapping(csv_row, fm, tc, module="activity")
activity_type = mapped.get("activity_type")
if not activity_type or not str(activity_type).strip():
error_details.append({"row": rows_total, "error": "Trainingsart fehlt"})