Skip to content

Commit

Permalink
Merge pull request #81 from rekcurd/feature/quit_saving_evaluation_re…
Browse files Browse the repository at this point in the history
…sult

quit saving evaluate result as file
  • Loading branch information
yuki-mt authored Apr 3, 2019
2 parents c3bceca + 65e9a70 commit 76aede1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
10 changes: 4 additions & 6 deletions rekcurd_dashboard/apis/api_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import json
from itertools import chain

from flask import abort
Expand Down Expand Up @@ -127,7 +126,7 @@ def post(self, project_id: int, application_id: str):
if evaluation_result_model is not None and args.get('overwrite', False):
return evaluation_result_model.result

eval_result_path = "eval-result-{0:%Y%m%d%H%M%S}.txt".format(datetime.datetime.utcnow())
eval_result_path = "eval-result-{0:%Y%m%d%H%M%S}.pkl".format(datetime.datetime.utcnow())
application_model: ApplicationModel = db.session.query(ApplicationModel).filter(
ApplicationModel.application_id == application_id).first_or_404()
rekcurd_dashboard_client = RekcurdDashboardClient(
Expand All @@ -136,17 +135,16 @@ def post(self, project_id: int, application_id: str):
response_body = rekcurd_dashboard_client.run_evaluate_model(evaluation_model.data_path, eval_result_path)

if response_body['status']:
result = json.dumps(response_body)
if evaluation_result_model is None:
evaluation_result_model = EvaluationResultModel(
model_id=service_model.model_id,
data_path=eval_result_path,
evaluation_id=evaluation_model.evaluation_id,
result=result)
result=response_body)
db.session.add(evaluation_result_model)
else:
evaluation_result_model.data_path = eval_result_path
evaluation_result_model.result = result
evaluation_result_model.result = response_body
db.session.flush()
response_body = evaluation_result_model.result
db.session.commit()
Expand Down Expand Up @@ -184,7 +182,7 @@ def get(self, project_id: int, application_id: str, eval_result_id: int):

return {
'status': all(r['status'] for r in response_body),
'metrics': response_body[0]['metrics'],
'metrics': evaluation_result_model.result,
'details': list(chain.from_iterable(r['detail'] for r in response_body))
}

Expand Down
4 changes: 0 additions & 4 deletions rekcurd_dashboard/data_servers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class DataServer(object):
Upload/Download files.
"""

# Suffix for evaluation results
__EVALUATE_RESULT = '_eval_res.pkl'
__EVALUATE_DETAIL = '_eval_detail.pkl'

def upload_model(
self, data_server_model: DataServerModel, application_model: ApplicationModel, local_filepath: str) -> str:
filepath = "{0}/ml-{1:%Y%m%d%H%M%S}.model".format(application_model.application_name, datetime.datetime.utcnow())
Expand Down
5 changes: 3 additions & 2 deletions test/apis/test_api_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ class ApiEvaluationResultTest(BaseTestCase):
def test_get(self):
evaluation_model = create_eval_model(TEST_APPLICATION_ID, save=True)
eval_result_model = create_eval_result_model(
model_id=TEST_MODEL_ID, evaluation_id=evaluation_model.evaluation_id, save=True)
model_id=TEST_MODEL_ID, evaluation_id=evaluation_model.evaluation_id,
result=json.dumps(default_metrics), save=True)
response = self.client.get(
f'/api/projects/{TEST_PROJECT_ID}/applications/{TEST_APPLICATION_ID}/'
f'evaluation_results/{eval_result_model.evaluation_result_id}')
self.assertEqual(200, response.status_code)
self.assertEqual(response.json['status'], True)
self.assertEqual(response.json['metrics'], default_metrics)
self.assertEqual(response.json['metrics'], dict(default_metrics, result_id=1))
details = response.json['details']
self.assertEqual(len(details), 4)
self.assertEqual(
Expand Down

0 comments on commit 76aede1

Please sign in to comment.