fix(datastore): support retroactive date logging and fix Garmin balance display logic
This commit is contained in:
@@ -474,8 +474,28 @@ class DatastoreEngine:
|
||||
start_dt = (now_dt - delta).astimezone(BERLIN_TZ)
|
||||
start_iso = start_dt.isoformat()
|
||||
elif not start:
|
||||
start_dt = now_dt.astimezone(BERLIN_TZ)
|
||||
start_iso = start_dt.isoformat()
|
||||
payload_date = payload.get("date") if isinstance(payload, dict) else None
|
||||
payload_time = payload.get("time") if isinstance(payload, dict) else None
|
||||
if payload_date:
|
||||
if payload_time:
|
||||
try:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T{payload_time}").replace(tzinfo=BERLIN_TZ)
|
||||
except Exception:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T12:00:00").replace(tzinfo=BERLIN_TZ)
|
||||
else:
|
||||
item_str = str(payload.get("item", "")).lower() if isinstance(payload, dict) else ""
|
||||
if meal == "abendessen" or "abend" in item_str or "bier" in item_str:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T20:00:00").replace(tzinfo=BERLIN_TZ)
|
||||
elif meal == "mittagessen" or "mittag" in item_str:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T12:30:00").replace(tzinfo=BERLIN_TZ)
|
||||
elif meal == "fruehstueck" or "morgen" in item_str:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T08:00:00").replace(tzinfo=BERLIN_TZ)
|
||||
else:
|
||||
start_dt = datetime.datetime.fromisoformat(f"{payload_date}T12:00:00").replace(tzinfo=BERLIN_TZ)
|
||||
start_iso = start_dt.isoformat()
|
||||
else:
|
||||
start_dt = now_dt.astimezone(BERLIN_TZ)
|
||||
start_iso = start_dt.isoformat()
|
||||
else:
|
||||
start_dt = datetime.datetime.fromisoformat(start)
|
||||
if start_dt.tzinfo is None:
|
||||
@@ -1186,6 +1206,7 @@ def run_cli():
|
||||
p_add.add_argument("--actor", default="cli", help="Reporter identifier")
|
||||
p_add.add_argument("--payload", required=True, help="JSON payload string")
|
||||
p_add.add_argument("--start", help="ISO start time")
|
||||
p_add.add_argument("--date", help="Target date YYYY-MM-DD for retroactive logging")
|
||||
p_add.add_argument("--end", help="ISO end time")
|
||||
p_add.add_argument("--since", help="Relative start offset backwards from now (e.g. '5m', '15m', '1h')")
|
||||
p_add.add_argument("--meal", help="Meal grouping")
|
||||
@@ -1232,12 +1253,25 @@ def run_cli():
|
||||
if "." not in kind:
|
||||
parser.error(f"Invalid kind '{kind}'. Expected domain.event (e.g. 'nutrition.intake', 'sleep.session', 'feeding.bottle').")
|
||||
payload = json.loads(args.payload)
|
||||
start_val = args.start
|
||||
if getattr(args, "date", None) and not start_val:
|
||||
meal_val = args.meal or ""
|
||||
item_str = str(payload.get("item", "")).lower() if isinstance(payload, dict) else ""
|
||||
if meal_val == "abendessen" or "abend" in item_str or "bier" in item_str:
|
||||
start_val = f"{args.date}T20:00:00+02:00"
|
||||
elif meal_val == "mittagessen" or "mittag" in item_str:
|
||||
start_val = f"{args.date}T12:30:00+02:00"
|
||||
elif meal_val == "fruehstueck" or "morgen" in item_str:
|
||||
start_val = f"{args.date}T08:00:00+02:00"
|
||||
else:
|
||||
start_val = f"{args.date}T12:00:00+02:00"
|
||||
|
||||
res = engine.add_event(
|
||||
kind=kind,
|
||||
subject=args.subject,
|
||||
actor=args.actor,
|
||||
payload=payload,
|
||||
start=args.start,
|
||||
start=start_val,
|
||||
end=args.end,
|
||||
since=args.since,
|
||||
meal=args.meal,
|
||||
|
||||
Reference in New Issue
Block a user