77from .models import Event , Submission , MarathonPlugin
88from .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
1147class 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
0 commit comments