def accum_buy_stats(games_stream, accum_stats, acceptable_deck_filter=lambda game, name: True, max_games=-1): """ Accumulate buy statistics from games_stream into accum_stats. games_stream: an iterable of game.Game objects. accum_stats: DeckBuyStats object to store results. acceptable_deck_filter: predicate that determines if information about a particular deck should be included. By default, include everything. """ for idx, game_val in enumerate(games_stream): counted_game_len = False every_set_cards = card_info.EVERY_SET_CARDS for changes in game_val.deck_changes_per_player(): if not acceptable_deck_filter(game_val, changes.name): continue any_gained = set() win_points = game_val.get_player_deck(changes.name).WinPoints() for category in game.PlayerDeckChange.CATEGORIES: for card in getattr(changes, category): getattr(accum_stats[card], category).add_outcome(win_points) if category in ['gains', 'buys']: any_gained.add(card) for card in any_gained: accum_stats[card].any_gained.add_outcome(win_points) all_avail = analysis_util.available_cards(game_val, any_gained) for card in all_avail: accum_stats[card].available.add_outcome(win_points) if not counted_game_len: # don't double count this counted_game_len = True game_len = game_val.get_turns()[-1].get_turn_no() for card in all_avail: stats_obj = accum_stats[card] stats_obj.game_length.add_outcome(game_len) if 'Colony' in game_val.get_supply(): stats_obj.game_length_colony.add_outcome(game_len) if idx + 1 == max_games: break
def accum_buy_stats(games_stream, accum_stats, acceptable_deck_filter=lambda game, name: True, max_games=-1): """ Accumulate buy statistics from games_stream into accum_stats. games_stream: an iterable of game.Game objects. accum_stats: DeckBuyStats object to store results. acceptable_deck_filter: predicate that determines if information about a particular deck should be included. By default, include everything. """ for idx, game_val in enumerate(games_stream): counted_game_len = False every_set_cards = card_info.EVERY_SET_CARDS for changes in game_val.deck_changes_per_player(): if not acceptable_deck_filter(game_val, changes.name): continue any_gained = set() win_points = game_val.get_player_deck(changes.name).WinPoints() for category in game.PlayerDeckChange.CATEGORIES: for card in getattr(changes, category): getattr(accum_stats[card], category).add_outcome( win_points) if category in ['gains', 'buys']: any_gained.add(card) for card in any_gained: accum_stats[card].any_gained.add_outcome(win_points) all_avail = analysis_util.available_cards(game_val, any_gained) for card in all_avail: accum_stats[card].available.add_outcome(win_points) if not counted_game_len: # don't double count this counted_game_len = True game_len = game_val.get_turns()[-1].get_turn_no() for card in all_avail: stats_obj = accum_stats[card] stats_obj.game_length.add_outcome(game_len) if 'Colony' in game_val.get_supply(): stats_obj.game_length_colony.add_outcome(game_len) if idx + 1 == max_games: break
def accumulate_card_stats(games_stream, stats_accumulator, max_games=-1): for game_obj in games_stream: detected_events = detect_events(game_obj) per_player_accum = game_obj.cards_gained_per_player()[game.BOUGHT].iteritems() for player, accum_dict in per_player_accum: avail = analysis_util.available_cards(game_obj, accum_dict.keys()) win_points = game_obj.get_player_deck(player).WinPoints() for card in avail: count = accum_dict.get(card, 0) small_gain_stat = SmallGainStat() if count: small_gain_stat.win_given_any_gain.add_outcome(win_points) else: small_gain_stat.win_given_no_gain.add_outcome(win_points) small_gain_stat.win_weighted_gain.add_many_outcomes( win_points, count) card_index = str(card.index) stats_accumulator.merge_stats(detected_events, card_index, small_gain_stat) max_games -= 1 if max_games == 0: break
def accumulate_card_stats(games_stream, stats_accumulator, max_games=-1): ct = 0 for game in games_stream: detected_events = detect_events(game) per_player_accum = game.cards_accumalated_per_player().iteritems() for player, accum_dict in per_player_accum: avail = analysis_util.available_cards(game, accum_dict.keys()) win_points = game.get_player_deck(player).WinPoints() for card in avail: count = accum_dict.get(card, 0) small_gain_stat = SmallGainStat() if count: small_gain_stat.win_given_any_gain.add_outcome(win_points) else: small_gain_stat.win_given_no_gain.add_outcome(win_points) small_gain_stat.win_weighted_gain.add_many_outcomes( win_points, count) card_index = str(card_info.card_index(card)) stats_accumulator.merge_stats(detected_events, card_index, small_gain_stat) max_games -= 1 if max_games == 0: break