Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quit saving evaluate result as file #81

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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