Skip to content

Commit bff1d7e

Browse files
authored
Merge pull request #172 from MahjongRepository/simplify-trueskill-filters
Simplify trueskill filters
2 parents e5df2b6 + 7e021b4 commit bff1d7e

File tree

4 files changed

+32
-108
lines changed

4 files changed

+32
-108
lines changed

server/locale/ru/LC_MESSAGES/django.po

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ msgid "Average place (descending)"
6161
msgstr "Среднее место (по убыванию)"
6262

6363
#: club/views.py:40 templates/club/details.html:49
64-
#: templates/rating/_external_results_table.html:67
64+
#: templates/rating/_external_results_table.html:35
6565
#: templates/rating/_results_table.html:17
6666
#: templates/tournament/_tournament_results.html:15
6767
#: utils/tenhou/yakuman_list.py:18
@@ -894,7 +894,7 @@ msgid "Sorting:"
894894
msgstr "Сортировка:"
895895

896896
#: templates/club/details.html:47 templates/club/list.html:19
897-
#: templates/rating/_external_results_table.html:64
897+
#: templates/rating/_external_results_table.html:32
898898
#: templates/rating/_results_table.html:14
899899
#: templates/tournament/_current_tournaments_table.html:8
900900
#: templates/tournament/_tournament_results.html:8
@@ -916,7 +916,7 @@ msgstr "Имя"
916916
#: templates/player/tenhou.html:630 templates/player/tenhou.html:642
917917
#: templates/player/tenhou.html:696 templates/player/tenhou.html:708
918918
#: templates/player/tenhou.html:768
919-
#: templates/rating/_external_results_table.html:72
919+
#: templates/rating/_external_results_table.html:40
920920
#: templates/tenhou/games_history.html:51
921921
#: templates/tenhou/tenhou_accounts.html:47
922922
#: templates/tenhou/tenhou_accounts.html:110
@@ -1162,7 +1162,7 @@ msgstr "Ранг"
11621162
#: templates/ms/ms_accounts.html:29 templates/player/_changes_table.html:9
11631163
#: templates/player/ms.html:27 templates/player/ms.html:66
11641164
#: templates/player/tenhou.html:198
1165-
#: templates/rating/_external_results_table.html:70
1165+
#: templates/rating/_external_results_table.html:38
11661166
#: templates/rating/_results_table.html:20
11671167
#: templates/website/_qualification_2025_table.html:13
11681168
#: templates/website/_qualification_table.html:13
@@ -1334,14 +1334,14 @@ msgstr "Ханчаны"
13341334

13351335
#: templates/player/rating_changes.html:17
13361336
#: templates/player/rating_details.html:116
1337-
#: templates/rating/_external_results_table.html:56
1337+
#: templates/rating/_external_results_table.html:24
13381338
#: templates/rating/_results_table.html:6
13391339
msgid "Rating date"
13401340
msgstr "Рейтинг на"
13411341

13421342
#: templates/player/rating_changes.html:17
13431343
#: templates/player/rating_details.html:116
1344-
#: templates/rating/_external_results_table.html:56
1344+
#: templates/rating/_external_results_table.html:24
13451345
#: templates/rating/_results_table.html:6
13461346
msgid "latest changes"
13471347
msgstr "последние изменения"
@@ -1502,31 +1502,15 @@ msgid "四鳳南 (Houou Hanchan)"
15021502
msgstr "四鳳南 (Феникс ханчаны)"
15031503

15041504
#: templates/rating/_external_results_table.html:17
1505-
msgid "at least 20 games"
1506-
msgstr "не менее 20 игр"
1505+
msgid "at least 50 games, last game at least 2 years ago"
1506+
msgstr "не менее 50 игр, последняя игра менее 2 лет назад"
15071507

15081508
#: templates/rating/_external_results_table.html:25
1509-
msgid "at least 50 games"
1510-
msgstr "не менее 50 игр"
1511-
1512-
#: templates/rating/_external_results_table.html:33
1513-
msgid "last game at least 1 year ago"
1514-
msgstr "последняя игра менее года назад"
1515-
1516-
#: templates/rating/_external_results_table.html:41
1517-
msgid "last game at least 2 year ago"
1518-
msgstr "последняя игра менее 2 лет назад"
1519-
1520-
#: templates/rating/_external_results_table.html:49
1521-
msgid "last game at least 3 year ago"
1522-
msgstr "последняя игра менее 3 лет назад"
1523-
1524-
#: templates/rating/_external_results_table.html:57
15251509
#: templates/rating/_results_table.html:7
15261510
msgid "All dates"
15271511
msgstr "Все даты"
15281512

1529-
#: templates/rating/_external_results_table.html:74
1513+
#: templates/rating/_external_results_table.html:42
15301514
#: templates/rating/_results_table.html:24
15311515
#: templates/tournament/_tournament_results.html:18
15321516
#: templates/website/_qualification_2025_table.html:14
@@ -1535,7 +1519,7 @@ msgctxt "location"
15351519
msgid "From"
15361520
msgstr "Откуда"
15371521

1538-
#: templates/rating/_external_results_table.html:75
1522+
#: templates/rating/_external_results_table.html:43
15391523
msgid "Last game date"
15401524
msgstr "Дата последней игры"
15411525

server/rating/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
class ExternalRating(BaseModel):
1212
EXT_FILTER_ALL_RESULTS = "all_results"
13-
EXT_FILTER_MORE_20_GAMES = "more_20_games"
14-
EXT_FILTER_MORE_50_GAMES = "more_50_games"
15-
EXT_FILTER_LAST_GAME_YEAR = "last_game_year"
16-
EXT_FILTER_LAST_GAME_TWO_YEARS = "last_game_two_years"
17-
EXT_FILTER_LAST_GAME_THREE_YEARS = "last_game_three_years"
13+
EXT_FILTER_MORE_50_GAMES_LAST_GAME_TWO_YEARS = "more_50_games_last_game_two_years"
1814

1915
TRUESKILL = 0
2016
ONLINE_TRUESKILL = 1

server/rating/views.py

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,33 @@ def get_external_rating_details(rating, request, year=None, month=None, day=None
5656
today, rating_date, is_last = parse_rating_date(year, month, day)
5757
if not rating_date:
5858
today, rating_date = get_latest_rating_date(rating, is_external=True)
59-
all_results = True if stat_type is None or stat_type == ExternalRating.EXT_FILTER_ALL_RESULTS else False
59+
60+
all_results = stat_type is None or stat_type == ExternalRating.EXT_FILTER_ALL_RESULTS
61+
more_50_games_last_game_two_years = stat_type == ExternalRating.EXT_FILTER_MORE_50_GAMES_LAST_GAME_TWO_YEARS
62+
6063
if all_results:
6164
rating_results = (
62-
ExternalRatingDelta.objects.filter(rating=rating, date=rating_date, game_numbers__gte=10)
63-
.prefetch_related("player")
64-
.order_by("-base_rank")
65-
)
66-
if (
67-
all_results is False
68-
and stat_type == ExternalRating.EXT_FILTER_MORE_20_GAMES
69-
or stat_type == ExternalRating.EXT_FILTER_MORE_50_GAMES
70-
):
71-
game_count_filter = 20 if stat_type == ExternalRating.EXT_FILTER_MORE_20_GAMES else 50
72-
rating_results = (
73-
ExternalRatingDelta.objects.filter(rating=rating, date=rating_date, game_numbers__gte=game_count_filter)
65+
ExternalRatingDelta.objects.filter(
66+
rating=rating,
67+
date=rating_date,
68+
game_numbers__gte=10,
69+
)
7470
.prefetch_related("player")
7571
.order_by("-base_rank")
7672
)
77-
if (
78-
all_results is False
79-
and stat_type == ExternalRating.EXT_FILTER_LAST_GAME_YEAR
80-
or stat_type == ExternalRating.EXT_FILTER_LAST_GAME_TWO_YEARS
81-
or stat_type == ExternalRating.EXT_FILTER_LAST_GAME_THREE_YEARS
82-
):
83-
last_game_date_filter = rating_date
84-
if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_YEAR:
85-
last_game_date_filter = rating_date - relativedelta(years=1)
86-
if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_TWO_YEARS:
87-
last_game_date_filter = rating_date - relativedelta(years=2)
88-
if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_THREE_YEARS:
89-
last_game_date_filter = rating_date - relativedelta(years=3)
73+
if more_50_games_last_game_two_years:
74+
game_count_filter = 50
75+
last_game_date_filter = rating_date - relativedelta(years=2)
9076
rating_results = (
9177
ExternalRatingDelta.objects.filter(
92-
rating=rating, date=rating_date, last_game_date__gte=last_game_date_filter
78+
rating=rating,
79+
date=rating_date,
80+
game_numbers__gte=game_count_filter,
81+
last_game_date__gte=last_game_date_filter,
9382
)
9483
.prefetch_related("player")
9584
.order_by("-base_rank")
9685
)
97-
more_20_games = True if stat_type == ExternalRating.EXT_FILTER_MORE_20_GAMES else False
98-
more_50_games = True if stat_type == ExternalRating.EXT_FILTER_MORE_50_GAMES else False
99-
last_game_year = True if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_YEAR else False
100-
last_game_two_years = True if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_TWO_YEARS else False
101-
last_game_three_years = True if stat_type == ExternalRating.EXT_FILTER_LAST_GAME_THREE_YEARS else False
10286

10387
player_places_map = {}
10488
place = 1
@@ -124,18 +108,10 @@ def get_external_rating_details(rating, request, year=None, month=None, day=None
124108
"show_games_numbers": True,
125109
"ext_filters": {
126110
"all_results": ExternalRating.EXT_FILTER_ALL_RESULTS,
127-
"more_20_games": ExternalRating.EXT_FILTER_MORE_20_GAMES,
128-
"more_50_games": ExternalRating.EXT_FILTER_MORE_50_GAMES,
129-
"last_game_year": ExternalRating.EXT_FILTER_LAST_GAME_YEAR,
130-
"last_game_two_years": ExternalRating.EXT_FILTER_LAST_GAME_TWO_YEARS,
131-
"last_game_three_years": ExternalRating.EXT_FILTER_LAST_GAME_THREE_YEARS,
111+
"more_50_games_last_game_two_years": ExternalRating.EXT_FILTER_MORE_50_GAMES_LAST_GAME_TWO_YEARS,
132112
},
133113
"all_results": all_results,
134-
"more_20_games": more_20_games,
135-
"more_50_games": more_50_games,
136-
"last_game_year": last_game_year,
137-
"last_game_two_years": last_game_two_years,
138-
"last_game_three_years": last_game_three_years,
114+
"more_50_games_last_game_two_years": more_50_games_last_game_two_years,
139115
},
140116
)
141117

server/templates/rating/_external_results_table.html

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,11 @@
1010
</a>
1111

1212
{% if is_last == True %}
13-
<a href="{% url 'rating_filter' rating.slug ext_filters.more_20_games %}">
13+
<a href="{% url 'rating_filter' rating.slug ext_filters.more_50_games_last_game_two_years %}">
1414
{% else %}
15-
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.more_20_games %}">
15+
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.more_50_games_last_game_two_years %}">
1616
{% endif %}
17-
<span class="badge bg-{% if not more_20_games %}success{% else %}primary{% endif %}">{% trans 'at least 20 games' %}</span>
18-
</a>
19-
20-
{% if is_last == True %}
21-
<a href="{% url 'rating_filter' rating.slug ext_filters.more_50_games %}">
22-
{% else %}
23-
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.more_50_games %}">
24-
{% endif %}
25-
<span class="badge bg-{% if not more_50_games %}success{% else %}primary{% endif %}">{% trans 'at least 50 games' %}</span>
26-
</a>
27-
28-
{% if is_last == True %}
29-
<a href="{% url 'rating_filter' rating.slug ext_filters.last_game_year %}">
30-
{% else %}
31-
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.last_game_year %}">
32-
{% endif %}
33-
<span class="badge bg-{% if not last_game_year %}success{% else %}primary{% endif %}">{% trans 'last game at least 1 year ago' %}</span>
34-
</a>
35-
36-
{% if is_last == True %}
37-
<a href="{% url 'rating_filter' rating.slug ext_filters.last_game_two_years %}">
38-
{% else %}
39-
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.last_game_two_years %}">
40-
{% endif %}
41-
<span class="badge bg-{% if not last_game_two_years %}success{% else %}primary{% endif %}">{% trans 'last game at least 2 year ago' %}</span>
42-
</a>
43-
44-
{% if is_last == True %}
45-
<a href="{% url 'rating_filter' rating.slug ext_filters.last_game_three_years %}">
46-
{% else %}
47-
<a href="{% url 'rating_filter' rating.slug rating_date.year rating_date.month rating_date.day ext_filters.last_game_three_years %}">
48-
{% endif %}
49-
<span class="badge bg-{% if not last_game_three_years %}success{% else %}primary{% endif %}">{% trans 'last game at least 3 year ago' %}</span>
17+
<span class="badge bg-{% if not more_50_games_last_game_two_years %}success{% else %}primary{% endif %}">{% trans 'at least 50 games, last game at least 2 years ago' %}</span>
5018
</a>
5119
</div>
5220

0 commit comments

Comments
 (0)