Пример #1
0
def livesearch_match():
    try:
        from database_management import db_interaction as dbi

        searchbox = request.form.get("text")
        connection1 = dbi.get_database_connection()
        connection2 = dbi.get_database_connection()

        select = ("match_id", "map_name", "map_img_url", "date", "s1", "s2")

        if searchbox == "":
            #r = dbi.search_table(connection1,"matches","match_id",searchbox,*select)
            r = ""
            return jsonify(r)
        elif searchbox == "d" or searchbox == "de" or searchbox == "de_":
            r = result_date = dbi.search_table(connection2, "matches", "date",
                                               searchbox, *select)
            return jsonify(r)
        result_id = dbi.search_table(connection1, "matches", "match_id",
                                     searchbox, *select)
        result_map = dbi.search_table(connection2, "matches", "map_name",
                                      searchbox, *select)
        result_date = dbi.search_table(connection2, "matches", "date",
                                       searchbox, *select)

        results = result_id + result_date + result_map
        return jsonify(results)
    except Exception as e:
        return jsonify(str(e))
Пример #2
0
def add_pop_match():
    try:
        if request.method == "GET":
            return handle_error(
                "Im sorry bro, you can't access this endpoint this way.")
        elif request.method == "POST":
            from database_management import db_interaction as dbi
            from match_extraction import popflash_scraper as ps

        pop_id = request.form["pop_id"]
        conn = dbi.get_database_connection()
        if dbi.exists_in_table(conn, "matches", int(pop_id)):
            flash_str = "Match " + str(
                pop_id
            ) + " has already been added to the database! Player data has not been affected."
            flash(flash_str)
            return redirect("/tenman")

        if dbi.lock_database_flag():
            url = "/tenman/add_match/" + str(pop_id)
            return redirect(url)
        else:
            flash_str = "A match is already beeing added to the database by someone else. To avoid match duplicates, try again in a minute."
            flash(flash_str)
            return redirect("/tenman")

    except Exception as e:
        return str(e)
Пример #3
0
def seasons_prepare():
    try:
        navbar_status = [""] * NUM_TABS
        navbar_status[3] = "active"

        from database_management import db_interaction as dbi
        from datetime import date
        connection = dbi.get_database_connection()
        today = date.today()
        month = today.strftime("%B %d, %Y")[:3]
        table = "players_" + month
        if not dbi.table_exists(connection, table):
            # Create table
            query = "CREATE TABLE " + table + \
                """(pop_id int(10), points int(5), hltv_rating float(7,4), kd_ratio float(7,4), wins int(4), losses int(4), streak int(4))"""
            cur = connection.cursor()
            cur.execute(query)
            cur.close()
        season_data = dbi.get_top_season_players(connection, table)

        return render_template("/tenman/seasons.html",
                               navbar_status=navbar_status,
                               season_data=season_data)
    except Exception as e:
        return handle_error(e)
Пример #4
0
def matches():
    navbar_status = [""] * NUM_TABS
    navbar_status[2] = "active"
    try:
        from database_management import db_interaction as dbi

        navbar_status = ["", "", "active", ""]
        conn = dbi.get_database_connection()
        num_matches = dbi.get_number_of_matches(conn)

        top_maps, maps_img, map_rounds = dbi.get_most_frequent_maps(conn, 8)
        hours_dict, days_dict, months_dict = dbi.get_playtime_statistics(conn)

        return render_template("/tenman/matches.html",
                               navbar_status=navbar_status,
                               num_matches=num_matches,
                               top_maps=top_maps,
                               maps_img=maps_img,
                               map_rounds=map_rounds,
                               hours_dict=hours_dict,
                               days_dict=days_dict,
                               months_dict=months_dict)

    except Exception as e:
        return handle_error(e)
Пример #5
0
def tenman_index():
    PLAYER_THRESHOLD = 6
    try:
        navbar_status = [""] * NUM_TABS
        navbar_status[0] = "active"

        from database_management import db_interaction as dbi

        from match_extraction import popflash_scraper as ps

        if dbi.get_number_of_players(dbi.get_database_connection()) == 0:
            return render_template("tenman/no_players.html",
                                   num_matches=0,
                                   num_players=0,
                                   navbar_status=navbar_status)

        conn = dbi.get_database_connection()
        top_players = dbi.get_top_players(conn, threshold=PLAYER_THRESHOLD)

        num_matches = dbi.get_number_of_matches(conn)
        num_players = dbi.get_number_of_players(conn)

        # Get latest match
        data = dbi.get_table_data(conn, "matches")
        last_match = data[len(data) - 1]
        from match_extraction.Match import Match
        from match_extraction.Team import Team
        from match_extraction.Player import Player
        latest_match = Match(int(last_match[0]),
                             team1=Team(),
                             team2=Team(),
                             map_img_url=last_match[2],
                             date=last_match[3],
                             map_name=last_match[1])

        return render_template("tenman/tenman_landing.html",
                               navbar_status=navbar_status,
                               top_players=top_players,
                               num_matches=num_matches,
                               num_players=num_players,
                               latest_match=latest_match,
                               threshold=PLAYER_THRESHOLD)

    except Exception as e:
        return handle_error(e)
Пример #6
0
def tenman_index():
    PLAYER_THRESHOLD = 6
    navbar_status = ["active","",""]
    try:
        try:
            from database_management import db_interaction as dbi
        except Exception as e:
            return "db_interaction Import failed: " +  str(e)
        try:
            from match_extraction import popflash_scraper as ps
        except Exception as e:
            return "ps Import failed: " +  str(e)
        
        if dbi.get_number_of_players(dbi.get_database_connection()) == 0:
            return render_template("tenman/no_players.html",num_matches=0,num_players=0)
        try:
            conn = dbi.get_database_connection()

            top_players = dbi.get_top_players(conn,threshold=PLAYER_THRESHOLD)
        except Exception as e:
            return "failed in get top players " +  str(e)

        try:   
            num_matches = dbi.get_number_of_matches(conn)
            num_players = dbi.get_number_of_players(conn)
        except Exception as e:
            return "asd" + str(e)
        
        try:
            # Get latest match
            data = dbi.get_table_data(conn,"matches")
            last_match = data[len(data)-1]
            from match_extraction.Match import Match
            from match_extraction.Team import Team
            from match_extraction.Player import Player
            latest_match = Match(int(last_match[0]),team1=Team(),team2=Team(),map_img_url=last_match[2],date=last_match[3],map_name=last_match[1])
        except Exception as e:
            return "get latest; " + str(e)        
        return render_template("tenman/tenman_landing.html",navbar_status=navbar_status,top_players=top_players,num_matches=num_matches,num_players=num_players,latest_match=latest_match,threshold=PLAYER_THRESHOLD)

    except Exception as e:
        return "failed:" + str(e)
Пример #7
0
def livesearch_match():
    try:
        from database_management import db_interaction as dbi

        searchbox = request.form.get("text")
        connection = dbi.get_database_connection()
        result = dbi.search_table(connection,"matches","match_id",int(searchbox),"match_id")

        return jsonify(result)
    except Exception as e:
        return jsonify(str(e))
Пример #8
0
def livesearch():
    try:
        from database_management import db_interaction as dbi

        searchbox = request.form.get("text")
        connection = dbi.get_database_connection()
        result = dbi.search_table(connection,"players","nick",searchbox,"pop_id","nick","hltv_rating","img_url","wins","losses")

        return jsonify(result)
    except Exception as e:
        return jsonify(str(e))
Пример #9
0
def matches():
    try:
        from database_management import db_interaction as dbi
        
        navbar_status = ["","","active"]
        conn = dbi.get_database_connection()
        num_matches = dbi.get_number_of_matches(conn)
        
        return render_template("/tenman/matches.html",navbar_status=navbar_status,num_matches=num_matches)
    except Exception as e:
        return str(e)
Пример #10
0
def get_season_data():
    try:
        from database_management import db_interaction as dbi

        table = request.form.get("text")
        connection = dbi.get_database_connection()
        data = dbi.get_top_season_players(connection, table)

        return jsonify(data)

    except Exception as e:
        return jsonify(str(e))
Пример #11
0
def players():
    try:
        from database_management import db_interaction as dbi
        conn = dbi.get_database_connection()
        num_players = dbi.get_number_of_players(conn)

        navbar_status = [""] * NUM_TABS
        navbar_status[1] = "active"
        return render_template("tenman/players.html",
                               num_players=num_players,
                               navbar_status=navbar_status)
    except Exception as e:
        return handle_error(e)
Пример #12
0
def update_matches(startmatch=0):
    conn = dbi.get_database_connection()
    matches = dbi.get_table_data(conn, "matches")
    count = 0
    for row in matches:
        if count < startmatch:
            count += 1
            continue
        match_id = int(row[0])
        print("Getting data for match", match_id)
        m = ps.get_match_data(match_id)
        print("Updating data for match", match_id)
        dbi.update_match_data(m)

    print("Done!")
Пример #13
0
def add_match_after_flag(match_id):
    from database_management import db_interaction as dbi
    from match_extraction import popflash_scraper as ps
    conn = dbi.get_database_connection()

    # To protect against users entering url not from add match page
    if not dbi.exists_in_table(conn, "matches", int(match_id)):
        pop_match = ps.get_match_data(match_id)
        dbi.add_match_data(conn, pop_match)

        if not pop_match.is_tie():
            dbi.update_season_player_data(conn, pop_match)

        flash_str = "Successfully added match " + str(
            match_id) + " and updated player data."
        flash(flash_str)
        conn.close()
        dbi.relase_database_flag()
        return redirect("/tenman")
Пример #14
0
def add_pop_match():
    try:
        if request.method == "GET":
            return "Dissallowed, GET"
        elif request.method == "POST":
            
            try:
                from database_management import db_interaction as dbi
            except Exception as e:
                return "db_interaction Import failed: " +  str(e)
            
            try:
                from match_extraction import popflash_scraper as ps
            except Exception as e:
                return "ps Import failed: " +  str(e)           
            
            try:
                
                pop_id = request.form["pop_id"]
                conn = dbi.get_database_connection()
                if dbi.exists_in_table(conn,"matches",int(pop_id)):
                    flash_str = "Match " + str(pop_id) + " has already been added to the database! Player data has not been updated."
                    flash(flash_str) 
                    return redirect("/tenman")        
                else:
                    pop_match = ps.get_match_data(pop_id)            
                    dbi.add_match_data(conn,pop_match)

                    flash_str = "Successfully added match " + str(pop_id) + " and updated player data."
                    flash(flash_str)                   
                    return redirect("/tenman")                
                
            except Exception as e:
                return str(e)
            
            
    except Exception as e:
        return str(e)
Пример #15
0
def players():
    from database_management import db_interaction as dbi
    conn = dbi.get_database_connection()
    num_players = dbi.get_number_of_players(conn)
    navbar_status = ["","active",""]
    return render_template("tenman/players.html",num_players=num_players,navbar_status=navbar_status)