Exemplo n.º 1
0
 def get_players_data(self, connection, app_id, clan_id, members):
     players_data = []
     for member in members:
         account_id = member['account_id']
         account_name = member['account_name']
         try:
             player_data = self.get_player_data(connection, app_id, clan_id, account_id, account_name)
             if self.requires_recalculation(player_data):
                 # get accounts stat
                 account_stats = self._retrieve_account_stats(account_id, app_id)
                 player_data = AccountStatsToPlayerDataMapper.map(account_stats, account_id, account_name)
                 personal_stats = self._retrieve_personal_stats(account_id, app_id)
                 player_data = AccountStatsToPlayerDataMapper.amend_player_data(player_data, personal_stats, account_id)
                 # create snapshot
                 self.create_snapshot(connection, player_data)
                 # calculate 30 day
                 from_date = AppTime.get_now() - datetime.timedelta(days=30)
                 self._calculate_stats_at_date(connection, player_data, from_date)
                 # update player_stat
                 PlayerRepository.update_player_stats(connection, player_data)
             players_data.append(player_data)
         except Exception as e:
             print('Failed on player: {account_name} - error: {error}'
                   .format(account_name=member['account_name'], error=str(e)))
     players_data.sort(key=lambda x: x['account_name'].lower())
     return players_data
Exemplo n.º 2
0
 def get_players_data(self, connection, app_id, clan_id, members):
     players_data = []
     for member in members:
         account_id = member['account_id']
         account_name = member['account_name']
         try:
             player_data = self.get_player_data(connection, app_id, clan_id,
                                                account_id, account_name)
             if self.requires_recalculation(player_data):
                 # get accounts stat
                 account_stats = self._retrieve_account_stats(
                     account_id, app_id)
                 player_data = AccountStatsToPlayerDataMapper.map(
                     account_stats, account_id, account_name)
                 personal_stats = self._retrieve_personal_stats(
                     account_id, app_id)
                 player_data = AccountStatsToPlayerDataMapper.amend_player_data(
                     player_data, personal_stats, account_id)
                 # create snapshot
                 self.create_snapshot(connection, player_data)
                 # calculate 30 day
                 from_date = AppTime.get_now() - datetime.timedelta(days=30)
                 self._calculate_stats_at_date(connection, player_data,
                                               from_date)
                 # update player_stat
                 PlayerRepository.update_player_stats(
                     connection, player_data)
             players_data.append(player_data)
         except Exception as e:
             print(
                 'Failed on player: {account_name} - error: {error}'.format(
                     account_name=member['account_name'], error=str(e)))
     players_data.sort(key=lambda x: x['account_name'].lower())
     return players_data
 def test_empty_source_data(self):
     accounts_data = {}
     player_data = AccountStatsToPlayerDataMapper.map(accounts_data, 0, 'test_player')
     expected = {}
     self.assertEqual(expected, player_data)
     accounts_data = None
     player_data = AccountStatsToPlayerDataMapper.map(accounts_data, 0, 'test_player')
     self.assertEqual(expected, player_data)
 def test_empty_source_data(self):
     accounts_data = {}
     player_data = AccountStatsToPlayerDataMapper.map(
         accounts_data, 0, 'test_player')
     expected = {}
     self.assertEqual(expected, player_data)
     accounts_data = None
     player_data = AccountStatsToPlayerDataMapper.map(
         accounts_data, 0, 'test_player')
     self.assertEqual(expected, player_data)
Exemplo n.º 5
0
 def get_player_data(self, connection, app_id, clan_id, account_id, account_name):
     record = PlayerRepository.get_player(connection, clan_id, account_id)
     if record is None:
         account_stats = self._retrieve_account_stats(account_id, app_id)
         player_data = AccountStatsToPlayerDataMapper.map(account_stats, account_id, account_name)
         personal_stats = self._retrieve_personal_stats(account_id, app_id)
         player_data = AccountStatsToPlayerDataMapper.amend_player_data(player_data, personal_stats, account_id)
         self.create_player_stat(connection, player_data)
     else:
         player_data = RecordToPlayerDataMapper.map(record)
     return player_data
Exemplo n.º 6
0
 def get_player_data(self, connection, app_id, clan_id, account_id,
                     account_name):
     record = PlayerRepository.get_player(connection, clan_id, account_id)
     if record is None:
         account_stats = self._retrieve_account_stats(account_id, app_id)
         player_data = AccountStatsToPlayerDataMapper.map(
             account_stats, account_id, account_name)
         personal_stats = self._retrieve_personal_stats(account_id, app_id)
         player_data = AccountStatsToPlayerDataMapper.amend_player_data(
             player_data, personal_stats, account_id)
         self.create_player_stat(connection, player_data)
     else:
         player_data = RecordToPlayerDataMapper.map(record)
     return player_data
 def test_normal_data(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = AccountStatsToPlayerDataMapper.map(AccountStatsFixtures.standard_accounts_record(),
                                                      512841364, 'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         "last_update": AppTime.get_now()
     }
     self.assertEqual(expected, player_data)
 def test_normal_data(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = AccountStatsToPlayerDataMapper.map(
         AccountStatsFixtures.standard_accounts_record(), 512841364,
         'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         "last_update": AppTime.get_now()
     }
     self.assertEqual(expected, player_data)