Afifa Kureshi commited on
Commit
c2cba45
·
1 Parent(s): 4ed4736

Final dynamic scoring fix for Phase 2

Browse files
Files changed (1) hide show
  1. grader/grader.py +49 -25
grader/grader.py CHANGED
@@ -240,37 +240,61 @@ def print_report(report: dict):
240
 
241
  print("=" * 60 + "\n")
242
 
243
- # ------------------------------------------------------------------
244
- # OpenEnv compatibility wrapper
245
- # ------------------------------------------------------------------
246
-
247
  def grade_state(fs, task_name):
248
- """
249
- Convert your existing grader output into
250
- OpenEnv reward format (0.0–1.0)
251
- """
252
 
253
- # Get current filesystem state
254
- final_state = fs.get_state()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
 
256
- # Use the same initial state
257
- initial_state = fs.initial_state
258
 
259
- # Get task criteria from config or task loader
260
- criteria = fs.criteria
261
 
262
- grader = Grader(
263
- task_type=task_name,
264
- initial_state=initial_state,
265
- criteria=criteria
266
- )
267
 
268
- report = grader.grade(final_state)
269
 
270
- # Convert percentage to reward
271
- reward = report["percentage"] / 100.0
 
272
 
273
- # Ensure valid range
274
- reward = max(0.0, min(1.0, reward))
275
 
276
- return reward
 
240
 
241
  print("=" * 60 + "\n")
242
 
 
 
 
 
243
  def grade_state(fs, task_name):
 
 
 
 
244
 
245
+ files = fs.list_files()
246
+
247
+ total = len(files)
248
+
249
+ if total == 0:
250
+ return 0.5
251
+
252
+ progress = 0
253
+
254
+ # EASY — files moved to Documents
255
+ if task_name == "easy":
256
+
257
+ for f in files:
258
+
259
+ path = f.get("path", "")
260
+
261
+ if "Documents" in path:
262
+
263
+ progress += 1
264
+
265
+ # MEDIUM — duplicates removed
266
+ elif task_name == "medium":
267
+
268
+ names = set()
269
+
270
+ for f in files:
271
+
272
+ names.add(f.get("name"))
273
+
274
+ progress = len(names)
275
+
276
+ # HARD — storage reduction
277
+ elif task_name == "hard":
278
+
279
+ initial_files = fs.initial_state.get("root", {})
280
+
281
+ initial_count = len(initial_files)
282
+
283
+ current_count = total
284
 
285
+ progress = max(0, initial_count - current_count)
 
286
 
287
+ else:
 
288
 
289
+ progress = total // 2
 
 
 
 
290
 
291
+ score = progress / max(total, 1)
292
 
293
+ # Keep strictly between 0 and 1
294
+ if score <= 0:
295
+ score = 0.05
296
 
297
+ if score >= 1:
298
+ score = 0.95
299
 
300
+ return round(score, 2)