<commit_before>from app.constants import RANK_IMAGE_LIST


def _scrape_quickplay_data(response, player):
    # Scrapes Most played hero
    most_played_hero = response.text[response.text.find('data-hero-competitive'):].split('"')[1]
    if not most_played_hero:
        most_played_hero = response.text[response.text.find('data-hero-quickplay'):].split('"')[1]
    player[1]['most_played_hero'] = most_played_hero
    player[1]['portrait'] = 'img/portrait/{}.png'.format(most_played_hero)

    # Scrapes level
    player[1]['level'] = int(response.text[response.text.find('<div class="u-vertical-center'):].split('>')[1][:-5])

    # Scrapes level frame image URL
    player[1]['level_frame_img_url'] = response.text[response.text.find('class="player-level"') - 100:].split('(')[1].split(')')[0]
    level_img_starting_index = player[1]['level_frame_img_url'].find('0x0')
    level_img_ending_index = player[1]['level_frame_img_url'].find('_Border.png')
    level_img_hex_value = player[1]['level_frame_img_url'][level_img_starting_index:level_img_ending_index]
    if int(level_img_hex_value, 16) > int('0x0250000000000955', 16):
        player[1]['level'] += 600

    # Scrapes rank image URL
    if response.text.find('class="player-rank"') > 0:
        player[1]['rank_img_url'] = response.text[response.text.find('class="player-rank"') - 100:].split('(')[1].split(')')[0]
        for rank_img_tuple in RANK_IMAGE_LIST:
            for image_url in rank_img_tuple[0]:
                if player[1]['rank_img_url'].find(image_url) > 0:
                    player[1]['level'] += rank_img_tuple[1]

    #############################################################################################################
    ##### Below scraping won't work if the player is new, all the calculation based on scraping goes below ######

    # Scrapes and calculates winrate
    if response.text.find('Games Won', 70000) == -1:
        player[1]['games_won'] = 0
        player[1]['games_played'] = 0
        return player

    games_won = response.text[response.text.find('Games Won', 70000):].split("</td>")[1][4:].replace(',', '')
    # Since they removed this, gotta hack to figure it out using one of the stats
    # I'm using damage done
    #games_played = response.text[response.text.find('Games Played', 70000):].split("</td>")[1][4:].replace(',', '')
    damage_done = response.text[response.text.find('<td>Damage Done</td>'):].split('<td>')[2][:-14].replace(',', '')
    avg_damage_done = response.text[response.text.find('<td>Damage Done - Average</td>'):].split('<td>')[2][:-14].replace(',', '')
    games_played = int(int(damage_done) / int(avg_damage_done))

    player[1]['games_won'] = int(games_won)
    player[1]['games_played'] = int(games_played)
    player[1]['winrate'] = '{:.1f}'.format(float(games_won)/float(games_played) * 100)

    # Scrapes and calculates KDA
    defensive_assists = 0
    if response.text.find('<td>Defensive Assists</td>') != -1:
        defensive_assists = response.text[response.text.find('<td>Defensive Assists</td>'):].split('</td>')[1][4:].replace(',', '')
    offensive_assists = 0
    if response.text.find('<td>Offensive Assists</td>') != -1:
        offensive_assists = response.text[response.text.find('<td>Offensive Assists</td>'):].split('</td>')[1][4:].replace(',', '')


    kills = response.text[response.text.find('<td>Eliminations</td>'):].split('</td>')[1][4:].replace(',', '')
    deaths = response.text[response.text.find('<td>Deaths</td>'):].split('</td>')[1][4:].replace(',', '')
    player[1]['kills'] = kills
    player[1]['offensive_assists'] = offensive_assists<commit_msg>Quick Play winrate fix<commit_after>from app.constants import RANK_IMAGE_LIST


def _scrape_quickplay_data(response, player):
    # Scrapes Most played hero
    most_played_hero = response.text[response.text.find('data-hero-competitive'):].split('"')[1]
    if not most_played_hero:
        most_played_hero = response.text[response.text.find('data-hero-quickplay'):].split('"')[1]
    player[1]['most_played_hero'] = most_played_hero
    player[1]['portrait'] = 'img/portrait/{}.png'.format(most_played_hero)

    # Scrapes level
    player[1]['level'] = int(response.text[response.text.find('<div class="u-vertical-center'):].split('>')[1][:-5])

    # Scrapes level frame image URL
    player[1]['level_frame_img_url'] = response.text[response.text.find('class="player-level"') - 100:].split('(')[1].split(')')[0]
    level_img_starting_index = player[1]['level_frame_img_url'].find('0x0')
    level_img_ending_index = player[1]['level_frame_img_url'].find('_Border.png')
    level_img_hex_value = player[1]['level_frame_img_url'][level_img_starting_index:level_img_ending_index]
    if int(level_img_hex_value, 16) > int('0x0250000000000955', 16):
        player[1]['level'] += 600

    # Scrapes rank image URL
    if response.text.find('class="player-rank"') > 0:
        player[1]['rank_img_url'] = response.text[response.text.find('class="player-rank"') - 100:].split('(')[1].split(')')[0]
        for rank_img_tuple in RANK_IMAGE_LIST:
            for image_url in rank_img_tuple[0]:
                if player[1]['rank_img_url'].find(image_url) > 0:
                    player[1]['level'] += rank_img_tuple[1]

    #############################################################################################################
    ##### Below scraping won't work if the player is new, all the calculation based on scraping goes below ######

    # Scrapes and calculates winrate
    if response.text.find('Games Won', 70000) == -1:
        player[1]['games_won'] = 0
        player[1]['games_played'] = 0
        return player

    games_won = response.text[response.text.find('<td>Games Won</td>', 2500):].split("</td>")[1][4:].replace(',', '')
    # Since they removed this, gotta hack to figure it out using one of the stats
    # I'm using damage done
    #games_played = response.text[response.text.find('Games Played', 70000):].split("</td>")[1][4:].replace(',', '')
    damage_done = response.text[response.text.find('<td>Damage Done</td>'):].split('<td>')[2][:-14].replace(',', '')
    avg_damage_done = response.text[response.text.find('<td>Damage Done - Average</td>'):].split('<td>')[2][:-14].replace(',', '')
    games_played = int(int(damage_done) / int(avg_damage_done))

    player[1]['games_won'] = int(games_won)
    player[1]['games_played'] = int(games_played)
    player[1]['winrate'] = '{:.1f}'.format(float(games_won)/float(games_played) * 100)

    # Scrapes and calculates KDA
    defensive_assists = 0
    if response.text.find('<td>Defensive Assists</td>') != -1:
        defensive_assists = response.text[response.text.find('<td>Defensive Assists</td>'):].split('</td>')[1][4:].replace(',', '')
    offensive_assists = 0
    if response.text.find('<td>Offensive Assists</td>') != -1:
        offensive_assists = response.text[response.text.find('<td>Offensive Assists</td>'):].split('</td>')[1][4:].replace(',', '')


    kills = response.text[response.text.find('<td>Eliminations</td>'):].split('</td>')[1][4:].replace(',', '')
    deaths = response.text[response.text.find('<td>Deaths</td>'):].split('</td>')[1][4:].replace(',', '')
    player[1]['kills'] = kills
    player[1]['offensive_assists'] = offensive_assists
{'fraction_non_alphanumeric': 0.22726649293649706, 'fraction_numerical': 0.028939788780688522, 'mean_word_length': 4.719215686274509, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '862010', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2428, 'n_words': 358}