diff --git a/src/models/__init__.py b/src/models/__init__.py index d5b37a1..469cc94 100644 --- a/src/models/__init__.py +++ b/src/models/__init__.py @@ -16,6 +16,7 @@ along with scoreboard-benchmark . If not, see . """ 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 diff --git a/src/views/scoreboard.py b/src/views/scoreboard.py index 62b6297..9af629c 100644 --- a/src/views/scoreboard.py +++ b/src/views/scoreboard.py @@ -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():