Skip to content

Commit a2428d2

Browse files
committed
issue39 stat tonpu hanchan for four
1 parent 3041544 commit a2428d2

File tree

5 files changed

+159
-175
lines changed

5 files changed

+159
-175
lines changed
96 Bytes
Binary file not shown.

server/locale/ru/LC_MESSAGES/django.po

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,35 +1288,35 @@ msgstr "За всё время"
12881288

12891289
#: templates/player/tenhou.html:422
12901290
msgid "四般東 (Ippan Tonpuusen)"
1291-
msgstr "Кю-лобби тонпусены"
1291+
msgstr "四般東 (Кю-лобби тонпусены)"
12921292

12931293
#: templates/player/tenhou.html:453
12941294
msgid "四般南 (Ippan Hanchan)"
1295-
msgstr "Кю-лобби ханчаны"
1295+
msgstr "四般南 (Кю-лобби ханчаны)"
12961296

12971297
#: templates/player/tenhou.html:484
12981298
msgid "四上東 (Joukyuu Tonpuusen)"
1299-
msgstr "Перводан тонпусены"
1299+
msgstr "四上東 (Перводан тонпусены)"
13001300

13011301
#: templates/player/tenhou.html:515
13021302
msgid "四上南 (Joukyuu Hanchan)"
1303-
msgstr "Перводан ханчаны"
1303+
msgstr "四上南 (Перводан ханчаны)"
13041304

13051305
#: templates/player/tenhou.html:546
13061306
msgid "四特東 (Tokujou Tonpuusen)"
1307-
msgstr "Втородан тонпусены"
1307+
msgstr "四特東 (Втородан тонпусены)"
13081308

13091309
#: templates/player/tenhou.html:577
13101310
msgid "四特南 (Tokujou Hanchan)"
1311-
msgstr "Втородан ханчаны"
1311+
msgstr "四特南 (Втородан ханчаны)"
13121312

13131313
#: templates/player/tenhou.html:608
13141314
msgid "四鳳東 (Houou Ton)"
1315-
msgstr "Феникс тонпусены"
1315+
msgstr "四鳳東 (Феникс тонпусены)"
13161316

13171317
#: templates/player/tenhou.html:639
13181318
msgid "四鳳南 (Houou Hanchan)"
1319-
msgstr "Феникс ханчаны"
1319+
msgstr "四鳳南 (Феникс ханчаны)"
13201320

13211321
#: templates/rating/_external_results_table.html:17
13221322
msgid "at least 20 games"

server/player/tenhou/models.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -55,92 +55,6 @@ def all_time_stat(self):
5555
def all_time_stat_four(self):
5656
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS).order_by("game_date")
5757

58-
def all_time_stat_ton_Ippan(self):
59-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四般東").order_by("game_date")
60-
61-
def all_time_stat_nan_Ippan(self):
62-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四般南").order_by("game_date")
63-
64-
def all_time_stat_ton_Joukyuu(self):
65-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四上東").order_by("game_date")
66-
67-
def all_time_stat_nan_Joukyuu(self):
68-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四上南").order_by("game_date")
69-
70-
def all_time_stat_ton_Tokujou(self):
71-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四特東").order_by("game_date")
72-
73-
def all_time_stat_nan_Tokujou(self):
74-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四特南").order_by("game_date")
75-
76-
def all_time_stat_ton_Houou(self):
77-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四鳳東").order_by("game_date")
78-
79-
def all_time_stat_nan_Houou(self):
80-
return self.game_logs.filter(game_players=TenhouGameLog.FOUR_PLAYERS, game_rules__startswith="四鳳南").order_by("game_date")
81-
82-
def calculate_statistics(self, queryset):
83-
if not queryset.exists():
84-
return None
85-
86-
stats = queryset.aggregate(
87-
total_games=Count('id'),
88-
average_place=Avg('place'),
89-
first_place=100.0 * Avg(
90-
Case(
91-
When(place=1, then=1),
92-
default=0,
93-
output_field=FloatField()
94-
)
95-
),
96-
second_place=100.0 * Avg(
97-
Case(
98-
When(place=2, then=1),
99-
default=0,
100-
output_field=FloatField()
101-
)
102-
),
103-
third_place=100.0 * Avg(
104-
Case(
105-
When(place=3, then=1),
106-
default=0,
107-
output_field=FloatField()
108-
)
109-
),
110-
fourth_place=100.0 * Avg(
111-
Case(
112-
When(place=4, then=1),
113-
default=0,
114-
output_field=FloatField()
115-
)
116-
)
117-
)
118-
return stats
119-
120-
def get_Ippan_ton_stats(self):
121-
return self.calculate_statistics(self.all_time_stat_ton_Ippan())
122-
123-
def get_Ippan_nan_stats(self):
124-
return self.calculate_statistics(self.all_time_stat_nan_Ippan())
125-
126-
def get_Joukyuu_ton_stats(self):
127-
return self.calculate_statistics(self.all_time_stat_ton_Joukyuu())
128-
129-
def get_Joukyuu_nan_stats(self):
130-
return self.calculate_statistics(self.all_time_stat_nan_Joukyuu())
131-
132-
def get_Tokujou_ton_stats(self):
133-
return self.calculate_statistics(self.all_time_stat_ton_Tokujou())
134-
135-
def get_Tokujou_nan_stats(self):
136-
return self.calculate_statistics(self.all_time_stat_nan_Tokujou())
137-
138-
def get_Houou_ton_stats(self):
139-
return self.calculate_statistics(self.all_time_stat_ton_Houou())
140-
141-
def get_Houou_nan_stats(self):
142-
return self.calculate_statistics(self.all_time_stat_nan_Houou())
143-
14458
def current_month_stat(self):
14559
return self.statistics.filter(stat_type=TenhouStatistics.CURRENT_MONTH)
14660

server/player/views.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from django.db.models import F
66
from django.shortcuts import get_object_or_404, redirect, render
7-
7+
from django.db.models import Avg, Count, Case, When, FloatField
88
from club.club_games.models import ClubRating
99
from player.mahjong_soul.models import MSAccount
1010
from player.models import Player
@@ -202,6 +202,44 @@ def _get_rating_changes(rating, player, today):
202202

203203
return filtered_results
204204

205+
def calculate_statistics(queryset):
206+
if not queryset.exists():
207+
return None
208+
209+
stats = queryset.aggregate(
210+
total_games=Count('id'),
211+
average_place=Avg('place'),
212+
first_place=100.0 * Avg(
213+
Case(
214+
When(place=1, then=1),
215+
default=0,
216+
output_field=FloatField()
217+
)
218+
),
219+
second_place=100.0 * Avg(
220+
Case(
221+
When(place=2, then=1),
222+
default=0,
223+
output_field=FloatField()
224+
)
225+
),
226+
third_place=100.0 * Avg(
227+
Case(
228+
When(place=3, then=1),
229+
default=0,
230+
output_field=FloatField()
231+
)
232+
),
233+
fourth_place=100.0 * Avg(
234+
Case(
235+
When(place=4, then=1),
236+
default=0,
237+
output_field=FloatField()
238+
)
239+
)
240+
)
241+
return stats
242+
205243

206244
def player_tenhou_details(request, slug):
207245
player = get_object_or_404(Player, slug=slug)
@@ -212,6 +250,30 @@ def player_tenhou_details(request, slug):
212250
)
213251
tenhou_data_all_time_stat_four = tenhou_data[0].all_time_stat_four() if tenhou_data else []
214252

253+
ippan_ton = calculate_statistics(tenhou_data_all_time_stat_four
254+
.filter(game_rules__startswith="四般東"))
255+
256+
ippan_nan = calculate_statistics(tenhou_data_all_time_stat_four
257+
.filter(game_rules__startswith="四般南"))
258+
259+
joukyuu_ton = calculate_statistics(tenhou_data_all_time_stat_four
260+
.filter(game_rules__startswith="四上東"))
261+
262+
joukyuu_nan = calculate_statistics(tenhou_data_all_time_stat_four
263+
.filter(game_rules__startswith="四上南"))
264+
265+
tokujou_ton = calculate_statistics(tenhou_data_all_time_stat_four
266+
.filter(game_rules__startswith="四特東"))
267+
268+
tokujou_nan = calculate_statistics(tenhou_data_all_time_stat_four
269+
.filter(game_rules__startswith="四特南"))
270+
271+
houou_ton = calculate_statistics(tenhou_data_all_time_stat_four
272+
.filter(game_rules__startswith="四鳳東"))
273+
274+
houou_nan = calculate_statistics(tenhou_data_all_time_stat_four
275+
.filter(game_rules__startswith="四鳳南"))
276+
215277
return render(
216278
request,
217279
"player/tenhou.html",
@@ -220,6 +282,14 @@ def player_tenhou_details(request, slug):
220282
"tenhou_data": tenhou_data,
221283
"tenhou_data_all_time_stat_four": tenhou_data_all_time_stat_four,
222284
"RANKS": TenhouAggregatedStatistics.RANKS,
285+
"ippan_ton": ippan_ton,
286+
"ippan_nan": ippan_nan,
287+
"joukyuu_ton": joukyuu_ton,
288+
"joukyuu_nan": joukyuu_nan,
289+
"tokujou_ton": tokujou_ton,
290+
"tokujou_nan": tokujou_nan,
291+
"houou_ton": houou_ton,
292+
"houou_nan": houou_nan,
223293
},
224294
)
225295

0 commit comments

Comments
 (0)