Adding a new field in model: IP
This commit is contained in:
parent
162498948c
commit
a40164da9a
2 changed files with 8 additions and 43 deletions
|
@ -16,6 +16,7 @@
|
|||
along with scoreboard-benchmark . If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
import sqlalchemy_utils
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
@ -25,19 +26,21 @@ class Result(db.Model):
|
|||
The result model will store benchmark results.
|
||||
"""
|
||||
__tablename__ = 'results'
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
id = db.Column(db.Integer, primary_key=True, index=True)
|
||||
name = db.Column(db.String(50))
|
||||
gpu = db.Column(db.String(256))
|
||||
cpu = db.Column(db.String(256))
|
||||
log = db.Column(db.Text)
|
||||
score = db.Column(db.Integer)
|
||||
score = db.Column(db.Integer, index=True)
|
||||
ip = db.Column(sqlalchemy_utils.IPAddressType)
|
||||
|
||||
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=1):
|
||||
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, ip=None, score=1):
|
||||
self.name = name
|
||||
self.gpu = gpu
|
||||
self.cpu = cpu
|
||||
self.log = log
|
||||
self.score = score
|
||||
self.ip = ip
|
||||
|
||||
def __repr__(self):
|
||||
return self.gpu
|
||||
|
|
|
@ -52,6 +52,7 @@ def result_post():
|
|||
cpu = content['cpu']
|
||||
log = content['log']
|
||||
score = int(content['score'])
|
||||
ip = flask.request.remote_addr
|
||||
|
||||
# Extra validators
|
||||
if score <= 0:
|
||||
|
@ -68,7 +69,7 @@ def result_post():
|
|||
error = str(e)
|
||||
else:
|
||||
# Add data to the database
|
||||
entry = Result(name=name, gpu=gpu, cpu=cpu, log=log, score=score)
|
||||
entry = Result(name=name, gpu=gpu, cpu=cpu, log=log, score=score, ip=ip)
|
||||
db.session.add(entry)
|
||||
db.session.commit()
|
||||
|
||||
|
@ -99,45 +100,6 @@ def result(rid):
|
|||
flask.abort(404)
|
||||
|
||||
|
||||
# @utilities.cache.cached(timeout=60)
|
||||
# @scoreboard.route("/", methods=['GET', 'POST'])
|
||||
# def index():
|
||||
# import math
|
||||
# """
|
||||
# This method returns the index page.
|
||||
# """
|
||||
# results_per_page = flask.current_app.config["MAX_RESULTS_PER_PAGE"]
|
||||
# max_pages = flask.current_app.config["MAX_PAGES"]
|
||||
#
|
||||
# # We're extracting the page argument from the url, if it's not present we set page_no to zero.
|
||||
# page_no = utilities.to_zero_count(flask.request.args.get('page'))
|
||||
# searched_name = flask.request.args.get('result_name')
|
||||
#
|
||||
# # The filters dictionary is used to filter the data
|
||||
# filters = {}
|
||||
# if searched_name is not None and searched_name is not '':
|
||||
# filters['name'] = searched_name
|
||||
#
|
||||
# # Computing the offset for the results
|
||||
# offset = page_no * results_per_page
|
||||
#
|
||||
# # We're getting the results length and data
|
||||
# results_length = Result.query.filter_by(**filters).count()
|
||||
# results = Result.query.filter_by(**filters).order_by(Result.score.desc()).offset(offset).limit(results_per_page)
|
||||
#
|
||||
# # This is used by the view to display available pages, if any.
|
||||
# available_pages = math.floor((results_length - offset) / results_per_page)
|
||||
#
|
||||
# # Compute the available pages to the left
|
||||
# pages_left = min(page_no, max_pages)
|
||||
# # Compute the available pages to the right
|
||||
# pages_right = min(max_pages, available_pages)
|
||||
# # Create pagination information tuple
|
||||
# pagination_information = results_length, results_per_page, page_no + 1, pages_left, pages_right
|
||||
#
|
||||
# return flask.render_template("index.html",
|
||||
# results=results,
|
||||
# pagination=pagination_information)
|
||||
@utilities.cache.cached(timeout=60)
|
||||
@scoreboard.route("/", methods=['GET', 'POST'])
|
||||
def index():
|
||||
|
|
Loading…
Reference in a new issue