- Updated the `get_activity_detail` function to include session metrics in the activity detail output, allowing for enriched data representation. - Refactored the activity import logic to streamline the process of inserting and updating activity records, utilizing new helper functions for better maintainability. - Improved the handling of duplicate activity entries by implementing a more robust identification mechanism. - Enhanced the metadata for activity detail registration to reflect the inclusion of EAV metrics and updated source tables.
31 lines
950 B
Python
31 lines
950 B
Python
"""
|
|
Einheitliche Startzeit-Normalisierung für Aktivität (CSV, Legacy-Import, Dedupe).
|
|
|
|
Anbieter-agnostisch: beliebige ISO-/Export-Strings über dateutil.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import time as dt_time
|
|
from typing import Optional
|
|
|
|
from dateutil import parser as du_parser
|
|
|
|
|
|
def normalize_activity_start(start_raw: str) -> tuple[str, Optional[dt_time]]:
|
|
"""
|
|
Roh-String „Start“ aus Exporten → (YYYY-MM-DD, TIME ohne μs) für DB Dedupe/INSERT.
|
|
|
|
Leerer Input → ("", None). Fallback bei Parse-Fehler: erstes Datum aus ersten 10 Zeichen.
|
|
"""
|
|
s = (start_raw or "").strip()
|
|
if not s:
|
|
return "", None
|
|
try:
|
|
parsed = du_parser.parse(s, dayfirst=False)
|
|
t = parsed.time().replace(microsecond=0)
|
|
return parsed.date().isoformat(), t
|
|
except (ValueError, TypeError, OverflowError):
|
|
if len(s) >= 10:
|
|
return s[:10], None
|
|
return "", None
|