File size: 1,209 Bytes
97fbb1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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))