Esempio n. 1
0
def remove_match():
    m = Matches(db)
    match_id = request.args.get("id", -1)
    match = m.get(match_id)
    if match is None:
        removed = False
    else:
        removed = True
        match = m.read(match)
        m.remove(match_id)
    return render_template("remove.html",
                           match_id=match_id,
                           match=match,
                           removed=removed)
Esempio n. 2
0
def remove_match():
    m = Matches(db)
    match_id = request.args.get("id", -1)
    match = m.get(match_id)
    if match is None:
        removed = False
    else:
        removed = True
        match = m.read(match)
        m.remove(match_id)
    return render_template("remove.html",
                           match_id=match_id,
                           match=match,
                           removed=removed)
Esempio n. 3
0
def export_matches():
    m = Matches(db)
    matches = m.backup()
    return Response(response=dumps(matches),
                    status=200,
                    mimetype="application/json")
Esempio n. 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", "")

    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)
Esempio n. 5
0
def index():
    m = Matches(db)
    form_mode = False
    form_deck = False
    form_opponent = False
    last_added = False
    deck_exists = False
    submit_error = False

    # try submit a new match
    if request.method == "POST" and "username" in session:
        form_mode = request.form.get("mode", "")
        form_deck = request.form.get("deck", "")
        form_opponent = request.form.get("opponent", "")
        form_notes = request.form.get("notes", "")
        form_outcome = request.form.get("outcome", "")
        can_add = (form_mode != "" and
                   form_deck != "" and
                   form_opponent != "" and
                   form_outcome != "")
        outcome = form_outcome == "win"
        if not can_add:
            submit_error = "Missing match values in form"
        elif not valid_deck_name(form_deck):
            submit_error = "Deck name does not match template"
        else:
            deck_exists = form_deck in m.decks()
            last_added = m.add(form_mode, form_deck,
                               form_opponent, form_notes,
                               outcome)

    active_mode = (form_mode or request.args.get("mode", ""))
    active_deck = (form_deck or request.args.get("deck", ""))
    active_opponent = (form_opponent or request.args.get("opponent", ""))

    if active_mode == "":
        active_mode = m.last_mode()

    if active_deck != "":
        deck = "=" + active_deck
    else:
        deck = None

    matches = [mode_icon(hero_icon(x)) for x in
               m.search(limit=config.front_match_limit, deck=deck)]
    deck_stats = [hero_icon(x) for x in m.deck_stats(a_month_ago())]
    season_stats = {
        "standard": m.stats(m.search(start_of_month(),
                                     mode=["Ranked"],
                                     card_format="Standard")),
        "wild": m.stats(m.search(start_of_month(),
                                 mode=["Ranked"],
                                 card_format="Wild"))
    }
    overall_stats = [m.stats(m.search(a_day_ago(), deck=deck, limit=None)),
                     m.stats(m.search(a_week_ago(), deck=deck, limit=None)),
                     m.stats(m.search(a_month_ago(), deck=deck, limit=None)),
                     m.stats(m.search(deck=deck, limit=None))]

    opponent_stats = {
        "day": m.opponent_stats(m.search(a_day_ago(), deck=deck)),
        "week": m.opponent_stats(m.search(a_week_ago(), deck=deck)),
        "month": m.opponent_stats(m.search(a_month_ago(), deck=deck))
    }

    if "username" in session:
        gs = None
    else:
        gs = m.guest_stats()
        if gs:
            best_rank = mode_icon({"mode": gs["best_rank"]})
            most_played_deck = hero_icon({"deck": gs["most_played_deck"][0],
                                          "data": gs["most_played_deck"][1]})
            best_deck = hero_icon({"deck": gs["best_deck"][0],
                                   "data": gs["best_deck"][1]})
            worst_deck = hero_icon({"deck": gs["worst_deck"][0],
                                    "data": gs["worst_deck"][1]})
            gs["best_rank"] = best_rank
            gs["most_played_deck"] = most_played_deck
            gs["best_deck"] = best_deck
            gs["worst_deck"] = worst_deck

    args = {
        "modes": m.recent_mode_input(),
        "heroes": config.heroes,
        "deck_template": config.deck_template,
        "deck_stats": [format_winrate(x) for x in deck_stats],
        "standard_season_stats": format_winrate(season_stats["standard"]),
        "wild_season_stats": format_winrate(season_stats["wild"]),
        "season_rank": mode_icon({"mode": m.current_rank()}),
        "overall_stats": [format_winrate(x) for x in overall_stats],
        "opponent_stats": {
            "day": [format_winrate(x) for x in
                    format_opponents(opponent_stats["day"])],
            "week": [format_winrate(x) for x in
                     format_opponents(opponent_stats["week"])],
            "month": [format_winrate(x) for x in
                      format_opponents(opponent_stats["month"])]
        },
        "opponent_ratios": {
            "day": opponent_ratios(opponent_stats["day"]),
            "week": opponent_ratios(opponent_stats["week"]),
            "month": opponent_ratios(opponent_stats["month"])
        },
        "matches": format_matches(matches),
        "total_matches": len(matches),
        "total_decks": len(deck_stats),
        "active_mode": active_mode,
        "active_deck": active_deck,
        "active_opponent": active_opponent,
        "active_notes": request.args.get("notes", ""),
        "deck_exists": deck_exists,
        "submit_error": submit_error,
        "guest_stats": gs,
        "last_added": last_added
    }

    return render_template("hearthpy.html", **args)
Esempio n. 6
0
def export_matches():
    m = Matches(db)
    matches = m.backup()
    return Response(response=dumps(matches),
                    status=200,
                    mimetype="application/json")
Esempio n. 7
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)
Esempio n. 8
0
def index():
    m = Matches(db)
    form_mode = False
    form_deck = False
    form_opponent = False
    last_added = False
    deck_exists = False
    submit_error = False

    # try submit a new match
    if request.method == "POST" and "username" in session:
        form_mode = request.form.get("mode", "")
        form_deck = request.form.get("deck", "")
        form_opponent = request.form.get("opponent", "")
        form_notes = request.form.get("notes", "")
        form_outcome = request.form.get("outcome", "")
        can_add = (form_mode != "" and form_deck != "" and form_opponent != ""
                   and form_outcome != "")
        outcome = form_outcome == "win"
        if not can_add:
            submit_error = "Missing match values in form"
        elif not valid_deck_name(form_deck):
            submit_error = "Deck name does not match template"
        else:
            deck_exists = form_deck in m.decks()
            last_added = m.add(form_mode, form_deck, form_opponent, form_notes,
                               outcome)

    active_mode = (form_mode or request.args.get("mode", ""))
    active_deck = (form_deck or request.args.get("deck", ""))
    active_opponent = (form_opponent or request.args.get("opponent", ""))

    if active_mode == "":
        active_mode = m.last_mode()

    if active_deck != "":
        deck = "=" + active_deck
    else:
        deck = None

    matches = [
        mode_icon(hero_icon(x))
        for x in m.search(limit=config.front_match_limit, deck=deck)
    ]
    deck_stats = [hero_icon(x) for x in m.deck_stats(a_month_ago())]
    season_stats = {
        "standard":
        m.stats(
            m.search(start_of_month(), mode=["Ranked"],
                     card_format="Standard")),
        "wild":
        m.stats(m.search(start_of_month(), mode=["Ranked"],
                         card_format="Wild"))
    }
    overall_stats = [
        m.stats(m.search(a_day_ago(), deck=deck, limit=None)),
        m.stats(m.search(a_week_ago(), deck=deck, limit=None)),
        m.stats(m.search(a_month_ago(), deck=deck, limit=None)),
        m.stats(m.search(deck=deck, limit=None))
    ]

    opponent_stats = {
        "day": m.opponent_stats(m.search(a_day_ago(), deck=deck)),
        "week": m.opponent_stats(m.search(a_week_ago(), deck=deck)),
        "month": m.opponent_stats(m.search(a_month_ago(), deck=deck))
    }

    if "username" in session:
        gs = None
    else:
        gs = m.guest_stats()
        if gs:
            best_rank = mode_icon({"mode": gs["best_rank"]})
            most_played_deck = hero_icon({
                "deck": gs["most_played_deck"][0],
                "data": gs["most_played_deck"][1]
            })
            best_deck = hero_icon({
                "deck": gs["best_deck"][0],
                "data": gs["best_deck"][1]
            })
            worst_deck = hero_icon({
                "deck": gs["worst_deck"][0],
                "data": gs["worst_deck"][1]
            })
            gs["best_rank"] = best_rank
            gs["most_played_deck"] = most_played_deck
            gs["best_deck"] = best_deck
            gs["worst_deck"] = worst_deck

    args = {
        "modes": m.recent_mode_input(),
        "heroes": config.heroes,
        "deck_template": config.deck_template,
        "deck_stats": [format_winrate(x) for x in deck_stats],
        "standard_season_stats": format_winrate(season_stats["standard"]),
        "wild_season_stats": format_winrate(season_stats["wild"]),
        "season_rank": mode_icon({"mode": m.current_rank()}),
        "overall_stats": [format_winrate(x) for x in overall_stats],
        "opponent_stats": {
            "day": [
                format_winrate(x)
                for x in format_opponents(opponent_stats["day"])
            ],
            "week": [
                format_winrate(x)
                for x in format_opponents(opponent_stats["week"])
            ],
            "month": [
                format_winrate(x)
                for x in format_opponents(opponent_stats["month"])
            ]
        },
        "opponent_ratios": {
            "day": opponent_ratios(opponent_stats["day"]),
            "week": opponent_ratios(opponent_stats["week"]),
            "month": opponent_ratios(opponent_stats["month"])
        },
        "matches": format_matches(matches),
        "total_matches": len(matches),
        "total_decks": len(deck_stats),
        "active_mode": active_mode,
        "active_deck": active_deck,
        "active_opponent": active_opponent,
        "active_notes": request.args.get("notes", ""),
        "deck_exists": deck_exists,
        "submit_error": submit_error,
        "guest_stats": gs,
        "last_added": last_added
    }

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