Spaces:
Sleeping
Sleeping
Subhash Vadaparthi commited on
Commit Β·
2e8afb0
1
Parent(s): 1022124
fix: guard against division-by-zero and ensure grader NEVER returns 0.0 or 1.0 - reset env at startup, add NaN protection, fix empty-state defaults
Browse filesFiles changed (2)
- server/app.py+15-3
- tasks.py+24-13
80 unmodified lines8182838485868761 unmodified lines14915015115215315415515615715815916016116216316416515415515616616716816917017180 unmodified lines
_env = HealthcareEnvironment()_env.reset() # MUST reset at startup so grader has valid patient data
# ββ Root / health endpoints (always needed) βββββββββββββββββββββββββ61 unmodified lines@app.get("/grader")def get_grader_scores(): """Grade the current episode across all tasks.""" def safe_score(fn): """Ensure score is always strictly between 0 and 1.""" try: s = fn() s = float(s) if s != s: # NaN return 0.5 return min(max(s, 0.01), 0.99) except Exception: return 0.5
grader = TaskGrader(_env) return { "task_scores": { "task_1": grader.grade_task_1(), "task_2": grader.grade_task_2(), "task_3": grader.grade_task_3(), "task_1": safe_score(grader.grade_task_1), "task_2": safe_score(grader.grade_task_2), "task_3": safe_score(grader.grade_task_3), } }
16 unmodified lines17181920212021222324252627282930312832333034353637382 unmodified lines414243394041444546474849505152531 unmodified line55565758594950606162525363646566566768697071617273747516 unmodified lines self.env = env
def _clamp(self, score: float) -> float: """Clamp score to strictly (0, 1) range.""" return min(max(score, 0.01), 0.99) """Clamp score to strictly (0, 1) range β never exactly 0.0 or 1.0.""" if score != score: # NaN check return 0.5 return min(max(float(score), 0.01), 0.99)
def grade_task_1(self) -> float: """ Task 1 (Easy): successfully book an appointment when slots are available. Score based on number of waiting patients booked. """ if not self.env.patients: return 0.5 # No patients = default mid-range score booked_count = sum(1 for p in self.env.patients.values() if p["status"] == "booked") booked_count = sum(1 for p in self.env.patients.values() if p.get("status") == "booked") total_patients = len(self.env.patients) # 50% booking is enough for full score here if total_patients == 0: return 0.5 raw_score = booked_count / (total_patients * 0.5) return self._clamp(raw_score)
2 unmodified lines Task 2 (Medium): Handle scheduling conflicts and rescheduling. Score based on rescheduling success and slot utilization. """ booked_count = sum(1 for p in self.env.patients.values() if p["status"] == "booked") # In Task 2, we expect some rescheduling to happen. raw_score = booked_count / (len(self.env.patients) * 0.7) if not self.env.patients: return 0.5 booked_count = sum(1 for p in self.env.patients.values() if p.get("status") == "booked") total_patients = len(self.env.patients) if total_patients == 0: return 0.5 raw_score = booked_count / (total_patients * 0.7) return self._clamp(raw_score)
def grade_task_3(self) -> float:1 unmodified line Task 3 (Hard): Optimize scheduling for multiple patients with different priorities. Score based on priority completion. Priority 1 should be booked FIRST. """ if not self.env.patients: return 0.5 p1_total = sum(1 for p in self.env.patients.values() if p["priority"] == 1) p1_booked = sum(1 for p in self.env.patients.values() if p["priority"] == 1 and p["status"] == "booked") p1_total = sum(1 for p in self.env.patients.values() if p.get("priority") == 1) p1_booked = sum(1 for p in self.env.patients.values() if p.get("priority") == 1 and p.get("status") == "booked") p2_total = sum(1 for p in self.env.patients.values() if p["priority"] == 2) p2_booked = sum(1 for p in self.env.patients.values() if p["priority"] == 2 and p["status"] == "booked") p2_total = sum(1 for p in self.env.patients.values() if p.get("priority") == 2) p2_booked = sum(1 for p in self.env.patients.values() if p.get("priority") == 2 and p.get("status") == "booked") if p1_total == 0: p1_score = 1.0 p1_score = 0.5 else: p1_score = p1_booked / p1_total
if p2_total == 0: p2_score = 1.0 p2_score = 0.5 else: p2_score = p2_booked / p2_total server/app.py+15-3
tasks.py+24-13