diff --git a/flatland/evaluators/aicrowd_helpers.py b/flatland/evaluators/aicrowd_helpers.py index 0d46dca01f47cf00185332a1cd0e751b9f1c8d4c..606550d521ea02e7bba305fab46e4d94163a54ab 100644 --- a/flatland/evaluators/aicrowd_helpers.py +++ b/flatland/evaluators/aicrowd_helpers.py @@ -3,6 +3,7 @@ import os import random import subprocess import uuid +import pathlib ############################################################### # Expected Env Variables @@ -11,7 +12,7 @@ import uuid # AICROWD_IS_GRADING : true # CROWDAI_IS_GRADING : true # S3_BUCKET : aicrowd-production -# S3_UPLOAD_PATH_TEMPLATE : misc/flatland-rl-Media/{}.mp4 +# S3_UPLOAD_PATH_TEMPLATE : misc/flatland-rl-Media/{} # AWS_ACCESS_KEY_ID # AWS_SECRET_ACCESS_KEY # http_proxy @@ -20,7 +21,7 @@ import uuid AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID", False) AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", False) S3_BUCKET = os.getenv("S3_BUCKET", "aicrowd-production") -S3_UPLOAD_PATH_TEMPLATE = os.getenv("S3_UPLOAD_PATH_TEMPLATE", "misc/flatland-rl-Media/{}.mp4") +S3_UPLOAD_PATH_TEMPLATE = os.getenv("S3_UPLOAD_PATH_TEMPLATE", "misc/flatland-rl-Media/{}") def get_boto_client(): @@ -62,7 +63,7 @@ def upload_random_frame_to_s3(frames_folder): if not S3_BUCKET: raise Exception("S3_BUCKET not provided...") - image_target_key = S3_UPLOAD_PATH_TEMPLATE.replace(".mp4", ".png").format(str(uuid.uuid4())) + image_target_key = (S3_UPLOAD_PATH_TEMPLATE + ".png").format(str(uuid.uuid4())) s3.put_object( ACL="public-read", Bucket=S3_BUCKET, @@ -79,14 +80,17 @@ def upload_to_s3(localpath): if not S3_BUCKET: raise Exception("S3_BUCKET not provided...") - image_target_key = S3_UPLOAD_PATH_TEMPLATE.format(str(uuid.uuid4())) + file_suffix = str(pathlib.Path(localpath).suffix) + file_target_key = (S3_UPLOAD_PATH_TEMPLATE + file_suffix).format( + str(uuid.uuid4()) + ) s3.put_object( ACL="public-read", Bucket=S3_BUCKET, - Key=image_target_key, + Key=file_target_key, Body=open(localpath, 'rb') ) - return image_target_key + return file_target_key def make_subprocess_call(command, shell=False): diff --git a/flatland/evaluators/service.py b/flatland/evaluators/service.py index 782dc1856bd6c4e439a7a13b7489c016df9c566c..e0a352f69a2a45df877cc28947b2612fd366f9a7 100644 --- a/flatland/evaluators/service.py +++ b/flatland/evaluators/service.py @@ -746,12 +746,15 @@ class FlatlandRemoteEvaluationService: # Write Results to a file (if applicable) ##################################################################### if self.result_output_path: - if self.evaluation_metadata_df is not None: - self.evaluation_metadata_df.to_csv(self.result_output_path) - print("Wrote output results to : {}".format(self.result_output_path)) - else: - print("[WARING] Unable to write final results to the specified path" - " as metadata.csv is not provided in the tests_folder") + self.evaluation_metadata_df.to_csv(self.result_output_path) + print("Wrote output results to : {}".format(self.result_output_path)) + + # Upload the metadata file to S3 + if aicrowd_helpers.is_grading() and aicrowd_helpers.is_aws_configured(): + metadata_s3_key = aicrowd_helpers.upload_to_s3( + self.result_output_path + ) + self.evaluation_state["meta"]["private_metadata_s3_key"] = metadata_s3_key _command_response = {} _command_response['type'] = messages.FLATLAND_RL.ENV_SUBMIT_RESPONSE