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

+9 -1
View File
@@ -24,6 +24,7 @@ from csv_parser.core import (
normalize_header_for_signature,
parse_csv_sample,
)
from csv_parser.field_units import source_unit_choices_for_field
from csv_parser.module_registry import get_module_definition, list_modules, validate_field_mappings
from csv_parser.sleep_apple_import import detect_apple_sleep_csv_format
@@ -60,11 +61,18 @@ def csv_modules(session: dict = Depends(require_auth)):
for mid in list_modules():
d = get_module_definition(mid)
if d:
fields_out = {}
for fname, finfo in (d.get("fields") or {}).items():
fd = dict(finfo)
opts = source_unit_choices_for_field(mid, fname)
if opts:
fd["source_unit_options"] = opts
fields_out[fname] = fd
out.append(
{
"id": mid,
"table": d["table"],
"fields": d["fields"],
"fields": fields_out,
"import_mode": d.get("import_mode"),
}
)