Adding positive score constraint
This commit is contained in:
parent
304435162b
commit
5acf92155d
2 changed files with 11 additions and 4 deletions
|
@ -32,7 +32,7 @@ class Result(db.Model):
|
||||||
log = db.Column(db.String(10000))
|
log = db.Column(db.String(10000))
|
||||||
score = db.Column(db.Integer)
|
score = db.Column(db.Integer)
|
||||||
|
|
||||||
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=0):
|
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=1):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.gpu = gpu
|
self.gpu = gpu
|
||||||
self.cpu = cpu
|
self.cpu = cpu
|
||||||
|
@ -41,3 +41,8 @@ class Result(db.Model):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.gpu
|
return self.gpu
|
||||||
|
|
||||||
|
__table_args__ = (
|
||||||
|
db.CheckConstraint(score > 0, name="positive_score_constraint"),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
|
@ -54,10 +54,12 @@ def result_post():
|
||||||
cpu = content['cpu']
|
cpu = content['cpu']
|
||||||
log = content['log']
|
log = content['log']
|
||||||
score = int(content['score'])
|
score = int(content['score'])
|
||||||
|
if score <= 0:
|
||||||
|
error = "Score must be positive!"
|
||||||
except KeyError: # Json doesn't contain the keys we need.
|
except KeyError: # Json doesn't contain the keys we need.
|
||||||
error = "invalid json keys: gpu, cpu, log, score name"
|
error = "Invalid json keys: gpu, cpu, log, score name!"
|
||||||
except TypeError: # The types from the json object are not correct.
|
except TypeError: # The types from the json object are not correct.
|
||||||
error = "invalid json object"
|
error = "Invalid json object!"
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
return flask.jsonify({'error': error, 'success': False}), 400
|
return flask.jsonify({'error': error, 'success': False}), 400
|
||||||
|
@ -69,7 +71,7 @@ def result_post():
|
||||||
|
|
||||||
location = "/result/{}".format(entry.id)
|
location = "/result/{}".format(entry.id)
|
||||||
|
|
||||||
return flask.jsonify({'success': True, 'location': location}), 201, {'location': location}
|
return flask.jsonify({'success': True}), 201, {'location': location}
|
||||||
|
|
||||||
|
|
||||||
@utilities.cache.cached(timeout=60*5)
|
@utilities.cache.cached(timeout=60*5)
|
||||||
|
|
Loading…
Reference in a new issue