Skip to content

Commit

Permalink
rounds denars when displayed to nearest 50 (#167)
Browse files Browse the repository at this point in the history
<!--- Please write your PR name in the present imperative tense.
Examples of that tense are: "Fix issue in the dispatcher where…",
"Improve our handling of…", etc." -->
<!-- For more information on Pull Requests, you can reference here:
https://success.vanillaforums.com/kb/articles/228-using-pull-requests-to-contribute
-->
## Describe Your Changes

create rounding function and call it in both cases we display denars

## Non-Obvious Technical Information

Notice we currently don't store this in the database. 

## Checklist Before Requesting a Review
- [X] The code runs successfully.

```commandline
HERE IS SOME COMMAND LINE OUTPUT
```
  • Loading branch information
anisfeld authored Mar 14, 2024
1 parent c026ae1 commit 44b64d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions prijateli_tree/app/routers/administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -169,7 +177,6 @@ def dashboard(
"students": students,
"student_dict": student_dict,
"session_players": session_players,
"DENAR_FACTOR": DENAR_FACTOR,
},
)

Expand Down
3 changes: 2 additions & 1 deletion prijateli_tree/app/routers/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h2>List of Awards</h2>
<td>{{ sp.user.first_name + ' ' + sp.user.last_name }}</td>
<td>{{ sp.correct_answers }}</td>
<td>{{ sp.points }}</td>
<td>{{ sp.points * DENAR_FACTOR }}</td>
<td>{{ sp.denars }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions prijateli_tree/app/utils/administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 44b64d7

Please sign in to comment.