Example #1
0
 def post(self):
     self.stage = int(self.request.get('stage', 1))
     self.start_cursor = ndb.Cursor(urlsafe=self.request.get('cursor'))
     queue = taskqueue.Queue('logs-processing')
     if self.stage == 1:
         RecalcAllLogs.delete_all_stat()
         self.next_stage()
         self.abort(200)
     elif self.stage == 2:
         words = self.fetch_portion(GlobalDictionaryWord.query(GlobalDictionaryWord.used_times > 0))
         for fut in map(self.reset_word, words):
             fut.get_result()
     elif self.stage == 3:
         logs = self.fetch_portion(GameLog.query())
         for el in logs:
             if not el.ignored:
                 el.ignored = False
                 el.put()
     elif self.stage == 4:
         map(lambda k: queue.add_async(taskqueue.Task(url='/internal/add_game_to_statistic',
                                                      params={'game_key': k.urlsafe()})),
             self.fetch_portion(GameLog.query(GameLog.ignored == False), keys_only=True))
     elif self.stage == 5:
         map(lambda k: queue.add_async(taskqueue.Task(url='/internal/add_game_to_statistic',
                                       params={'game_key': k.urlsafe()})),
             self.fetch_portion(GameHistory.query(GameHistory.ignored == False), keys_only=True))
     if self.more and self.cursor:
         self.next_portion()
     else:
         self.next_stage()
Example #2
0
 def put(self, **kwargs):
     game_id = json.loads(self.request.body)['setup']['meta']['game.id']
     game_key = ndb.Key(GameLog, game_id).get()
     if game_key is None:
         log = GameLog(json=self.request.body, id=game_id)
         game_key = log.put().urlsafe()
         taskqueue.add(url='/internal/add_game_to_statistic', params={'game_key': game_key}, countdown=5)
     self.response.set_status(201)
Example #3
0
 def testPostV2NoEndTimestamp(self):
     log = GameLog(json=TEST_LOG_V2_NO_END_TIMESTAMP)
     game_key = log.put().urlsafe()
     request = Request.blank('/internal/add_game_to_statistic')
     request.method = 'POST'
     request.body = 'game_key=' + game_key
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
Example #4
0
 def testPostV1(self):
     game_id = json.loads(TEST_LOG_V1)['setup']['meta']['game.id']
     log = GameLog(json=TEST_LOG_V1, id=game_id)
     game_key = log.put().urlsafe()
     request = Request.blank('/internal/add_game_to_statistic')
     request.method = 'POST'
     request.body = 'game_key=' + game_key
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
Example #5
0
 def put(self, **kwargs):
     game_id = json.loads(self.request.body)['setup']['meta']['game.id']
     game_key = ndb.Key(GameLog, game_id).get()
     if game_key is None:
         log = GameLog(json=self.request.body, id=game_id)
         game_key = log.put().urlsafe()
         taskqueue.add(url='/internal/add_game_to_statistic',
                       params={'game_key': game_key},
                       countdown=5)
     self.response.set_status(201)
 def test_add_game_log(self):
     key = GameLog(json=LOG_JSON, id="test_log").put().urlsafe()
     words = [put_word(el) for el in WORDS]
     request = webapp2.Request.blank('/internal/add_game_to_statistic')
     request.method = 'POST'
     request.body = "game_key={}".format(key)
     response = request.get_response(main.app)
     self.assertEqual(response.status_int, 200)
     words = [el.get() for el in words]
     for i in range(len(words)):
         if i in EXPECTED_TIME:
             self.assertEqual(words[i].total_explanation_time,
                              EXPECTED_TIME[i])
             if EXPECTED_OUTCOME[i] == 'guessed':
                 self.assertGreaterEqual(len(words[i].counts_by_expl_time),
                                         EXPECTED_TIME[i] // 5)
                 self.assertEqual(
                     words[i].counts_by_expl_time[EXPECTED_TIME[i] // 5], 1)
             self.assertEqual(words[i].guessed_times,
                              1 if EXPECTED_OUTCOME[i] == 'guessed' else 0)
             self.assertEqual(words[i].failed_times,
                              1 if EXPECTED_OUTCOME[i] == 'failed' else 0)
             self.assertEqual(words[i].used_times, 1)
         else:
             self.assertEqual(words[i].total_explanation_time, 0)
             self.assertEqual(words[i].used_times, 0)
     tasks = self.taskq.get_filtered_tasks(
         url='/internal/recalc_rating_after_game')
     self.assertEqual(2, len(tasks))
     for el in tasks:
         j = urllib2.unquote(el.payload.split('=')[1]).replace('+', ' ')
         words = json.loads(j)
         self.assertIn([WORDS.index(w) for w in words], EXPECTED_RATES)
Example #7
0
 def post(self):
     self.stage = int(self.request.get('stage', 1))
     self.start_cursor = ndb.Cursor(urlsafe=self.request.get('cursor'))
     queue = taskqueue.Queue('logs-processing')
     if self.stage == 1:
         RecalcAllLogs.delete_all_stat()
         self.next_stage()
         self.abort(200)
     elif self.stage == 2:
         words = self.fetch_portion(
             GlobalDictionaryWord.query(
                 GlobalDictionaryWord.used_times > 0))
         for fut in map(self.reset_word, words):
             fut.get_result()
     elif self.stage == 3:
         logs = self.fetch_portion(GameLog.query())
         for el in logs:
             if not el.ignored:
                 el.ignored = False
                 el.put()
     elif self.stage == 4:
         map(
             lambda k: queue.add_async(
                 taskqueue.Task(url='/internal/add_game_to_statistic',
                                params={'game_key': k.urlsafe()})),
             self.fetch_portion(GameLog.query(GameLog.ignored == False),
                                keys_only=True))
     elif self.stage == 5:
         map(
             lambda k: queue.add_async(
                 taskqueue.Task(url='/internal/add_game_to_statistic',
                                params={'game_key': k.urlsafe()})),
             self.fetch_portion(
                 GameHistory.query(GameHistory.ignored == False),
                 keys_only=True))
     if self.more and self.cursor:
         self.next_portion()
     else:
         self.next_stage()
Example #8
0
 def post(self, **kwargs):
     log = GameLog(json=self.request.body)
     taskqueue.add(url='/internal/add_game_to_statistic',
                   params={'game_key': log.put().urlsafe()},
                   countdown=5)
     self.response.set_status(202)