Spaces:
Paused
Paused
Commit
·
5316350
1
Parent(s):
d1af8dc
feat: update score
Browse files- web_server.py +25 -4
web_server.py
CHANGED
@@ -118,11 +118,11 @@ def upload_submission_info(team_id: str, user_submission_info: Dict[str, Any]):
|
|
118 |
)
|
119 |
|
120 |
|
121 |
-
def
|
122 |
user_submission_info = download_submission_info(team_id)
|
123 |
for submission in user_submission_info["submissions"]:
|
124 |
if submission["submission_id"] == submission_id:
|
125 |
-
submission
|
126 |
break
|
127 |
upload_submission_info(team_id, user_submission_info)
|
128 |
|
@@ -314,6 +314,26 @@ class EnvHandler:
|
|
314 |
with self._lock:
|
315 |
self._log_list.append(log_message)
|
316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
class EnvHandlerManager:
|
319 |
def __init__(self):
|
@@ -417,7 +437,7 @@ def _get_env_handler(
|
|
417 |
|
418 |
submission_id = token_info["submission_id"]
|
419 |
if not env_manager.exists_env_handler(submission_id):
|
420 |
-
|
421 |
|
422 |
env_handler = env_manager.get_env_handler(submission_id)
|
423 |
if env_handler is None:
|
@@ -487,7 +507,8 @@ def execute_action_endpoint(
|
|
487 |
token_info = get_token_info(auth_token)
|
488 |
env_manager.close_env_handler(token_info["submission_id"])
|
489 |
delete_client_space(token_info["client_space_id"])
|
490 |
-
|
|
|
491 |
hf_api.upload_folder(
|
492 |
repo_id=COMPETITION_ID,
|
493 |
folder_path=env_handler.base_output,
|
|
|
118 |
)
|
119 |
|
120 |
|
121 |
+
def update_submission_data(team_id: str, submission_id: str, data: Dict[str, Any]):
|
122 |
user_submission_info = download_submission_info(team_id)
|
123 |
for submission in user_submission_info["submissions"]:
|
124 |
if submission["submission_id"] == submission_id:
|
125 |
+
submission.update(data)
|
126 |
break
|
127 |
upload_submission_info(team_id, user_submission_info)
|
128 |
|
|
|
314 |
with self._lock:
|
315 |
self._log_list.append(log_message)
|
316 |
|
317 |
+
def calculate_score(self) -> Dict[str, Any]:
|
318 |
+
"""
|
319 |
+
Calculate the score based on the current environment state.
|
320 |
+
Returns:
|
321 |
+
Dict[str, Any]: The score dictionary.
|
322 |
+
"""
|
323 |
+
if not self._done:
|
324 |
+
raise ValueError("Environment is not done yet. Cannot calculate score.")
|
325 |
+
|
326 |
+
all_score_json = []
|
327 |
+
for scene_config in self.scene_list:
|
328 |
+
scene_output = os.path.join(self.base_output, scene_config.name)
|
329 |
+
with open(os.path.join(scene_output, 'eval.json'), 'r') as f:
|
330 |
+
score_json = json.load(f)
|
331 |
+
all_score_json.append(score_json)
|
332 |
+
|
333 |
+
rc = np.mean([score['rc'] for score in all_score_json]).round(4)
|
334 |
+
hdscore = np.mean([score['hdscore'] for score in all_score_json]).round(4)
|
335 |
+
return {"rc": rc, "hdscore": hdscore}
|
336 |
+
|
337 |
|
338 |
class EnvHandlerManager:
|
339 |
def __init__(self):
|
|
|
437 |
|
438 |
submission_id = token_info["submission_id"]
|
439 |
if not env_manager.exists_env_handler(submission_id):
|
440 |
+
update_submission_data(token_info["team_id"], submission_id, {"status": SubmissionStatus.PROCESSING.value})
|
441 |
|
442 |
env_handler = env_manager.get_env_handler(submission_id)
|
443 |
if env_handler is None:
|
|
|
507 |
token_info = get_token_info(auth_token)
|
508 |
env_manager.close_env_handler(token_info["submission_id"])
|
509 |
delete_client_space(token_info["client_space_id"])
|
510 |
+
final_score = env_handler.calculate_score()
|
511 |
+
update_submission_data(token_info["team_id"], token_info["submission_id"], {"status": SubmissionStatus.SUCCESS.value, "score": final_score})
|
512 |
hf_api.upload_folder(
|
513 |
repo_id=COMPETITION_ID,
|
514 |
folder_path=env_handler.base_output,
|