Spaces:
Sleeping
Sleeping
| \ | |
| from typing import Dict | |
| def free_staffed_beds(staffed_capacity: int, current_occupied: int) -> int: | |
| return max(0, staffed_capacity - current_occupied) | |
| def beds_needed_to_clear(ed_waiting: int, free_now: int, surge_buffer: int = 0) -> int: | |
| return max(0, ed_waiting - free_now) + max(0, surge_buffer) | |
| def discharge_goal(today_ready: int, by_noon_ratio: float = 0.6) -> int: | |
| return max(0, int(round(today_ready * by_noon_ratio))) | |
| def compute_operational_numbers(snapshot: Dict) -> Dict: | |
| staffed_capacity = int(snapshot.get("beds_total", 0) * (snapshot.get("staffed_ratio", 1.0))) | |
| current_occupied = int(snapshot.get("beds_total", 0) * snapshot.get("occupied_pct", 0)) | |
| free_now = free_staffed_beds(staffed_capacity or snapshot.get("beds_total", 0), current_occupied) | |
| ed_waiting = int(snapshot.get("ed_admits_waiting", 0)) | |
| forecast = snapshot.get("forecast_admits_next_24h", {}) | |
| surge_buffer = int(round((forecast.get("respiratory", 0) + forecast.get("other", 0)) * 0.4)) | |
| need_now = beds_needed_to_clear(ed_waiting, free_now, surge_buffer=surge_buffer) | |
| noon_goal = discharge_goal(int(snapshot.get("discharge_ready_today", 0))) | |
| return { | |
| "staffed_capacity": staffed_capacity or snapshot.get("beds_total", 0), | |
| "current_occupied": current_occupied, | |
| "free_staffed_beds_now": free_now, | |
| "beds_needed_to_clear_now_plus_buffer": need_now, | |
| "target_noon_discharges": noon_goal, | |
| "surge_buffer_estimate": surge_buffer, | |
| } | |