Verified Commit ba442e7a authored by Peter Stanko's avatar Peter Stanko
Browse files

Submission statistics endpoint

parent 7d670ebe
......@@ -65,6 +65,19 @@ class SubmissionState(CustomResource):
return '', 204
@submissions_namespace.route('/<string:sid>/stats')
@submissions_namespace.param('sid', 'Submission id')
@submissions_namespace.response(404, 'Submissions not found')
class SubmissionStatistics(CustomResource):
@jwt_required
# @submissions_namespace.response(200, 'Submission state', model=submission_state_schema)
def get(self, sid: str):
submission = self.find.submission(sid)
course = submission.project.course
self.permissions(course=course).require.read_submission(submission)
return self.rest.submissions(submission).get_stats()
@submissions_namespace.route('/<string:sid>/files')
@submissions_namespace.param('sid', 'Submission id')
@submissions_namespace.response(404, 'Submissions not found')
......
......@@ -159,4 +159,10 @@ class SubmissionDiffTimeError(PortalAPIError):
class SuiteStatsNotExists(PortalError):
def __init__(self, submission):
self.message = f"Suite stats have not been found for the submission: {submission.log_name}"
\ No newline at end of file
self.message = f"Suite stats have not been found for the submission: {submission.log_name}"
class ResultsAreNotUploaded(PortalAPIError):
def __init__(self, submission):
message = f"Submission {submission.log_name} results are not ready."
super().__init__(code=404, message=message)
\ No newline at end of file
"""
Submissions service
"""
import json
import logging
from pathlib import Path
from typing import List, Union
......@@ -49,6 +49,10 @@ class SubmissionsService(GeneralService):
allowed = []
return self.update_entity(entity, data, allowed=allowed)
@property
def storage_results(self):
return self.storage.results.get(self.submission.id)
def create(self, user: User, project: Project, submission_params: dict):
"""Creates a new submission in the database and downloads its files.
......@@ -214,6 +218,15 @@ class SubmissionsService(GeneralService):
git_base = self.flask_app.config.get('GIT_REPO_BASE', 'git@gitlab.fi.muni.cz')
return f"{git_base}/{user.username}/{project.course.codename}"
def get_stats(self):
results = self.storage_results
if not results.path.exists():
raise errors.ResultsAreNotUploaded(self.submission)
stats = results.get('result-stats.json')
if not stats.exists():
raise errors.SuiteStatsNotExists(self.submission)
return json.loads(stats.read_text('utf-8'))
def nonempty_intersection(provided: list, required: list):
if not required:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment