Upload model.py
Browse files
model.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TypedDict
|
| 2 |
+
|
| 3 |
+
class WindowSafety(TypedDict):
|
| 4 |
+
should_close: bool
|
| 5 |
+
reason: str
|
| 6 |
+
|
| 7 |
+
def check_window_safety(weather: str, time_hour: int, room: str) -> WindowSafety:
|
| 8 |
+
"""Simple safety rule for windows.
|
| 9 |
+
|
| 10 |
+
- Close when it's raining or very windy.
|
| 11 |
+
- Close bedroom and front-facing windows at night.
|
| 12 |
+
"""
|
| 13 |
+
w = weather.lower()
|
| 14 |
+
r = room.lower()
|
| 15 |
+
|
| 16 |
+
if "rain" in w or "raining" in w or "storm" in w:
|
| 17 |
+
return {
|
| 18 |
+
"should_close": True,
|
| 19 |
+
"reason": "Outside weather indicates rain or storm.",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
if "windy" in w and time_hour >= 22:
|
| 23 |
+
return {
|
| 24 |
+
"should_close": True,
|
| 25 |
+
"reason": "Windy conditions at night, better to close windows.",
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
if time_hour >= 23 or time_hour < 6:
|
| 29 |
+
if r in {"bedroom", "front", "living_room"}:
|
| 30 |
+
return {
|
| 31 |
+
"should_close": True,
|
| 32 |
+
"reason": "Night time; keep main windows closed for safety.",
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
"should_close": False,
|
| 37 |
+
"reason": "Conditions look safe to keep the window open.",
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
tests = [
|
| 42 |
+
("sunny", 21, "living_room"),
|
| 43 |
+
("raining", 15, "kitchen"),
|
| 44 |
+
("windy", 23, "bedroom"),
|
| 45 |
+
]
|
| 46 |
+
for w, h, r in tests:
|
| 47 |
+
print(w, h, r, "->", check_window_safety(w, h, r))
|