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 lines81828384858661 unmodified lines14814915015115215315415515615715815980 unmodified lines_env = HealthcareEnvironment()# ββ Root / health endpoints (always needed) βββββββββββββββββββββββββ61 unmodified lines@app.get("/grader")def get_grader_scores():"""Grade the current episode across all tasks."""grader = TaskGrader(_env)return {"task_scores": {"task_1": grader.grade_task_1(),"task_2": grader.grade_task_2(),"task_3": grader.grade_task_3(),}}80 unmodified lines8182838485868761 unmodified lines14915015115215315415515615715815916016116216316416516616716816917017180 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: # NaNreturn 0.5return min(max(s, 0.01), 0.99)except Exception:return 0.5grader = TaskGrader(_env)return {"task_scores": {"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 lines17181920212223242526272829303132332 unmodified lines3637383940414243441 unmodified line4647484950515253545556575859606162636416 unmodified linesself.env = envdef _clamp(self, score: float) -> float:"""Clamp score to strictly (0, 1) range."""return min(max(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."""booked_count = sum(1 for p in self.env.patients.values() if p["status"] == "booked")total_patients = len(self.env.patients)# 50% booking is enough for full score hereraw_score = booked_count / (total_patients * 0.5)return self._clamp(raw_score)2 unmodified linesTask 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)return self._clamp(raw_score)def grade_task_3(self) -> float:1 unmodified lineTask 3 (Hard): Optimize scheduling for multiple patients with different priorities.Score based on priority completion. Priority 1 should be booked FIRST."""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")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")if p1_total == 0:p1_score = 1.0else:p1_score = p1_booked / p1_totalif p2_total == 0:p2_score = 1.0else:p2_score = p2_booked / p2_total16 unmodified lines171819202122232425262728293031323334353637382 unmodified lines414243444546474849505152531 unmodified line55565758596061626364656667686970717273747516 unmodified linesself.env = envdef _clamp(self, score: float) -> float:"""Clamp score to strictly (0, 1) range β never exactly 0.0 or 1.0."""if score != score: # NaN checkreturn 0.5return 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 scorebooked_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.5raw_score = booked_count / (total_patients * 0.5)return self._clamp(raw_score)2 unmodified linesTask 2 (Medium): Handle scheduling conflicts and rescheduling.Score based on rescheduling success and slot utilization."""if not self.env.patients:return 0.5booked_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.5raw_score = booked_count / (total_patients * 0.7)return self._clamp(raw_score)def grade_task_3(self) -> float:1 unmodified lineTask 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.5p1_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.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 = 0.5else:p1_score = p1_booked / p1_totalif p2_total == 0:p2_score = 0.5else:p2_score = p2_booked / p2_total
server/app.py+15-3
tasks.py+24-13