-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from ZdruzenieSTROM/sum_methods
Refactor utils + fix sum methods
- Loading branch information
Showing
9 changed files
with
205 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
def rank_results(results: list[dict]) -> list[dict]: | ||
# Spodná hranica | ||
current_rank = 1 | ||
n_teams = 1 | ||
last_points = None | ||
for res in results: | ||
if last_points != res['total']: | ||
current_rank = n_teams | ||
last_points = res['total'] | ||
res['rank_changed'] = True | ||
else: | ||
res['rank_changed'] = False | ||
res['rank_start'] = current_rank | ||
n_teams += 1 | ||
|
||
# Horná hranica | ||
current_rank = len(results) | ||
n_teams = len(results) | ||
last_points = None | ||
for res in reversed(results): | ||
if last_points != res['total']: | ||
current_rank = n_teams | ||
last_points = res['total'] | ||
res['rank_end'] = current_rank | ||
n_teams -= 1 | ||
return results | ||
|
||
|
||
def generate_praticipant_invitations( | ||
results_with_ranking: list[dict], | ||
number_of_participants: int, | ||
number_of_substitues: int) -> list[dict]: | ||
invited_users = [] | ||
for i, result_row in enumerate(results_with_ranking): | ||
if i < number_of_participants: | ||
invited_users.append({ | ||
'first_name': result_row['registration']['profile']['first_name'], | ||
'last_name': result_row['registration']['profile']['last_name'], | ||
'school': result_row['registration']['school'], | ||
'is_participant': True | ||
}) | ||
elif i < number_of_participants+number_of_substitues: | ||
invited_users.append({ | ||
'first_name': result_row['registration']['profile']['first_name'], | ||
'last_name': result_row['registration']['profile']['last_name'], | ||
'school': result_row['registration']['school'], | ||
'is_participant': False | ||
}) | ||
return invited_users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from django.utils.timezone import now | ||
|
||
|
||
def get_school_year_start_by_date(date: Optional[datetime] = None) -> int: | ||
if date is None: | ||
date = now() | ||
|
||
return date.year if date.month >= 9 else date.year - 1 | ||
|
||
|
||
def get_school_year_end_by_date(date: Optional[datetime] = None) -> int: | ||
return get_school_year_start_by_date(date) + 1 | ||
|
||
|
||
def get_school_year_by_date(date: Optional[datetime] = None) -> str: | ||
return f'{get_school_year_start_by_date(date)}/{get_school_year_end_by_date(date)}' |
Oops, something went wrong.