From ccb5ca9df951282e611f338c2d949f33879f35e7 Mon Sep 17 00:00:00 2001 From: Duncan Ragsdale <88173870+Thistleman@users.noreply.github.com> Date: Fri, 3 Nov 2023 00:46:29 -0700 Subject: [PATCH] removed unused model fields that are causing issues adding analyses --- valhub/analyses/models.py | 3 -- valhub/analyses/serializers.py | 5 +-- valhub/analyses/views.py | 71 +--------------------------------- 3 files changed, 4 insertions(+), 75 deletions(-) diff --git a/valhub/analyses/models.py b/valhub/analyses/models.py index 5e58ce4d..2ed4baa8 100644 --- a/valhub/analyses/models.py +++ b/valhub/analyses/models.py @@ -8,7 +8,4 @@ class Analysis(models.Model): analysis_id = models.AutoField(primary_key=True) analysis_name = models.CharField(max_length=100, default="analysis") - evaluation_script = models.FileField(max_length=1000, upload_to=RandomFileName( - "evaluation_scripts")) # url to zip file - # annotation_file_name = models.FilePathField(default="test_annotation.txt", path="") max_concurrent_submission_evaluation = models.IntegerField(default=100) diff --git a/valhub/analyses/serializers.py b/valhub/analyses/serializers.py index ed811b6c..08470630 100644 --- a/valhub/analyses/serializers.py +++ b/valhub/analyses/serializers.py @@ -12,11 +12,10 @@ def __init__(self, *args, **kwargs): class Meta: model = Analysis - fields = ("evaluation_script", "analysis_name") + fields = ("analysis_name") def to_representation(self, instance): data = super(AnalysisSerializer, self).to_representation(instance) data["analysis_id"] = instance.analysis_id - # data["creator"] = {"uuid": instance.creator.uuid, - # "username": instance.creator.username} + data["analysis_name"] = instance.analysis_name return data diff --git a/valhub/analyses/views.py b/valhub/analyses/views.py index 58d73bc3..e3947afb 100644 --- a/valhub/analyses/views.py +++ b/valhub/analyses/views.py @@ -25,75 +25,8 @@ @api_view(["POST"]) @csrf_exempt def create_analysis(request): - # get user account - user_id = request.data["user_id"] - logging.warning(f'request data: {request.data}') - logging.warning(f'user id: {user_id}') - - try: - user = Account.objects.get(uuid=user_id) - except Account.DoesNotExist: - response_data = {"error": "User account does not exist"} - return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) - - serializer = AnalysisSerializer(data=request.data) - - if serializer.is_valid(): - - analysis_name = serializer.validated_data["analysis_name"] - # description = serializer.data["description"] - # evaluation_script = serializer.data["evaluation_script"] - - serializer.save(creator=user) - analysis_id = serializer.instance.analysis_id - - # upload package to s3 and upload evaluation_script_path - evaluation_script_path = serializer.instance.evaluation_script.path - # print("evaluation_script_path: {}".format(evaluation_script_path)) - bucket_name = "pv-validation-hub-bucket" - upload_path = os.path.join( - "evaluation_scripts", "analysis_{}.zip".format(analysis_id)) - - # upload algorithm code to s3 - # object_url = upload_to_s3_bucket( - # bucket_name, evaluation_script_path, upload_path) - # if object_url is None: - # response_data = {"error": "Cannot upload file to S3 bucket"} - # return Response(response_data, status=status.HTTP_400_BAD_REQUEST) - object_url = "fake.s3.url" - - # print("object_url: {}".format(object_url)) - Analysis.objects.filter(analysis_id=analysis_id).update( - evaluation_script=object_url) - - # spin up a worker instance which would create SQS queue - # ec2 = boto3.resource('ec2', region_name='us-west-2') - # worker = ec2.create_instances( - # MinCount=1, - # MaxCount=1, - # LaunchTemplate={ - # 'LaunchTemplateName': 'pv-insight-worker-template' - # }, - # TagSpecifications=[ - # { - # 'ResourceType': 'instance', - # 'Tags': [ - # { - # 'Key': 'ANALYSIS_PK', - # 'Value': str(analysis_id) - # } - # ] - # } - # ] - # ) - - # response_data = serializers.serialize('json', [serializer.instance]) - response_data = AnalysisSerializer(serializer.instance).data - else: - response_data = serializer.errors - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) - - return Response(response_data, status=status.HTTP_200_OK) + # dead route, replaced. Needs full cleansing later. + return Response("dead route.", status=status.HTTP_400_BAD_REQUEST) @api_view(["GET"])