def initializeplayers(): for playername, info in playerinfo.items(): player = { 'playername': playername, 'teamname': info[1], 'role': info[0], 'statistics': {}, 'latestgame': {}, 'gamesplayed': [] } cPlayers.update({'playername':playername}, player, upsert=True)
def updateplayerdata(): for playername, info in playerinfo.items(): gamesplayed = [] gamesplayedarray = [] latestgameplayedid = 0 gamesplayedquery = cGames.find({'playerlist': playername},) for game in gamesplayedquery: gamesplayed.append(game) for game in gamesplayed: gamesplayedarray.append(game['gameID']) for game in gamesplayed: if game['gameID'] == max(gamesplayedarray): latestgame = game cPlayers.update({'playername':playername}, {'$set':{'gamesplayed':gamesplayed, 'latestgame':latestgame}})