def exclude_voted_cards(self):
     if config['exclude cards if voted x times'] == 0:
         return
     cardidstoexclude = \
         [cardid[0] for cardid in sql.query(CardVote.cardId)
          .filter(CardVote.result == 1)
          .group_by(CardVote.cardId)
          .having(func.count() >= config['exclude cards if voted x times'])
          .all()]
     cardstoexclude = sql.query(Card).filter(
         Card.id.in_(cardidstoexclude)).all()
     self.base_cardpool = [
         card for card in self.base_cardpool if card not in cardstoexclude
     ]
 def exclude_past_games(self):
     if config['games to exclude'] == 0:
         return
     gameids = [
         game.id for game in sql.query(Game).order_by(desc(Game.id)).limit(
             config['games to exclude'])
     ]
     cardstoexclude = [
         gamecard.card for gamecard in sql.query(GameCard).filter(
             GameCard.gameId.in_(gameids))
     ]
     for card in cardstoexclude:
         if card in self.base_cardpool:
             self.base_cardpool.remove(card)
def display_stats():
    printer = request.args.get('printer', '')
    results = sql.query()
    data = []
    for result in results:
        if result['details']['printer'] == printer:
            if result['details']['status'] != 'finished':
                data.append(result)

    return json.dumps(data)
def init_database():
    from sqlops import SqlOps
    from sources.kingdomcards import kingdomcards

    SqlOps().create_tables()

    if sql.query(Card).all():
        # Cards are already in db
        return

    for cdict in kingdomcards:
        sql.add(Card().build_from_dict(cdict))
 def set_cardpool(self):
     self.set_expansion_requirements()
     expansions = [
         expansion for expansion in self.cards_needed_per_expansion
     ]
     self.base_cardpool = [
         card
         for card in sql.query(Card).filter(Card.expansion.in_(expansions))
     ]
     self.exclude_past_games()
     self.exclude_voted_cards()
     self.apply_popularity_requirements()
     self.current_cardpool = self.base_cardpool.copy()
def job_list():
    limit = request.args.get('limit', '')
    if limit == '':
        limit = '20'
    limit = int(limit)

    results = sql.query()
    if limit == 0:
        return json.dumps({})
    if limit > len(results):
        return json.dumps(results)

    else:
        return json.dumps(results[:limit])
def calculate_card_popularity():
    for card in sql.query(Card).all():
        popularityscorespergame = []

        gamesincludingcard = [gameid[0] for gameid in sql.query(GameCard.gameId).filter(GameCard.cardId == card.id)]
        if not gamesincludingcard:
            continue

        for gameid in gamesincludingcard:
            totalgamebuys = sql.query(func.count(CardBuy.id)).filter(CardBuy.gameId == gameid).all()[0][0]
            cardbuys = sql.query(func.count(CardBuy.id)).filter(CardBuy.gameId == gameid,
                                                                CardBuy.cardId == card.id).all()[0][0]
            popularityscorespergame.append(cardbuys / totalgamebuys)

        popularityscore = sum(popularityscorespergame) / len(popularityscorespergame)
        sql.query(Card).filter(Card.id == card.id).update({
            "popularity": popularityscore})

    sql.commit()
Beispiel #8
0
 def select_id_by_name(name):
     p = sql.query(Player.id).filter_by(name=name).first()
     return p[0] if p is not None else None
Beispiel #9
0
 def select_id_by_name(name):
     c = sql.query(Card.id).filter_by(name=name).first()
     return c[0] if c is not None else None
def get_card_names_from_db():
    writer = open('cards.txt', 'w')

    cardnames = sql.query(Card.name).all()
    for cardname in cardnames:
        writer.write(cardname[0] + ',')