Exemplo n.º 1
0
    def create_from_ids(ids: List[str]) -> List['ReplayGroupChartData']:
        stats = wrapper.get_group_stats(ids)

        players = list(stats['playerStats'].keys())
        if 'ensembleStats' in stats:
            players.append('ensembleStats')
        all_chart_data = []
        for chart_metadata in player_stats_metadata:
            chart_data = ReplayGroupChartData(
                title=chart_metadata.stat_name,
                chart_data_points=[
                    ChartDataPoint(
                        name=stats['playerStats'][player_id]['name']
                        if player_id in stats['playerStats'] else 'Ensemble',
                        value=stats['playerStats'][player_id]['average'].get(
                            chart_metadata.stat_name, 0)
                        if player_id in stats['playerStats'] else
                        stats[player_id]['average'].get(
                            chart_metadata.stat_name, 0),
                    ) for player_id in players
                ],
                type_=chart_metadata.type,
                subcategory=chart_metadata.subcategory)
            if all(chart_data_point['value'] is None
                   or chart_data_point['value'] == 0
                   for chart_data_point in chart_data.chartDataPoints):
                continue
            all_chart_data.append(chart_data)

        return all_chart_data
Exemplo n.º 2
0
    def create_from_id(cls, id_: str, raw=False, rank=None, replay_ids=None, playlist=13, win=None, session=None):
        game_count = player_wrapper.get_total_games(session, id_)
        if game_count == 0:
            raise UserHasNoReplays()
        if rank is None:
            rank = get_rank(id_)
        try:
            averaged_stats = player_stat_wrapper.get_averaged_stats(session, id_,
                                                                    redis=get_redis(), raw=raw,
                                                                    rank=rank, replay_ids=replay_ids,
                                                                    playlist=playlist, win=win)
        except NoResultFound:
            raise NoReplaysForPlaylist(playlist)
        spider_charts_groups = player_stat_wrapper.get_stat_spider_charts()

        play_style_chart_datas: List[PlayStyleChartData] = []
        for spider_chart_group in spider_charts_groups:
            title = spider_chart_group['title']
            chart_data_points = [
                ChartDataPoint(name=explanations[name].short_name if name in explanations else name,
                               value=averaged_stats[name])
                for name in spider_chart_group['group']
            ]
            play_style_chart_datas.append(PlayStyleChartData(title, chart_data_points))

        return PlayStyleResponse(
            chart_datas=play_style_chart_datas,
            show_warning=game_count <= cls.showWarningThreshold
        )
Exemplo n.º 3
0
    def create_from_ids(ids: List[str]) -> List['ReplayGroupChartData']:
        stats = wrapper.get_group_stats(ids)
        player_stats = stats['playerStats']
        player_names = [player['name'] for player in player_stats]
        if 'ensembleStats' in stats:
            player_stats.append(stats['ensembleStats'])
        
        categories = list(player_stats[0]['stats'].keys())

        all_chart_data = []

        for chart_metadata in player_group_stats_metadata:
            for category in categories:
                chart_data_points = []
                for player in player_stats:
                    name = player['name'] if 'name' in player and player['name'] in player_names else 'Ensemble'
                    value = player['stats'][category].get(chart_metadata.stat_name, 0)
                    is_orange = player['is_orange'] if 'is_orange' in player else None

                    if is_orange is not None:
                        chart_data_points.append(StatDataPoint(
                            name=name,
                            value=value,
                            is_orange=is_orange
                        ))
                    else:
                        chart_data_points.append(ChartDataPoint(
                            name=name,
                            value=value
                        ))
                
                chart_data = ReplayGroupChartData(
                    title=chart_metadata.stat_name + ' ' + category,
                    chart_data_points=chart_data_points,
                    type_=chart_metadata.type,
                    subcategory=chart_metadata.subcategory
                )
                if all(chart_data_point['value'] is None or chart_data_point['value'] == 0 for chart_data_point in
                    chart_data.chartDataPoints):
                    continue
                all_chart_data.append(chart_data)

        return all_chart_data