Skip to content

Commit

Permalink
removed unused model fields that are causing issues adding analyses
Browse files Browse the repository at this point in the history
  • Loading branch information
Thistleman committed Nov 3, 2023
1 parent 5374039 commit ccb5ca9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 75 deletions.
3 changes: 0 additions & 3 deletions valhub/analyses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 2 additions & 3 deletions valhub/analyses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 2 additions & 69 deletions valhub/analyses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit ccb5ca9

Please sign in to comment.