from modules.core.Game import Game
from modules.core.Games import Games
from modules.core.PlayerAssessment import PlayerAssessment, PlayerAssessments

def recentGames(playerAssessments, gameJSONs):
  try:
    playerAssessments = PlayerAssessments(sorted(playerAssessments.playerAssessments,
      key = lambda x: (x.assessment, x.date), reverse=True))
    gs1 = []
    gs2 = []
    print(gameJSONs)
    for playerAssessment in playerAssessments.playerAssessments:
      gameJSON = gameJSONs.get(playerAssessment.gameId, None)
      pgn = gameJSON.get('pgn', '')
      if gameJSON is not None and 'variant' not in gameJSON and 'emts' in gameJSON and gameLength(pgn) > 44:
        gs1.append(Game(playerAssessment.gameId, pgn, gameJSON['emts']))
    games1 = Games(gs1[:5])
    """
    for gameId, gameJSON in gameJSONs.items():
      pgn = gameJSON.get('pgn', '')
      if not games1.hasId(gameId) and 'variant' not in gameJSON and 'emts' in gameJSON and gameLength(pgn) > 44:
        gs2.append(Game(gameId, pgn, gameJSON['emts']))
    games = gs1 + gs2
    """
    games = gs1
    games = Games(games[:10])
    return games
  except ValueError:
    return Games([])
  except IndexError:
    return Games([])

def gameLength(pgn):
    return len(pgn.split(' '))
@@ -375,29 +375,8 @@
  %5B%5D%0A
-    print(gameJSONs)%0A
     
@@ -744,27 +744,24 @@
 s1%5B:5%5D)%0A    
-%22%22%22
 %0A    for gam
@@ -1009,96 +1009,38 @@
     
-games = gs1 + gs2%0A    %22%22%22%0A    games = gs1%0A    games = Games(games%5B:10%5D)%0A    return games
+return Games((gs1 + gs2)%5B:10%5D)
 %0A  e

remove debug points