|
5 | 5 | import os |
6 | 6 | import pymongo |
7 | 7 | import re |
| 8 | +from itertools import groupby |
8 | 9 |
|
9 | 10 | from config.config import Config |
10 | 11 |
|
@@ -189,6 +190,40 @@ def update_player_name(self, player, name): |
189 | 190 | player.name = name |
190 | 191 | return self.update_player(player) |
191 | 192 |
|
| 193 | + def get_all_player_tournaments_by_id(self, id): |
| 194 | + result = self.players_col.find({"_id": id}) |
| 195 | + if result.count() == 0: |
| 196 | + return None |
| 197 | + tournaments = \ |
| 198 | + [ M.Tournament.load(t, context='db') for t in self.tournaments_col.find({'players': {'$in': [id] }}) ] |
| 199 | + return tournaments |
| 200 | + |
| 201 | + def sort_player_tournaments_by_region(self, id): |
| 202 | + result = self.players_col.find({"_id": id}) |
| 203 | + if result.count() == 0: |
| 204 | + return None |
| 205 | + tournaments = self.get_all_player_tournaments_by_id(id) |
| 206 | + |
| 207 | + region_count = {} |
| 208 | + for tournament in tournaments: |
| 209 | + if not tournament.regions[0]: pass |
| 210 | + |
| 211 | + region = tournament.regions[0] |
| 212 | + if region_count.get(region, None) is None: |
| 213 | + region_count[region] = 0 |
| 214 | + region_count[region] = region_count[region] + 1 |
| 215 | + |
| 216 | + counts = [] |
| 217 | + for region, count in region_count.iteritems(): |
| 218 | + r = { |
| 219 | + 'name': region, |
| 220 | + 'count': count |
| 221 | + } |
| 222 | + counts.append(r) |
| 223 | + counts = sorted(counts, key=lambda x: x['count'], reverse=True) |
| 224 | + return counts |
| 225 | + |
| 226 | + |
192 | 227 | def insert_pending_tournament(self, pending_tournament): |
193 | 228 | return self.pending_tournaments_col.insert(pending_tournament.dump(context='db')) |
194 | 229 |
|
@@ -566,7 +601,7 @@ def get_region_ranking_criteria(self, region_id): |
566 | 601 | result = self.regions_col.find_one({'_id': region_id}) |
567 | 602 | if result: |
568 | 603 | region = M.Region.load(result, context='db') |
569 | | - return region.dump(context='web') |
| 604 | + return region.dump(context='web') |
570 | 605 |
|
571 | 606 | # throws an exception, which is okay because this is called from just create_user |
572 | 607 | def insert_user(self, user): |
|
0 commit comments