from typing import TypedDict class BatteryAdvice(TypedDict): expected_drop_pct: float safe_to_start: bool reason: str def estimate_battery_for_session(activity_type: str, duration_min: float, current_battery_pct: float) -> BatteryAdvice: """Estimate battery drop and decide if it's safe to start a session.""" at = activity_type.lower() if at == "cleaning": rate = 0.7 # percent per minute (synthetic) elif at == "mapping": rate = 0.6 elif at == "patrol": rate = 0.5 else: # idle_docked or unknown rate = 0.1 expected_drop = duration_min * rate remaining = current_battery_pct - expected_drop safe = remaining >= 20 # keep some reserve reason = f"activity={activity_type}, duration={duration_min}min, expected_drop≈{expected_drop:.1f}%." return { "expected_drop_pct": round(expected_drop, 1), "safe_to_start": safe, "reason": reason, } if __name__ == "__main__": tests = [ ("cleaning", 45, 90), ("mapping", 20, 60), ("patrol", 25, 35), ("idle_docked", 60, 30), ] for t in tests: print(t, "->", estimate_battery_for_session(*t))