From 504d58dca0c761bd0b830999162156e9136d5bc0 Mon Sep 17 00:00:00 2001 From: brmnjsh Date: Fri, 15 Sep 2023 16:51:54 +0000 Subject: [PATCH] upload estimation to s3 --- app/services/ability_estimation_service.py | 14 ++++++++++++-- app/services/base.py | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/services/ability_estimation_service.py b/app/services/ability_estimation_service.py index 147fb1a..3ad1d00 100644 --- a/app/services/ability_estimation_service.py +++ b/app/services/ability_estimation_service.py @@ -1,5 +1,9 @@ +import json, io + from services.base import Base +from helpers import aws_helper from models.ability_estimation import AbilityEstimation +from lib.application_configs import ApplicationConfigs class AbilityEstimationService(Base): ACTION = 'abilityEstimation' @@ -7,6 +11,12 @@ class AbilityEstimationService(Base): def process(self): attributes = self.service_attributes() ability_estimation = AbilityEstimation.parse_obj(attributes) - results = ability_estimation.calculate() + # we need to convert the results from numpy array to a list to dump to json + json_data = json.dumps(ability_estimation.calculate().tolist()) - return None + # temp file name + self.file_name = f'{ability_estimation.exam_id}_ability_estimation_result.json' + + return aws_helper.file_stream_upload( + io.BytesIO(bytes(json_data.encode('UTF-8'))), self.file_name, + ApplicationConfigs.s3_processed_bucket, self.ACTION) diff --git a/app/services/base.py b/app/services/base.py index 2cd63c0..52df3f7 100644 --- a/app/services/base.py +++ b/app/services/base.py @@ -23,3 +23,5 @@ class Base: attributes = json.loads( tar_helper.extract_file_from_tar( self.tar, f'{action_snake}_attributes.json').read()) + + return attributes