diff --git a/prijateli_tree/app/routers/administration.py b/prijateli_tree/app/routers/administration.py index cc542759..8f939a7c 100644 --- a/prijateli_tree/app/routers/administration.py +++ b/prijateli_tree/app/routers/administration.py @@ -33,7 +33,11 @@ SessionLocal, User, ) -from prijateli_tree.app.utils.administration import Hasher, show_network +from prijateli_tree.app.utils.administration import ( + Hasher, + round_denars, + show_network, +) from prijateli_tree.app.utils.constants import ( DENAR_FACTOR, KEY_LOGIN_SECRET, @@ -149,6 +153,10 @@ def dashboard( sessions = db.query(GameSession).all() students = db.query(User).filter_by(role=ROLE_STUDENT).all() session_players = db.query(GameSessionPlayer).all() + + for sp in session_players: + sp.denars = round_denars(sp.points, DENAR_FACTOR) + student_dict = {} for s in students: student_dict[s.id] = s @@ -169,7 +177,6 @@ def dashboard( "students": students, "student_dict": student_dict, "session_players": session_players, - "DENAR_FACTOR": DENAR_FACTOR, }, ) diff --git a/prijateli_tree/app/routers/games.py b/prijateli_tree/app/routers/games.py index 0f390889..4f06c777 100644 --- a/prijateli_tree/app/routers/games.py +++ b/prijateli_tree/app/routers/games.py @@ -22,6 +22,7 @@ User, get_db, ) +from prijateli_tree.app.utils.administration import round_denars from prijateli_tree.app.utils.constants import ( DENAR_FACTOR, FILE_MODE_READ, @@ -674,7 +675,7 @@ def end_of_session( # Get points and won games from session player total_points = session_player.points n_correct_answers = session_player.correct_answers - denars = int(total_points * DENAR_FACTOR) + denars = round_denars(total_points, DENAR_FACTOR) template_text = languages[get_lang_from_player_id(player_id, db)] diff --git a/prijateli_tree/app/templates/administration/admin_dashboard.html b/prijateli_tree/app/templates/administration/admin_dashboard.html index 5136b037..33d3cdb7 100644 --- a/prijateli_tree/app/templates/administration/admin_dashboard.html +++ b/prijateli_tree/app/templates/administration/admin_dashboard.html @@ -122,7 +122,7 @@

List of Awards

{{ sp.user.first_name + ' ' + sp.user.last_name }} {{ sp.correct_answers }} {{ sp.points }} - {{ sp.points * DENAR_FACTOR }} + {{ sp.denars }} {% endfor %} diff --git a/prijateli_tree/app/utils/administration.py b/prijateli_tree/app/utils/administration.py index 7e26939c..cc49998e 100644 --- a/prijateli_tree/app/utils/administration.py +++ b/prijateli_tree/app/utils/administration.py @@ -24,3 +24,8 @@ def verify_password(plain_password, hashed_password): @staticmethod def get_password_hash(password): return pwd_context.hash(password) + + +def round_denars(points, denar_factor): + denar = points * denar_factor + return round(denar * 0.02) * 50