Skip to content

Commit 62e8f23

Browse files
committed
group submitted games
1 parent b4de6c8 commit 62e8f23

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

marathon/cms_plugins.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,42 @@
77
from .models import Event, Submission, MarathonPlugin
88
from .utils import get_player_info_for_user
99

10+
class SubmissionListSubmission:
11+
def __init__(self, submission):
12+
self.game_title = submission.game_title
13+
self.category = submission.category
14+
self.players = []
15+
self.estimate = submission.estimate
16+
for player in submission.players.all():
17+
self.players.append(SubmissionListPlayer(player))
18+
19+
def update(self, submission):
20+
for player in submission.players.all():
21+
found = False
22+
for p in self.players:
23+
if p.user_id == player.user_id:
24+
found = True
25+
break
26+
if not found:
27+
self.players.append(SubmissionListPlayer(player))
28+
ctime = self.estimate.split(":")
29+
stime = submission.estimate.split(":")
30+
if len(ctime) == 2 and len(stime) == 2:
31+
crun_time = int(ctime[0]) * 60 + int(ctime[1])
32+
srun_time = int(stime[0]) * 60 + int(stime[1])
33+
if crun_time < srun_time:
34+
self.estimate = submission.estimate
35+
return srun_time - crun_time
36+
return 0
37+
38+
39+
class SubmissionListPlayer:
40+
def __init__(self, player):
41+
self.nickname = player.nickname
42+
self.twitch = player.twitch
43+
self.user_id = player.user_id
44+
45+
1046
@plugin_pool.register_plugin
1147
class SubmissionListPlugin(CMSPluginBase):
1248
name = 'Submission List'
@@ -23,33 +59,31 @@ def render(self, context, instance, placeholder):
2359
submissions = Submission.objects.filter(hidden=False)
2460

2561
unique_players = []
26-
run_times = {}
2762
total_time = 0
63+
unique_submissions = {}
2864
for s in submissions:
2965
for p in s.players.all():
30-
if p not in unique_players:
31-
unique_players.append(p)
32-
time = s.estimate.split(":")
33-
if len(time) == 2:
34-
run_id = s.game_title.lower() + s.category.lower()
35-
run_time = int(time[0]) * 60 + int(time[1])
36-
if run_id in run_times:
37-
if run_times[run_id] < run_time:
38-
total_time -= run_times[run_id]
39-
run_times[run_id] = run_time
40-
total_time += run_time
41-
else:
42-
run_times[run_id] = run_time
43-
total_time += run_time
66+
if p.user_id not in unique_players:
67+
unique_players.append(p.user_id)
68+
run_id = s.game_title.lower() + s.category.lower()
69+
if run_id not in unique_submissions:
70+
unique_submissions[run_id] = SubmissionListSubmission(s)
71+
time = s.estimate.split(":")
72+
if len(time) == 2:
73+
total_time += int(time[0]) * 60 + int(time[1])
74+
else:
75+
total_time += unique_submissions[run_id].update(s)
76+
4477
total_days = int(total_time / 60 / 24)
4578
total_hours = int(total_time / 60) % 24
4679
total_minutes = total_time % 60
4780
time_string = str(total_hours) + " t " + str(total_minutes) + " m"
4881
if total_days > 0:
4982
time_string = str(total_days) + " p " + str(total_hours) + "." + str(int(total_minutes/6)) + " t"
5083

51-
context['submissions'] = submissions
52-
context['game_count'] = str(len(run_times))
84+
u_subs = unique_submissions.values()
85+
context['submissions'] = u_subs
86+
context['game_count'] = str(len(u_subs))
5387
context['unique_players'] = str(len(unique_players))
5488
context['total_run_time'] = time_string
5589
return context

static/css/_form.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ $errorFlashShadow2: $viuhti-orange;
537537
text-decoration-color: $viuhti-darkextrafade;
538538
& > span {
539539
text-decoration-color: $viuhti-darkextrafade;
540-
541540
}
542541
.twitch-icon {
543542
margin-top: 0;

0 commit comments

Comments
 (0)