def find_or_create_global_game(game_tree, meta): game_handle = meta.get("game_handle") game_type = meta.get("game_type", 0) format = meta.get("format", 0) start_time = game_tree.start_time end_time = game_tree.end_time if "stats" in meta and "ranked_season_stats" in meta["stats"]: ladder_season = meta["stats"]["ranked_season_stats"]["season"] else: ladder_season = guess_ladder_season(end_time) global_game = None # Check if we have enough metadata to deduplicate the game if eligible_for_unification(meta): matches = GlobalGame.objects.filter( build=meta["build"], game_type=game_type, game_handle=game_handle, server_address=meta.get("server_ip"), server_port=meta.get("server_port"), match_start__range=deduplication_time_range(start_time), ) if matches: if len(matches) > 1: # clearly something's up. invalidate the upload, look into it manually. raise ValidationError("Found too many global games. Mumble mumble...") return matches.first(), True global_game = GlobalGame.objects.create( game_handle=game_handle, server_address=meta.get("server_ip"), server_port=meta.get("server_port"), server_version=meta.get("server_version"), game_type=game_type, format=format, build=meta["build"], match_start=start_time, match_end=end_time, ladder_season=ladder_season, scenario_id=meta.get("scenario_id"), num_entities=len(game_tree.game.entities), num_turns=game_tree.game.tags.get(GameTag.TURN), ) return global_game, False
def find_or_create_global_game(game_tree, meta): build = meta["build"] if build is None and "stats" in meta: build = meta["stats"]["meta"]["build"] game_id = meta.get("game_id") game_type = meta.get("game_type", 0) start_time = game_tree.start_time end_time = game_tree.end_time if "stats" in meta and "ranked_season_stats" in meta["stats"]: ladder_season = meta["stats"]["ranked_season_stats"]["season"] else: ladder_season = guess_ladder_season(end_time) global_game = None # Check if we have enough metadata to deduplicate the game if eligible_for_unification(meta): matches = GlobalGame.objects.filter( build=build, game_type=game_type, game_server_game_id=game_id, game_server_address=meta.get("server_ip"), game_server_port=meta.get("server_port"), match_start__range=deduplication_time_range(start_time), ) if matches: if len(matches) > 1: # clearly something's up. invalidate the upload, look into it manually. raise ValidationError("Found too many global games. Mumble mumble...") return matches.first(), True global_game = GlobalGame.objects.create( game_server_game_id=game_id, game_server_address=meta.get("server_ip"), game_server_port=meta.get("server_port"), game_type=game_type, build=build, match_start=start_time, match_end=end_time, ladder_season=ladder_season, scenario_id=meta.get("scenario_id"), num_entities=len(game_tree.game.entities), num_turns=game_tree.game.tags.get(GameTag.TURN), ) return global_game, False
def find_or_create_global_game(entity_tree, meta): ladder_season = meta.get("ladder_season") if not ladder_season: ladder_season = guess_ladder_season(meta["end_time"]) game_type = meta.get("game_type", 0) if game_type == 7: # the enum used to be wrong... game_type = int(BnetGameType.BGT_CASUAL_STANDARD) defaults = { "game_handle": meta.get("game_handle"), "server_address": meta.get("server_ip"), "server_port": meta.get("server_port"), "server_version": meta.get("server_version"), "game_type": game_type, "format": meta.get("format", 0), "build": meta["build"], "match_start": meta["start_time"], "match_end": meta["end_time"], "brawl_season": meta.get("brawl_season", 0), "ladder_season": ladder_season, "scenario_id": meta.get("scenario_id"), "num_entities": len(entity_tree.entities), "num_turns": entity_tree.tags.get(GameTag.TURN), "tainted_decks": False, } if eligible_for_unification(meta): # If the globalgame is eligible for unification, generate a digest # and get_or_create the object players = entity_tree.players lo1, lo2 = players[0].account_lo, players[1].account_lo digest = generate_globalgame_digest(meta, lo1, lo2) log.debug("GlobalGame digest is %r" % (digest)) global_game, created = GlobalGame.objects.get_or_create( digest=digest, defaults=defaults) else: global_game = GlobalGame.objects.create(digest=None, **defaults) created = True log.debug("Prepared GlobalGame(id=%r), created=%r", global_game.id, created) return global_game, created
def find_or_create_global_game(entity_tree, meta): ladder_season = meta.get("ladder_season") if not ladder_season: ladder_season = guess_ladder_season(meta["end_time"]) defaults = { "game_handle": meta.get("game_handle"), "server_address": meta.get("server_ip"), "server_port": meta.get("server_port"), "server_version": meta.get("server_version"), "game_type": meta.get("game_type", 0), "format": meta.get("format", 0), "build": meta["build"], "match_start": meta["start_time"], "match_end": meta["end_time"], "brawl_season": meta.get("brawl_season", 0), "ladder_season": ladder_season, "scenario_id": meta.get("scenario_id"), "num_entities": len(entity_tree.entities), "num_turns": entity_tree.tags.get(GameTag.TURN), } if eligible_for_unification(meta): # If the globalgame is eligible for unification, generate a digest # and get_or_create the object players = entity_tree.players lo1, lo2 = players[0].account_lo, players[1].account_lo digest = generate_globalgame_digest(meta, lo1, lo2) log.debug("GlobalGame digest is %r" % (digest)) global_game, created = GlobalGame.objects.get_or_create(digest=digest, defaults=defaults) else: global_game = GlobalGame.objects.create(digest=None, **defaults) created = True log.debug("Prepared GlobalGame(id=%r), created=%r", global_game.id, created) return global_game, created