예제 #1
1
def retrieveLot(lotID):
    lot = lotID.get()
    
    container = LOTContainer()
    container.lot = lot
    container.games = list(Game.query(Game.lotID == lotID.id()))
    
    #Load all players that are referenced by the LOT.  First, get their player IDs and remove dupes
    pids = set(flatten([g.players for g in container.games])) | set(lot.playersParticipating) | set(lot.playerRanks)
    
    #logging.info("Loading lot " + str(lotID) + " got " + str(len(pids)) + " pids")
    
    #Turn the player IDs into Player instances
    players = list(ndb.get_multi([ndb.Key(Player, p) for p in pids]))
    
    #Store them as a dictionary so we can easily look them up by id later
    container.players = dict([(p.key.id(), p) for p in players if p is not None])
    
    return container
예제 #2
0
    def post(self, lotID):
        if not TestMode:
            return self.response.write(
                "api.TestMode is not enabled.  This page should only be used while testing."
            )

        container = lot.getLot(lotID)

        if 'ClearData' in self.request.POST:
            #User clicked Clear Data, delete all games and players
            ndb.delete_multi([
                o.key for o in Game.query(Game.lotID == container.lot.key.id())
            ])
            container.lot.playerRanks = []
            container.lot.playerRating = {}
            container.lot.playerMean = {}
            container.lot.playerStandardDeviation = {}
            container.lot.put()
            container.changed()
            memcache.flush_all()
            TestPage.renderPage(self, lotID, 'Deleted all games')
        elif 'RunCron' in self.request.POST:
            #Just execute the same thing that we'd do if we hit /cron, but also time it
            start = datetime.now()
            cron.execute(self.request, container)
            TestPage.renderPage(
                self, lotID,
                'Cron finished in ' + unicode(datetime.now() - start))
        elif 'AddPlayers' in self.request.POST:
            #Add some dummy player data. It won't work on warlight.net of course, but if TestMode is enabled it won't ever be passed there.   Just be sure and delete it before disabling TestMode.
            numPlayers = long(self.request.POST["NumPlayers"])

            for z in range(numPlayers):
                name = ''.join(
                    random.choice(string.ascii_uppercase + string.digits)
                    for x in range(5))
                p = Player(name=name,
                           inviteToken=name,
                           color="#0000FF",
                           customProperties={},
                           numberOfGamesAtOnce=2)
                p.put()
                container.lot.playersParticipating.append(p.key.id())

            container.lot.put()
            container.changed()
            TestPage.renderPage(self, lotID,
                                'Added ' + str(numPlayers) + ' fake players')
        elif 'FlushCache' in self.request.POST:
            if memcache.flush_all():
                TestPage.renderPage(self, lotID,
                                    'Deleted everything from cache')
            else:
                TestPage.renderPage(self, lotID,
                                    'Error while trying to flush cache')
        elif 'Test' in self.request.POST:
            #Just a blank space for testing random stuff
            TestPage.renderPage(self, lotID, 'Ran test code')
        else:
            self.response.write("No handler")
예제 #3
0
 def get(self, playerID):
     playerID = long(playerID)
     p = Player.get_by_id(playerID)
     games = Game.query(Game.players == playerID)
     self.response.write(
         get_template('viewplayer.html').render({
             'player': p,
             'games': games
         }))
 def get(self, playerID, lotID):
     playerID = long(playerID)
     p = Player.get_by_id(playerID)
     games = Game.query(Game.players == playerID)
     container = lot.getLot(lotID)
     
     currentPlayer = None
     if 'authenticatedtoken' in self.session:
         inviteToken = self.session['authenticatedtoken']
         currentPlayer = Player.query(Player.inviteToken == inviteToken).get()
     
     self.response.write(get_template('viewplayer.html').render({'player': p, 'games': games, 'currentPlayer': currentPlayer, 'container':container}))
예제 #5
0
파일: test.py 프로젝트: FizzerWL/CLOT
  def post(self, lotID):
    if not TestMode:
      return self.response.write("api.TestMode is not enabled.  This page should only be used while testing.")

    container = lot.getLot(lotID)

    if 'ClearData' in self.request.POST:
      #User clicked Clear Data, delete all games and players
      ndb.delete_multi([o.key for o in Game.query(Game.lotID == container.lot.key.id())])
      container.lot.playersParticipating = []
      container.lot.playerRanks = []
      container.lot.put()
      container.changed()
      memcache.flush_all()
      TestPage.renderPage(self, lotID, 'Deleted all games and players')

    elif 'RunCron' in self.request.POST:
      #Just execute the same thing that we'd do if we hit /cron, but also time it
      start = datetime.now()
      cron.execute(self.request, container)
      TestPage.renderPage(self, lotID, 'Cron finished in ' + unicode(datetime.now() - start))
    
    elif 'AddPlayers' in self.request.POST:
      #Add some dummy player data. It won't work on warlight.net of course, but if TestMode is enabled it won't ever be passed there.   Just be sure and delete it before disabling TestMode.
      numPlayers = long(self.request.POST["NumPlayers"])
      
      for z in range(numPlayers):
        name = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(5))
        p = Player(name=name, inviteToken=name, color="#0000FF")
        p.put()
        container.lot.playersParticipating.append(p.key.id())
      
      container.lot.put()
      container.changed()
      TestPage.renderPage(self, lotID, 'Added ' + str(numPlayers) + ' fake players')

    elif 'FlushCache' in self.request.POST:
      if memcache.flush_all():
        TestPage.renderPage(self, lotID, 'Deleted everything from cache')
      else:
        TestPage.renderPage(self, lotID, 'Error while trying to flush cache')

    elif 'Test' in self.request.POST:

      #Just a blank space for testing random stuff


      
      TestPage.renderPage(self, lotID, 'Ran test code')

    else:
      self.response.write("No handler")
    def get(self, playerID, lotID):
        playerID = long(playerID)
        p = Player.get_by_id(playerID)
        games = Game.query(Game.players == playerID)
        container = lot.getLot(lotID)

        currentPlayer = None
        if 'authenticatedtoken' in self.session:
            inviteToken = self.session['authenticatedtoken']
            currentPlayer = Player.query(
                Player.inviteToken == inviteToken).get()

        self.response.write(
            get_template('viewplayer.html').render({
                'player': p,
                'games': games,
                'currentPlayer': currentPlayer,
                'container': container
            }))
예제 #7
0
파일: viewplayer.py 프로젝트: FizzerWL/CLOT
 def get(self, playerID):
   playerID = long(playerID)
   p = Player.get_by_id(playerID)
   games = Game.query(Game.players == playerID)
   self.response.write(get_template('viewplayer.html').render({'player': p, 'games': games}))