コード例 #1
0
ファイル: frontend.py プロジェクト: ftlftw/dominionstats
    def retrieve_data(self, query_dict):
        """Extraction of the data retrieval logic from GET

        Done to make it a little easier to test

        query_dict supports the following options:

          targets: optional comma separated list of card names that
            want stats for, if empty/not given, use all of them

          interaction: optional comma separated list of cards that we
            want to condition the target stats on.

          nested: optional param, if given present, also get second
            order contional stats.

          unconditional: opt param, if present, also get unconditional
            stats.
        """
        targets = query_dict.get('targets', '').split(',')
        if sum(len(t) for t in targets) > 0:
            target_inds = map(self.str_card_index, targets)
        else:
            target_inds = [str(card.index) for card in dominioncards.all_cards()]
            
        interaction_tuples = self.interaction_card_index_tuples(query_dict)
        card_stats = self.fetch_conditional_stats(target_inds, 
                                                  interaction_tuples)
        return card_stats
コード例 #2
0
ファイル: frontend.py プロジェクト: rthorst/dominionstats
    def retrieve_data(self, query_dict):
        """Extraction of the data retrieval logic from GET

        Done to make it a little easier to test

        query_dict supports the following options:

          targets: optional comma separated list of card names that
            want stats for, if empty/not given, use all of them

          interaction: optional comma separated list of cards that we
            want to condition the target stats on.

          nested: optional param, if given present, also get second
            order contional stats.

          unconditional: opt param, if present, also get unconditional
            stats.
        """
        targets = query_dict.get('targets', '').split(',')
        if sum(len(t) for t in targets) > 0:
            target_inds = map(self.str_card_index, targets)
        else:
            target_inds = [str(card.index) for card in dominioncards.all_cards()]
            
        interaction_tuples = self.interaction_card_index_tuples(query_dict)
        card_stats = self.fetch_conditional_stats(target_inds, 
                                                  interaction_tuples)
        return card_stats
コード例 #3
0
ファイル: frontend.py プロジェクト: ftlftw/dominionstats
    def GET(self):
        web.header("Content-Type", "text/html; charset=utf-8")
        query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))

        card_list = sorted(set(dominioncards.all_cards()) - 
                           set(dominioncards.TOURNAMENT_WINNINGS))

        card_x_card = dominioncards.get_card(query_dict.get('card_x', 'Minion'))
        card_y_card = dominioncards.get_card(query_dict.get('card_y', 'Chapel'))
        card_x = str(card_x_card)
        card_y = str(card_y_card)

        if card_x < card_y:
            db_id = card_x + ':' + card_y
            swap_x_and_y = False
        else:
            db_id = card_y + ':' + card_x
            swap_x_and_y = True

        db = utils.get_mongo_database()
        db_val = db.optimal_card_ratios.find_one({'_id': db_id})

        if not db_val:
            return 'No stats for "' + card_x + '" and "' + card_y + '".'

        tracker = DBCardRatioTracker()
        tracker.from_primitive_object(db_val)

        num_games = sum(meanvarstat.frequency() for meanvarstat 
                        in tracker.final.itervalues())
        num_games_threshold = int(round(num_games * .002))
        final_table = self.getHtmlTableForStats(
            tracker.final, swap_x_and_y, num_games, num_games_threshold)

        num_games = max(meanvarstat.frequency() for meanvarstat 
                        in tracker.progressive.itervalues())
        num_games_threshold = int(round(num_games * .002))
        progressive_table = self.getHtmlTableForStats(
            tracker.progressive, swap_x_and_y, num_games, num_games_threshold)

        render = web.template.render('')
        return render.optimal_card_ratios_template(
            card_list, card_x_card, card_y_card, final_table, progressive_table)
コード例 #4
0
ファイル: frontend.py プロジェクト: rthorst/dominionstats
    def GET(self):
        web.header("Content-Type", "text/html; charset=utf-8")
        query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))

        card_list = sorted(set(dominioncards.all_cards()) - 
                           set(dominioncards.TOURNAMENT_WINNINGS))

        card_x_card = dominioncards.get_card(query_dict.get('card_x', 'Minion'))
        card_y_card = dominioncards.get_card(query_dict.get('card_y', 'Chapel'))
        card_x = str(card_x_card)
        card_y = str(card_y_card)

        if card_x < card_y:
            db_id = card_x + ':' + card_y
            swap_x_and_y = False
        else:
            db_id = card_y + ':' + card_x
            swap_x_and_y = True

        db = utils.get_mongo_database()
        db_val = db.optimal_card_ratios.find_one({'_id': db_id})

        if not db_val:
            return 'No stats for "' + card_x + '" and "' + card_y + '".'

        tracker = DBCardRatioTracker()
        tracker.from_primitive_object(db_val)

        num_games = sum(meanvarstat.frequency() for meanvarstat 
                        in tracker.final.itervalues())
        num_games_threshold = int(round(num_games * .002))
        final_table = self.getHtmlTableForStats(
            tracker.final, swap_x_and_y, num_games, num_games_threshold)

        num_games = max(meanvarstat.frequency() for meanvarstat 
                        in tracker.progressive.itervalues())
        num_games_threshold = int(round(num_games * .002))
        progressive_table = self.getHtmlTableForStats(
            tracker.progressive, swap_x_and_y, num_games, num_games_threshold)

        render = web.template.render('')
        return render.optimal_card_ratios_template(
            card_list, card_x_card, card_y_card, final_table, progressive_table)
コード例 #5
0
ファイル: frontend.py プロジェクト: DLu/dominionstats
 def GET(self):
     web.header("Content-Type", "text/html; charset=utf-8")
     web.header("Access-Control-Allow-Origin", "*")
     query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
     # query_dict supports the following options.
     # targets: optional comma separated list of card names that want 
     #   stats for, if empty/not given, use all of them
     # interaction: optional comma separated list of cards that we want to
     #   condition the target stats on.
     # nested: optional param, if given present, also get second order
     #   contional stats.
     # unconditional: opt param, if present, also get unconditional stats.
     targets = query_dict.get('targets', '').split(',')
     if sum(len(t) for t in targets) == 0:
         targets = dominioncards.all_cards()
         
     target_inds = map(self.str_card_index, targets)
     interaction_tuples = self.interaction_card_index_tuples(query_dict)
     card_stats = self.fetch_conditional_stats(target_inds, 
                                               interaction_tuples)
     return self.readable_json_card_stats(card_stats)
コード例 #6
0
def supply_common_extractor(g, game_state):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(game_state.supply.get(card, 0))
    return ret
コード例 #7
0
def composition_deck_extractor(deck_comp, game_state, player):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(deck_comp.get(card, 0))
    return ret
コード例 #8
0
import utils


def nice_feature_name(n):
    return n.replace(' ', '_').replace("'", '')


def composition_deck_extractor(deck_comp, game_state, player):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(deck_comp.get(card, 0))
    return ret


composition_deck_extractor.feature_names = map(nice_feature_name,
                                               dominioncards.all_cards())


def score_deck_extractor(deck_comp, game_state, player):
    return [game_state.player_score(player)]


def deck_size_deck_extractor(deck_comp, game_state, player):
    return [sum(deck_comp.itervalues())]


def action_balance_deck_extractor(deck_comp, game_state, player):
    ret = 0
    for card, quant in deck_comp.iteritems():
        ret += (dominioncards.num_plus_actions() -
                dominioncards.is_action()) * quant
コード例 #9
0
def supply_common_extractor(g, game_state):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(game_state.supply.get(card, 0))
    return ret
コード例 #10
0
def composition_deck_extractor(deck_comp, game_state, player):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(deck_comp.get(card, 0))
    return ret
コード例 #11
0
import dominioncards
import game
import random
import utils

def nice_feature_name(n):
    return n.replace(' ', '_').replace("'", '')

def composition_deck_extractor(deck_comp, game_state, player):
    ret = []
    for card in dominioncards.all_cards():
        ret.append(deck_comp.get(card, 0))
    return ret
composition_deck_extractor.feature_names = map(nice_feature_name, 
                                               dominioncards.all_cards())

def score_deck_extractor(deck_comp, game_state, player):
    return [game_state.player_score(player)]

def deck_size_deck_extractor(deck_comp, game_state, player):
    return [sum(deck_comp.itervalues())]

def action_balance_deck_extractor(deck_comp, game_state, player):
    ret = 0
    for card, quant in deck_comp.iteritems():
        ret += (dominioncards.num_plus_actions() - dominioncards.is_action()) * quant
    return [ret / (sum(deck_comp.itervalues()) or 1)]

def unique_deck_extractor(deck_comp, game_state, player):
    return [len(deck_comp)]