Пример #1
0
def map_stat_to_csv(matchid, mapid):
    def generate():
        csvLst = [
            "team", "steamid", "name", "kills", "deaths", "assists", "rating",
            "hsp", "firstkills", "k2", "k3", "k4", "k5", "adr"
        ]
        data = StringIO()
        csvWrite = csv.writer(data)
        csvWrite.writerow([g for g in csvLst])
        yield data.getvalue()
        data.seek(0)
        data.truncate(0)
        match = Match.query.get_or_404(matchid)
        map_stat = match.map_stats.filter_by(map_number=mapid,
                                             match_id=matchid).first()
        app.logger.info("{}".format(map_stat))
        for player in map_stat.player_stats:
            csvWrite.writerow(player.statsToCSVRow())
            yield data.getvalue()
            data.seek(0)
            data.truncate(0)
        # stream the response as the data is generated

    logName = "export_data_match_{}_map_{}.csv".format(matchid, mapid)
    response = app.response_class(generate(), mimetype='text/csv')
    # add a filename
    response.headers.set("Content-Disposition", "attachment", filename=logName)
    return response
Пример #2
0
def match_config(matchid):
    match = Match.query.get_or_404(matchid)
    dict = match.build_match_dict()
    response = app.response_class(
        json.dumps(dict, sort_keys=False),
        mimetype='application/json')
    return response
Пример #3
0
def match_scoreboard(matchid):
    def merge(a, b):
        if isinstance(b, dict) and isinstance(a, dict):
            a_and_b = a.viewkeys() & b.viewkeys()
            every_key = a.viewkeys() | b.viewkeys()
            return {
                k: merge(a[k], b[k])
                if k in a_and_b else deepcopy(a[k] if k in a else b[k])
                for k in every_key
            }
        return deepcopy(b)

    match = Match.query.get_or_404(matchid)
    team1 = Team.query.get_or_404(match.team1_id)
    team2 = Team.query.get_or_404(match.team2_id)
    check_private_or_public(match, team1, team2)
    map_num = 0
    map_stat_list = match.map_stats.all()
    player_dict = {}
    matches = OrderedDict()
    match_num = 0
    sorted_player_dict = OrderedDict()
    for map_stats in map_stat_list:
        for player in map_stats.player_stats:
            player_dict = merge(
                player_dict, player.get_ind_scoreboard(map_stats.map_number))
        # Sort teams based on kills.
        sorted_player_dict[team1.name] = OrderedDict(
            sorted(player_dict[team1.name].items(),
                   key=lambda x: x[1].get('kills'),
                   reverse=True))
        sorted_player_dict[team2.name] = OrderedDict(
            sorted(player_dict[team2.name].items(),
                   key=lambda x: x[1].get('kills'),
                   reverse=True))

        t1score = map_stats.team1_score
        t2score = map_stats.team2_score
        curMap = map_stats.map_name
        sorted_player_dict[team1.name]['TeamName'] = team1.name
        sorted_player_dict[team2.name]['TeamName'] = team2.name
        sorted_player_dict[team1.name]['TeamScore'] = t1score
        sorted_player_dict[team2.name]['TeamScore'] = t2score
        sorted_player_dict['map'] = curMap
        matches['map_' + str(match_num)] = sorted_player_dict
        match_num += 1
        sorted_player_dict = OrderedDict()
        player_dict = {}

    response = app.response_class(json.dumps(matches, sort_keys=False),
                                  mimetype='application/json')
    return response