示例#1
0
def cards():
    c = Cards(db)
    search = {}

    name = request.args.get("name", "")
    text = request.args.get("text", "")
    mana = request.args.get("mana", "")
    attack = request.args.get("attack", "")
    health = request.args.get("health", "")
    notes = request.args.get("notes", "")
    offset = request.args.get("offset", "")
    missing = request.args.get("missing", "")

    hero = request.args.getlist("hero")
    rarity = request.args.getlist("rarity")
    card_set = request.args.getlist("set")
    card_type = request.args.getlist("type")
    mechanics = request.args.getlist("mechanics")

    if name != "":
        search["name"] = name

    if text != "":
        search["text"] = text

    if len(hero) > 0:
        search["hero"] = hero

    if mana != "":
        search["cost"] = mana

    if attack != "":
        search["attack"] = attack

    if health != "":
        search["health"] = health

    if len(rarity) > 0:
        search["rarity"] = rarity

    if len(card_set) > 0:
        if "Standard" in card_set:
            search["card_format"] = "Standard"
        sets_only = [x for x in card_set if x != "Standard"]
        if len(sets_only) > 0:
            search["card_set"] = sets_only

    if len(card_type) > 0:
        search["card_type"] = card_type

    if len(mechanics) > 0:
        search["mechanics"] = mechanics

    if notes != "":
        search["notes"] = notes

    missing_cards = c.missing()

    if missing != "":
        cards = missing_cards[0]
    else:
        cards = c.search(**search)
    total = len(cards)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    dust_needed = c.dust_needed()
    if len(dust_needed.keys()) > 0:
        packs = sorted(list(dust_needed.items()), key=lambda x: x[0])
        standard_packs = [x for x in packs if x[0] in config.standard_sets]
        buy_pack = sorted(standard_packs, key=lambda x: x[1], reverse=True)[0][0]
    else:
        packs = []
        buy_pack = None

    prev_offset = offset - config.card_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.card_limit
    if next_offset > total:
        next_offset = total - config.card_limit

    query = request.query_string.decode()
    prev_url = update_query_offset(query, prev_offset)
    next_url = update_query_offset(query, next_offset)

    args = {
        "cards": [format_card(x) for x in
                  cards[offset:offset + config.card_limit]],
        "heroes": ["Neutral"] + config.heroes,
        "rarities": [x.title() for x in c.rarities()],
        "card_sets": ["Standard"] + [x for x in c.sets()],
        "card_types": [x.title() for x in c.types()],
        "mechanics": [x.title() for x in c.mechanics()],
        "hero": hero,
        "name": name,
        "text": text,
        "mana": mana,
        "attack": attack,
        "health": health,
        "rarity": rarity,
        "card_set": card_set,
        "card_type": card_type,
        "mechanic": mechanics,
        "notes": notes,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.card_limit,
        "current_page": int(offset / config.card_limit) + 1,
        "total_pages": int(total / config.card_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.card_limit < total,
        "all_cards": c.total(),
        "total_ratio": winrate(c.total(), total),
        "card_image_url": config.card_image_url,
        "dust_needed": packs,
        "buy_pack": buy_pack,
        "total_missing": missing_cards[1],
        "total": total
    }

    return render_template("cards.html", **args)
示例#2
0
def cards():
    c = Cards(db)
    search = {}

    name = request.args.get("name", "")
    text = request.args.get("text", "")
    mana = request.args.get("mana", "")
    attack = request.args.get("attack", "")
    health = request.args.get("health", "")
    notes = request.args.get("notes", "")
    offset = request.args.get("offset", "")
    missing = request.args.get("missing", "")

    hero = request.args.getlist("hero")
    rarity = request.args.getlist("rarity")
    card_set = request.args.getlist("set")
    card_type = request.args.getlist("type")
    mechanics = request.args.getlist("mechanics")

    if name != "":
        search["name"] = name

    if text != "":
        search["text"] = text

    if len(hero) > 0:
        search["hero"] = hero

    if mana != "":
        search["cost"] = mana

    if attack != "":
        search["attack"] = attack

    if health != "":
        search["health"] = health

    if len(rarity) > 0:
        search["rarity"] = rarity

    if len(card_set) > 0:
        if "Standard" in card_set:
            search["card_format"] = "Standard"
        sets_only = [x for x in card_set if x != "Standard"]
        if len(sets_only) > 0:
            search["card_set"] = sets_only

    if len(card_type) > 0:
        search["card_type"] = card_type

    if len(mechanics) > 0:
        search["mechanics"] = mechanics

    if notes != "":
        search["notes"] = notes

    missing_cards = c.missing()

    if missing != "":
        cards = missing_cards[0]
    else:
        cards = c.search(**search)
    total = len(cards)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    dust_needed = c.dust_needed()
    if len(dust_needed.keys()) > 0:
        packs = sorted(list(dust_needed.items()), key=lambda x: x[0])
        standard_packs = [x for x in packs if x[0] in config.standard_sets]
        buy_pack = sorted(standard_packs, key=lambda x: x[1],
                          reverse=True)[0][0]
    else:
        packs = []
        buy_pack = None

    prev_offset = offset - config.card_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.card_limit
    if next_offset > total:
        next_offset = total - config.card_limit

    query = request.query_string.decode()
    prev_url = update_query_string(query, "offset", prev_offset)
    next_url = update_query_string(query, "offset", next_offset)

    args = {
        "cards":
        [format_card(x) for x in cards[offset:offset + config.card_limit]],
        "heroes": ["Neutral"] + config.heroes,
        "rarities": [x.title() for x in c.rarities()],
        "card_sets": ["Standard"] + [x for x in c.sets()],
        "card_types": [x.title() for x in c.types()],
        "mechanics": [x.title() for x in c.mechanics()],
        "hero": hero,
        "name": name,
        "text": text,
        "mana": mana,
        "attack": attack,
        "health": health,
        "rarity": rarity,
        "card_set": card_set,
        "card_type": card_type,
        "mechanic": mechanics,
        "notes": notes,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.card_limit,
        "current_page": int(offset / config.card_limit) + 1,
        "total_pages": int(total / config.card_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.card_limit < total,
        "all_cards": c.total(),
        "total_ratio": winrate(c.total(), total),
        "card_image_url": config.card_image_url,
        "dust_needed": packs,
        "buy_pack": buy_pack,
        "total_missing": missing_cards[1],
        "total": total
    }

    return render_template("cards.html", **args)
示例#3
0
def matches():
    m = Matches(db)

    from_date = request.args.get("from", "")
    to_date = request.args.get("to", "")
    deck = request.args.get("deck", "")
    notes = request.args.get("notes", "")
    outcome = request.args.get("outcome", "")
    offset = request.args.get("offset", "")
    card_format = request.args.get("format", "")

    opponent = request.args.getlist("opponent")
    mode = request.args.getlist("mode")

    search = {}

    if from_date != "":
        try:
            date = read_date(from_date)
            search["from_date"] = date
        except:
            search["from_date"] = None
    else:
        search["from_date"] = None

    if to_date != "":
        try:
            date = end_of_day(read_date(to_date))
            search["to_date"] = date
        except:
            search["to_date"] = None
    else:
        search["to_date"] = None

    if len(mode) > 0:
        search["mode"] = mode

    if deck != "":
        search["deck"] = deck

    if len(opponent) > 0:
        search["opponent"] = opponent

    if notes != "":
        search["notes"] = notes

    if outcome == "win":
        search["outcome"] = True
    elif outcome == "lose":
        search["outcome"] = False

    if card_format == "standard":
        search["card_format"] = "Standard"
    elif card_format == "wild":
        search["card_format"] = "Wild"

    matches = [mode_icon(hero_icon(x)) for x in
               format_matches(m.search(**search))]

    if len(matches) > 0:
        total = m.total_in_range(search["from_date"], search["to_date"])
    else:
        total = 0

    matches_found = len(matches)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    prev_offset = offset - config.match_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.match_limit
    if next_offset > matches_found:
        next_offset = matches_found - config.match_limit

    query = request.query_string.decode()
    prev_url = update_query_offset(query, prev_offset)
    next_url = update_query_offset(query, next_offset)

    total_ratio = winrate(total, matches_found)
    stats = m.stats(matches)
    opponent_stats = m.opponent_stats(matches)

    args = {
        "matches": matches[offset:offset + config.match_limit],
        "modes": ["Ranked"] + list(reversed(config.modes)),
        "opponents": config.heroes,
        "from_date": from_date,
        "to_date": to_date,
        "mode": mode,
        "deck": deck,
        "card_format": card_format,
        "opponent": opponent,
        "opponent_stats": opponent_stats,
        "opponent_ratios": opponent_ratios(opponent_stats),
        "notes": notes,
        "outcome": outcome,
        "total": total,
        "total_ratio": total_ratio,
        "matches_found": matches_found,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.match_limit,
        "current_page": int(offset / config.match_limit) + 1,
        "total_pages": int(matches_found / config.match_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.match_limit < matches_found,
        "winrate": stats["winrate"]
    }

    return render_template("matches.html", **args)
示例#4
0
def matches():
    m = Matches(db)

    from_date = request.args.get("from", "")
    to_date = request.args.get("to", "")
    deck = request.args.get("deck", "")
    notes = request.args.get("notes", "")
    outcome = request.args.get("outcome", "")
    offset = request.args.get("offset", "")
    card_format = request.args.get("format", "")
    sort = request.args.get("sort", "")

    opponent = request.args.getlist("opponent")
    mode = request.args.getlist("mode")

    search = {}

    if from_date != "":
        try:
            date = read_date(from_date)
            search["from_date"] = date
        except:
            search["from_date"] = None
    else:
        search["from_date"] = None

    if to_date != "":
        try:
            date = end_of_day(read_date(to_date))
            search["to_date"] = date
        except:
            search["to_date"] = None
    else:
        search["to_date"] = None

    if len(mode) > 0:
        search["mode"] = mode

    if deck != "":
        search["deck"] = deck

    if len(opponent) > 0:
        search["opponent"] = opponent

    if notes != "":
        search["notes"] = notes

    if outcome == "win":
        search["outcome"] = True
    elif outcome == "lose":
        search["outcome"] = False

    if card_format == "standard":
        search["card_format"] = "Standard"
    elif card_format == "wild":
        search["card_format"] = "Wild"

    if sort != "":
        search["sort"] = sort

    matches = [
        mode_icon(hero_icon(x)) for x in format_matches(m.search(**search))
    ]

    if len(matches) > 0:
        total = m.total_in_range(search["from_date"], search["to_date"])
    else:
        total = 0

    matches_found = len(matches)

    if offset != "" and is_int(offset):
        offset = int(offset)
    else:
        offset = 0

    prev_offset = offset - config.match_limit
    if prev_offset < 0:
        prev_offset = 0
    next_offset = offset + config.match_limit
    if next_offset > matches_found:
        next_offset = matches_found - config.match_limit

    query = request.query_string.decode()
    prev_url = update_query_string(query, "offset", prev_offset)
    next_url = update_query_string(query, "offset", next_offset)

    total_ratio = winrate(total, matches_found)
    stats = m.stats(matches)
    opponent_stats = m.opponent_stats(matches)

    active_sort = {}
    for col in m.columns():
        active_sort[col] = {}
        if sort[1:] == col:
            if sort[0] == "d":
                active_sort[col]["order"] = "down"
                active_sort[col]["url"] = update_query_string(
                    query, "sort", "a" + col)
            else:  # a
                active_sort[col]["order"] = "up"
                active_sort[col]["url"] = update_query_string(
                    query, "sort", "d" + col)
        else:
            active_sort[col]["order"] = None
            active_sort[col]["url"] = update_query_string(
                query, "sort", "d" + col)

    args = {
        "matches": matches[offset:offset + config.match_limit],
        "modes": ["Ranked"] + list(reversed(config.modes)),
        "opponents": config.heroes,
        "from_date": from_date,
        "to_date": to_date,
        "mode": mode,
        "deck": deck,
        "card_format": card_format,
        "opponent": opponent,
        "opponent_stats": opponent_stats,
        "opponent_ratios": opponent_ratios(opponent_stats),
        "notes": notes,
        "outcome": outcome,
        "total": total,
        "total_ratio": total_ratio,
        "matches_found": matches_found,
        "offset": offset,
        "prev_url": prev_url,
        "next_url": next_url,
        "limit": config.match_limit,
        "current_page": int(offset / config.match_limit) + 1,
        "total_pages": int(matches_found / config.match_limit) + 1,
        "prev_pages_left": offset > 0,
        "next_pages_left": offset + config.match_limit < matches_found,
        "winrate": stats["winrate"],
        "active_sort": active_sort
    }

    return render_template("matches.html", **args)