本文整理汇总了Python中KNN.getTopGames方法的典型用法代码示例。如果您正苦于以下问题:Python KNN.getTopGames方法的具体用法?Python KNN.getTopGames怎么用?Python KNN.getTopGames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KNN
的用法示例。
在下文中一共展示了KNN.getTopGames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gameRecommendations
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import getTopGames [as 别名]
def gameRecommendations(u_name):
# Get API key
all_api_keys1 = get_keys("./num1.txt")
all_api_keys2 = get_keys("./num2.txt")
api_key = str(all_api_keys1[0]) + str(all_api_keys2[0])
if len(api_key) != 32:
print("Uh-oh, don't forget to enter your API key!")
return
# Set up a requests session to allow retries when a request fails
session = reqGet.Session()
session.mount("http://", reqGet.adapters.HTTPAdapter(max_retries=10))
games_response_json = getUserGames(u_name, api_key)
all_games = loadGameIDs("./data/id_header.csv")
# Get all of the game names and IDs from steam and save them in a dictionary for easy usage
game_list = json.loads(session.get(url="http://api.steampowered.com/ISteamApps/GetAppList/v2").text)['applist']['apps']
game_dict = {}
for game in game_list:
game_dict[game['appid']] = game
user_game_array = ["0"] * len(all_games)
if not games_response_json:
return
for game in games_response_json:
if game['appid'] in all_games:
game_index = all_games.index(game['appid'])
user_game_array[game_index] = "1"
all_games = [game_dict[x]['name'] for x in all_games]
game_bit_string = int(''.join(user_game_array), 2)
dataset = KNN.loadDataset("./data/games_by_username_all.csv")
closest = KNN.findClosest(dataset, game_bit_string, 100)
return KNN.getTopGames(KNN.getVotes(all_games, closest, game_bit_string), 5)