def test_data_on_demand(): player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) start_time = time.perf_counter() player_data.raw_data end_time = time.perf_counter() result = end_time - start_time assert result < 4
def test_data_structure(): player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) assert len(over_stats.MODES) is 2 for mode in over_stats.MODES: assert type(player_data.comparison_types(mode)) is list for comparison_type in player_data.comparison_types(mode): assert type(player_data.comparison_heroes(mode, comparison_type)) is list for comparison_hero in player_data.comparison_heroes( mode, comparison_type): assert (player_data.comparisons(mode, comparison_type, comparison_hero)) is not None assert type(player_data.stat_heroes(mode)) is list for hero in player_data.stat_heroes(mode): assert type(player_data.stat_categories(mode, hero)) is list for category in player_data.stat_categories(mode, hero): assert type(player_data.stat_names(mode, hero, category)) is list for stat_name in player_data.stat_names(mode, hero, category): assert (player_data.stats(mode, hero, category, stat_name)) is not None assert type(player_data.achievement_types()) is list for achievement_type in player_data.achievement_types(): for achievement in player_data.achievements(achievement_type, over_stats.ACH_EARNED): assert type(achievement) is str for achievement in player_data.achievements(achievement_type, over_stats.ACH_MISSING): assert type(achievement) is str
async def ow_load_data(player, modes=['quickplay', 'competitive'], platform='pc', comparison_type=None, top=5 ): ow_data = {} ow_stats = {} player_data = over_stats.PlayerProfile(player, platform) player_data.load_data() for mode in modes: ow_data[mode] = {} if comparison_type: for comparison_hero in player_data.comparison_heroes(mode, comparison_type): ow_data[mode][comparison_hero] = str(player_data.comparisons(mode, comparison_type, comparison_hero)) stat = '**{} - {}**'.format(player, comparison_type) ow_stats[stat] = {} for mode in ow_data: ow_stats[stat]['**{}**'.format(mode.upper())] = {} for hero in utils.take(int(top), ow_data[mode]): ow_stats[stat]['**{}**'.format(mode.upper())]['{}'.format(hero)] = ow_data_formatter(ow_data[mode][hero], comparison_type) return ow_stats
def test_initialize(): # Test the PC profile player_data = over_stats.PlayerProfile('zappis#21285') assert type(player_data.raw_data) is dict # Test a PC profile by setting the platform parameter player_data = over_stats.PlayerProfile('zappis#21285', over_stats.PLAT_PC) assert type(player_data.raw_data) is dict # Test a PC profile by setting the platform parameter and using Decimals to wrap floats player_data = over_stats.PlayerProfile('zappis#21285', over_stats.PLAT_PC, True) assert type(player_data.raw_data) is dict # Test a non existing PC profile with pytest.raises(over_stats.errors.PlayerNotFound): player_data = over_stats.PlayerProfile('zappis#21286', over_stats.PLAT_PC, True) player_data.raw_data # Test a PSN profile player_data = over_stats.PlayerProfile('EhhFreezy', over_stats.PLAT_PSN) assert type(player_data.raw_data) is dict # Test a non existing PSN profile with pytest.raises(over_stats.errors.PlayerNotFound): player_data = over_stats.PlayerProfile('ThisIsNotAnExistingProfile', over_stats.PLAT_PC, True) player_data.raw_data # Test an XBL profile player_data = over_stats.PlayerProfile('Dethroned', over_stats.PLAT_XBL) assert type(player_data.raw_data) is dict # Test a non existing XBL profile with pytest.raises(over_stats.errors.PlayerNotFound): player_data = over_stats.PlayerProfile('AnotherNonExistigProfile', over_stats.PLAT_PC, True) player_data.raw_data
def find3MostPlayed(battletag): mostPlayed = {'hero1': {}, 'hero2': {}, 'hero3': {}} playerData = over_stats.PlayerProfile(battletag) heroes = playerData.stat_heroes('competitive') heroesDict = {} for x in heroes: if((x != 'ALL HEROES')): heroesDict[x] = convertTime(playerData.stats('competitive', x, 'Game', 'Time Played')) for x in range(0,3): key = findKey(heroesDict, max(heroesDict.values())) wins = playerData.stats('competitive', key, 'Game', 'Games Won') total = playerData.stats('competitive', key, 'Game', 'Games Played') mostPlayed['hero'+str(x+1)] = [key, heroesDict[key], (wins/total)] heroesDict.pop(key) mostPlayed['totalPlaytime'] = convertTime(playerData.stats('competitive', 'ALL HEROES', 'Game', 'Time Played')) mostPlayed['totalWinrate'] = (playerData.stats('competitive', 'ALL HEROES', 'Game', 'Games Won'))/(playerData.stats('competitive', 'ALL HEROES', 'Game', 'Games Played')) print(mostPlayed) return mostPlayed
import json import over_stats # Initialize a player profile by providing the player tag and the platform. # the platform is optional and by default it is 'pc'. Other valid values are # 'xbl' and 'psn' player_data = over_stats.PlayerProfile('Cyrus#1852') # or # player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) # Ther is a bug in the boto3 library that causes it not to be able to handle # floats. To get around this issue there is flag that you can use to wrap floats # into a Decimal. Be careful that Decimals cannot be dumped to json. # player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN, True) # Download and parse the profile's data player_data.load_data() # Print the entire profile's data in JSON format # print (json.dumps(player_data.raw_data, indent=4)) # You can also use the helper methods to access the data you want for mode in over_stats.MODES: # mode will be 'quickplay' or 'competitive' # print (f"Game Mode: {mode}") # print ("Comparison Types Available: " + str(player_data.comparison_types(mode))) # for comparison_type in player_data.comparison_types(mode): # # A comparison type will be one of the options in the 'Top Heroes' section, 'Times Played', 'Games Won', # # 'Weapon Accuracy', etc # print (f" - Comparison Type: {comparison_type}") # print (" - Heroes available to compare: " + str(player_data.comparison_heroes(mode, comparison_type)))
def test_json_dump_decimal(): player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN, True) with pytest.raises(TypeError): result = json.dumps(player_data.raw_data)
def test_json_dump(): player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) result = json.dumps(player_data.raw_data) assert type(result) is str
def test_object_init_perf(): start_time = time.perf_counter() player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) end_time = time.perf_counter() result = end_time - start_time assert result < 0.0001
import json import over_stats # Initialize a player profile by providing the player tag and the platform. # the platform is optional and by default it is 'pc'. Other valid values are # 'xbl' and 'psn' player_data = over_stats.PlayerProfile('ZanyDruid#13868') # or # player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN) # Ther is a bug in the boto3 library that causes it not to be able to handle # floats. To get around this issue there is flag that you can use to wrap floats # into a Decimal. Be careful that Decimals cannot be dumped to json. # player_data = over_stats.PlayerProfile('acesarramsan', over_stats.PLAT_PSN, True) # Download and parse the profile's data player_data.load_data() # Print the entire profile's data in JSON format # print (json.dumps(player_data.raw_data, indent=4)) # You can also use the helper methods to access the data you want for mode in player_data.modes(): # mode will be 'quickplay' or 'competitive' print(f"Game Mode: {mode}") print("Comparison Types Available: " + str(player_data.comparison_types(mode))) for comparison_type in player_data.comparison_types(mode): # A comparison type will be one of the options in the 'Top Heroes' section, 'Times Played', 'Games Won', # 'Weapon Accuracy', etc print(f" - Comparison Type: {comparison_type}")