def hall_of_fame(request, abbreviation): c = all_page_infos(request) game = get_object_or_404(Game, abbreviation=abbreviation) if game.sldb_name == "ZK": pass elif game.sldb_name != "": try: c["leaderboards"] = get_sldb_leaderboards(game) except SLDBConnectionError as exc: logger.error("get_sldb_leaderboards(%r): %s", game, exc) else: c["errmsg"] = "No ratings available for this game. Please choose one from the menu." logger.error("%s (%s)", c["errmsg"], game) if abbreviation == "ZK": c["intro_text"] = ['<b>The official Hall of Fame of Zero-K is at <a ' 'href="http://zero-k.info/Ladders">http://zero-k.info/Ladders</a>.</b><br/>No rating ' 'records are kept on this site anymore.'] c["games"] = Game.objects.exclude(sldb_name="") c["ladders"] = [x[1] for x in RatingBase.MATCH_TYPE_CHOICES] # games_with_bawards = Game.objects.filter(gamerelease__name__in=BAwards.objects.values_list("replay__gametype", flat=True).distinct()).distinct() # FIXME: show awards that belong to each game separately. for now only BA. games_with_bawards = Game.objects.filter(name="Balanced Annihilation") if game in games_with_bawards: try: sist = SiteStats.objects.get(id=1) except ObjectDoesNotExist: update_stats() sist = SiteStats.objects.get(id=1) c["bawards"] = sist.bawards c["bawards_lu"] = sist.last_modified c["thisgame"] = game return render(request, "hall_of_fame.html", c)
def hall_of_fame(request, abbreviation): c = all_page_infos(request) game = get_object_or_404(Game, abbreviation=abbreviation) if game.sldb_name == "ZK": pass elif game.sldb_name != "": try: c["leaderboards"] = get_sldb_leaderboards(game) except SLDBConnectionError as exc: logger.error("get_sldb_leaderboards(%r): %s", game, exc) else: c["errmsg"] = "No ratings available for this game. Please choose one from the menu." logger.error("%s (%s)", c["errmsg"], game) if abbreviation == "ZK": c["intro_text"] = [ '<b>The official Hall of Fame of Zero-K is at <a ' 'href="http://zero-k.info/Ladders">http://zero-k.info/Ladders</a>.</b><br/>No rating ' 'records are kept on this site anymore.' ] c["games"] = Game.objects.exclude(sldb_name="") c["ladders"] = [x[1] for x in RatingBase.MATCH_TYPE_CHOICES] # games_with_bawards = Game.objects.filter(gamerelease__name__in=BAwards.objects.values_list("replay__gametype", flat=True).distinct()).distinct() # FIXME: show awards that belong to each game separately. for now only BA. games_with_bawards = Game.objects.filter(name="Balanced Annihilation") if game in games_with_bawards: try: sist = SiteStats.objects.get(id=1) except ObjectDoesNotExist: update_stats() sist = SiteStats.objects.get(id=1) c["bawards"] = sist.bawards c["bawards_lu"] = sist.last_modified c["thisgame"] = game return render(request, "hall_of_fame.html", c)
def browse_archive(request, bfilter): c = all_page_infos(request) for browse_filter in ["t_today", "t_yesterday", "t_this_month", "t_last_month", "t_this_year", "t_last_year", "t_ancient"]: c[browse_filter] = replay_filter(Replay.objects.all(), "date " + browse_filter) try: sist = SiteStats.objects.get(id=1) except ObjectDoesNotExist: sist = update_stats() tags = map(lambda x: (Tag.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.tags.split('|')) c["top_tags"] = list() for t in range(0, 12, 3): if t + 3 > len(tags): break c["top_tags"].append((tags[t], tags[t + 1], tags[t + 2])) maps = map(lambda x: (Map.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.maps.split('|')) c["top_maps"] = list() for r in range(0, 8, 2): if r + 2 > len(maps): break c["top_maps"].append((maps[r], maps[r + 1])) c["top_players"] = map(lambda x: (PlayerAccount.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.active_players.split('|')) c["all_games"] = map(lambda x: (Game.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.games.split('|')) c["replays_num"] = Replay.objects.count() c["gr_all"] = GameRelease.objects.all() c["tags_all"] = Tag.objects.all() c["maps_all"] = Map.objects.all() c["pa_num"] = PlayerAccount.objects.exclude(accountid__lte=0).count() c["ah_num"] = Replay.objects.values("autohostname").distinct().count() c["user_num"] = len([user for user in User.objects.all() if user.replays_uploaded() > 0]) c["first_replay"] = Replay.objects.first() c["last_replay"] = Replay.objects.last() hosts = dict() for host in Replay.objects.values_list("autohostname", flat=True): if host: try: hosts[host] += 1 except KeyError: hosts[host] = 0 c["autohosts"] = [(name, count) for name, count in hosts.items() if count > 0] c["autohosts"].sort(key=operator.itemgetter(1), reverse=True) c["uploaders"] = [(user.username, user.replays_uploaded()) for user in User.objects.all() if user.replays_uploaded() > 0] c["uploaders"].sort(key=operator.itemgetter(1), reverse=True) if bfilter and bfilter.strip(): bfilter = str(MySQLdb.escape_string(bfilter)) args = bfilter.split("/") filters_ = map(lambda x: x.split("="), args) # only accept "date=1224/tag=8v8" etc c["filters"] = list() have = list() for filter_ in filters_: if len(filter_) == 2 and filter_[1].strip() and filter_[0] in ["date", "map", "tag", "game", "gameversion", "player", "autohost", "uploader"] and \ filter_[0] not in have: try: if filter_[0] == "date": pass elif filter_[0] == "map": c["map_name"] = Map.objects.get(id=filter_[1]).name elif filter_[0] == "tag": Tag.objects.get(id=filter_[1]) elif filter_[0] == "game": Game.objects.get(id=filter_[1]) elif filter_[0] == "gameversion": gr = GameRelease.objects.get(id=filter_[1]) c["game_abbreviation"] = gr.game.abbreviation + " " + gr.version elif filter_[0] == "player": PlayerAccount.objects.get(id=filter_[1]) elif filter_[0] == "autohost": Replay.objects.filter(autohostname=filter_[1])[0] elif filter_[0] == "uploader": Replay.objects.filter(uploader__username=filter_[1])[0] else: raise Exception("unknown filter type '%s'" % filter_[0]) # all fine, add filter c["filters"].append((filter_[0], filter_[1])) have.append(filter_[0]) except Exception as exc: # object doesnt exist logger.exception("FIXME: to broad exception handling.") logger.debug("invalid filter_: '%s' Exception: %s", filter_, exc) else: c["filters"] = "" return render(request, 'browse_archive.html', c)
def browse_archive(request, bfilter): c = all_page_infos(request) for browse_filter in [ "t_today", "t_yesterday", "t_this_month", "t_last_month", "t_this_year", "t_last_year", "t_ancient" ]: c[browse_filter] = replay_filter(Replay.objects.all(), "date " + browse_filter) try: sist = SiteStats.objects.get(id=1) except ObjectDoesNotExist: sist = update_stats() tags = map( lambda x: (Tag.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.tags.split('|')) c["top_tags"] = list() for t in range(0, 12, 3): if t + 3 > len(tags): break c["top_tags"].append((tags[t], tags[t + 1], tags[t + 2])) maps = map( lambda x: (Map.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.maps.split('|')) c["top_maps"] = list() for r in range(0, 8, 2): if r + 2 > len(maps): break c["top_maps"].append((maps[r], maps[r + 1])) c["top_players"] = map( lambda x: (PlayerAccount.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.active_players.split('|')) c["all_games"] = map( lambda x: (Game.objects.get(id=int(x.split(".")[0])), x.split(".")[1]), sist.games.split('|')) c["replays_num"] = Replay.objects.count() c["gr_all"] = GameRelease.objects.all() c["tags_all"] = Tag.objects.all() c["maps_all"] = Map.objects.all() c["pa_num"] = PlayerAccount.objects.exclude(accountid__lte=0).count() c["ah_num"] = Replay.objects.values("autohostname").distinct().count() c["user_num"] = len( [user for user in User.objects.all() if user.replays_uploaded() > 0]) c["first_replay"] = Replay.objects.first() c["last_replay"] = Replay.objects.last() hosts = dict() for host in Replay.objects.values_list("autohostname", flat=True): if host: try: hosts[host] += 1 except KeyError: hosts[host] = 0 c["autohosts"] = [(name, count) for name, count in hosts.items() if count > 0] c["autohosts"].sort(key=operator.itemgetter(1), reverse=True) c["uploaders"] = [(user.username, user.replays_uploaded()) for user in User.objects.all() if user.replays_uploaded() > 0] c["uploaders"].sort(key=operator.itemgetter(1), reverse=True) if bfilter and bfilter.strip(): bfilter = str(MySQLdb.escape_string(bfilter)) args = bfilter.split("/") filters_ = map(lambda x: x.split("="), args) # only accept "date=1224/tag=8v8" etc c["filters"] = list() have = list() for filter_ in filters_: if len(filter_) == 2 and filter_[1].strip() and filter_[0] in ["date", "map", "tag", "game", "gameversion", "player", "autohost", "uploader"] and \ filter_[0] not in have: try: if filter_[0] == "date": pass elif filter_[0] == "map": c["map_name"] = Map.objects.get(id=filter_[1]).name elif filter_[0] == "tag": Tag.objects.get(id=filter_[1]) elif filter_[0] == "game": Game.objects.get(id=filter_[1]) elif filter_[0] == "gameversion": gr = GameRelease.objects.get(id=filter_[1]) c["game_abbreviation"] = gr.game.abbreviation + " " + gr.version elif filter_[0] == "player": PlayerAccount.objects.get(id=filter_[1]) elif filter_[0] == "autohost": Replay.objects.filter(autohostname=filter_[1])[0] elif filter_[0] == "uploader": Replay.objects.filter(uploader__username=filter_[1])[0] else: raise Exception("unknown filter type '%s'" % filter_[0]) # all fine, add filter c["filters"].append((filter_[0], filter_[1])) have.append(filter_[0]) except Exception as exc: # object doesnt exist logger.exception("FIXME: to broad exception handling.") logger.debug("invalid filter_: '%s' Exception: %s", filter_, exc) else: c["filters"] = "" return render(request, 'browse_archive.html', c)