コード例 #1
0
def populate_dict(dict):
    for r in regions:
        match_data_directory = os.path.join(config.match_data_directory, r.upper())
        matches = os.listdir(match_data_directory)
        progress_counter = len(matches)
        for m in matches:
            if not m.endswith('json'):
                continue
            match_data = os.path.join(match_data_directory, m)
            with open(match_data, 'r') as f:  # open match file
                data = json.load(f)  # load match file as json
                win_team_id = [t['teamId'] for t in data['teams'] if t['winner']][0]
                for p in data['participants']:
                    tier = p['highestAchievedSeasonTier']
                    champion_id = p['championId']
                    team_id = p['teamId']
                    if win_team_id == team_id:
                        dict[r][tier][str(champion_id)]['won'] += 1
                    else:
                        dict[r][tier][str(champion_id)]['lost'] += 1
            progress_counter -= 1
            data_filter.progress_countdown(progress_counter, r)
コード例 #2
0
ファイル: minions.py プロジェクト: Kdodzz/RiotAPIChallenge2.0
def populate_dict(minions_json):
    minions_and_upgrades = static_io.read_json('minions_by_id.json')
    minions_and_upgrades.update(static_io.read_json('upgrades_by_id.json'))
    for r in regions:
        match_data_directory = os.path.join(config.match_data_directory, r.upper())
        matches = os.listdir(match_data_directory)
        progress_counter = len(matches)
        for m in matches:
            if not m.endswith('json'):
                continue
            match_data = os.path.join(match_data_directory, m)
            with open(match_data, 'r') as f:  # open match file
                data = json.load(f)  # load match file as json
                win_team_id = [t['teamId'] for t in data['teams'] if t['winner']][0]
                for p in data['participants']:
                    minion_bought = ''
                    tier = p['highestAchievedSeasonTier']
                    team_id = p['teamId']
                    for frame in data['timeline']['frames']:
                        if 'events' not in frame:
                            continue
                        for event in frame['events']:
                            if event['eventType'] == 'ITEM_PURCHASED' \
                                    and event['participantId'] == p['participantId'] \
                                    and str(event['itemId']) in minions_and_upgrades:
                                item_id = str(event['itemId'])
                                if minion_bought == '':
                                    if win_team_id == team_id:
                                        minions_json[r][tier][item_id]['won'] += 1
                                    else:
                                        minions_json[r][tier][item_id]['lost'] += 1
                                    minion_bought = item_id
                                else:
                                    if win_team_id == team_id:
                                        minions_json[r][tier][minion_bought][item_id]['won'] += 1
                                    else:
                                        minions_json[r][tier][minion_bought][item_id]['lost'] += 1
            progress_counter -= 1
            data_filter.progress_countdown(progress_counter, r)