Adding progress bar for the entry
This commit is contained in:
parent
d92b4a40e0
commit
6bebaaa9b9
3 changed files with 63 additions and 2 deletions
|
@ -15,7 +15,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with scoreboard-benchmark . If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from src.models import Result
|
||||
from flask_cache import Cache
|
||||
import os
|
||||
|
||||
|
@ -75,3 +75,54 @@ def get_env_variable(variable, fallback):
|
|||
return os.environ[variable]
|
||||
except KeyError:
|
||||
return fallback
|
||||
|
||||
|
||||
@cache.memoize(60*5)
|
||||
def get_highest_score():
|
||||
"""
|
||||
Will retrieve the result that has the highest score from the database.
|
||||
|
||||
Returns:
|
||||
The score of the highest rated result else it raises an exception.
|
||||
|
||||
Raises:
|
||||
LookupError if the database is empty.
|
||||
"""
|
||||
result = Result.query.order_by(Result.score.desc()).first()
|
||||
if result:
|
||||
return result.score
|
||||
else:
|
||||
raise LookupError("The database is empty.")
|
||||
|
||||
|
||||
@cache.memoize(60*5)
|
||||
def get_progress_bar_score(current):
|
||||
"""
|
||||
Will compute the procent of the highest score compared to the current score.
|
||||
|
||||
Args:
|
||||
current - The result with the current score.
|
||||
|
||||
Returns:
|
||||
The computed score, if it's greater than %100 then returns 100.
|
||||
"""
|
||||
highest = get_highest_score()
|
||||
score = (current * 100) / highest
|
||||
if score > 100:
|
||||
return 100.0
|
||||
else:
|
||||
return score
|
||||
|
||||
|
||||
@cache.memoize(60*5)
|
||||
def get_progress_bar_class(score):
|
||||
"""
|
||||
Returns the Boostrap class for the progress-bar based on the score.
|
||||
"""
|
||||
highest = get_highest_score()
|
||||
if score > highest / 2:
|
||||
return 'progress-bar-success'
|
||||
elif score > highest / 4:
|
||||
return 'progress-bar-warning'
|
||||
else:
|
||||
return 'progress-bar-danger'
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
<h3 class="panel-title">Detailed View</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="progress">
|
||||
<div class="progress-bar {{ progress_bar['class'] }}" role="progressbar"
|
||||
aria-valuenow="{{ progress_bar['value'] }}" aria-valuemin="0"
|
||||
aria-valuemax="100" style="width: {{ progress_bar['value'] }}%">
|
||||
<span class="sr-only">{{ progress_bar['value'] }}% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
<h2><small><i class="glyphicon glyphicon-plus"></i></small> Score: {{ name.score }}</h2>
|
||||
<h3><small><i class="glyphicon glyphicon-leaf"></i></small> GPU: {{ name.gpu | safe}}</h3>
|
||||
<h3><small><i class="glyphicon glyphicon-hdd"></i></small> CPU: {{ name.cpu | safe}}</h3>
|
||||
|
|
|
@ -81,7 +81,10 @@ def result(id):
|
|||
"""
|
||||
entry_name = Result.query.filter_by(id=id).first()
|
||||
if entry_name:
|
||||
return flask.render_template("result.html", name=entry_name)
|
||||
progress_bar_data = dict()
|
||||
progress_bar_data['value'] = utilities.get_progress_bar_score(entry_name.score)
|
||||
progress_bar_data['class'] = utilities.get_progress_bar_class(entry_name.score)
|
||||
return flask.render_template("result.html", name=entry_name, progress_bar=progress_bar_data)
|
||||
else:
|
||||
flask.abort(404)
|
||||
|
||||
|
|
Loading…
Reference in a new issue