Пример #1
0
    def test_bills_count(self):
        from the_tale.forum.models import Category, SubCategory
        from the_tale.game.bills.conf import bills_settings
        from the_tale.game.bills import relations as bills_relations

        forum_category = Category.objects.create(caption="category-1", slug="category-1")
        SubCategory.objects.create(
            caption=bills_settings.FORUM_CATEGORY_UID + "-caption",
            uid=bills_settings.FORUM_CATEGORY_UID,
            category=forum_category,
        )

        self.create_bill(0, self.account_2, bills_relations.BILL_STATE.VOTING)
        self.create_bill(1, self.account_2, bills_relations.BILL_STATE.ACCEPTED)
        self.create_bill(2, self.account_2, bills_relations.BILL_STATE.REJECTED)

        self.create_bill(3, self.account_3, bills_relations.BILL_STATE.ACCEPTED)
        self.create_bill(4, self.account_3, bills_relations.BILL_STATE.ACCEPTED)
        self.create_bill(5, self.account_3, bills_relations.BILL_STATE.REJECTED)

        self.create_bill(6, self.account_1, bills_relations.BILL_STATE.REJECTED)
        self.create_bill(7, self.account_1, bills_relations.BILL_STATE.REJECTED)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.bills_count for rv in RatingValues.objects.all().order_by("account__id")], [0, 1, 2, 0])
Пример #2
0
 def test_fast_accounts_filtration(self):
     register_user("user_5")
     RatingValuesPrototype.recalculate()
     self.assertEqual(
         [rv.account_id for rv in RatingValues.objects.all().order_by("account__id")],
         [self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id],
     )
Пример #3
0
    def test_level(self):
        self.set_values(self.account_1, level=10)
        self.set_values(self.account_2, level=9)
        self.set_values(self.account_3, level=7)
        self.set_values(self.account_4, level=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.level for rv in RatingValues.objects.all().order_by("account__id")], [10, 9, 7, 1])
Пример #4
0
    def test_banned_accounts_filtration(self):
        account_5 = self.accounts_factory.create_account(is_fast=True)

        account_5.ban_game(1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.account_id for rv in RatingValues.objects.all().order_by('account__id')],
                         [self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id, ])
Пример #5
0
    def test_physic_power(self):
        self.set_values(self.account_1, physic_power=9)
        self.set_values(self.account_2, physic_power=10)
        self.set_values(self.account_3, physic_power=7)
        self.set_values(self.account_4, physic_power=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.physic_power for rv in RatingValues.objects.all().order_by("account__id")], [9, 10, 7, 1])
Пример #6
0
    def test_help_count(self):
        self.set_values(self.account_1, help_count=10)
        self.set_values(self.account_2, help_count=1)
        self.set_values(self.account_3, help_count=17)
        self.set_values(self.account_4, help_count=5)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.help_count for rv in RatingValues.objects.all().order_by("account__id")], [10, 1, 17, 5])
Пример #7
0
    def test_might(self):
        self.set_values(self.account_1, might=10)
        self.set_values(self.account_2, might=1)
        self.set_values(self.account_3, might=17)
        self.set_values(self.account_4, might=5)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.might for rv in RatingValues.objects.all().order_by('account__id')],
                         [10.0, 1.0, 17.0, 5.0 ])
Пример #8
0
    def test_gifts_returned(self):
        self.set_values(self.account_1, gifts_returned=9)
        self.set_values(self.account_2, gifts_returned=10)
        self.set_values(self.account_3, gifts_returned=7)
        self.set_values(self.account_4, gifts_returned=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.gifts_returned for rv in RatingValues.objects.all().order_by('account__id')],
                         [9, 10, 7, 1 ])
Пример #9
0
    def test_banned_accounts_filtration(self):
        register_user('user_5', '*****@*****.**', '111111')
        account_5 = AccountPrototype.get_by_nick('user_5')

        account_5.ban_game(1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.account_id for rv in RatingValues.objects.all().order_by('account__id')],
                         [self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id, ])
    def handle(self, *args, **options):

        print "recalculate values"

        RatingValuesPrototype.recalculate()

        print "recalculate places"

        RatingPlacesPrototype.recalculate()
Пример #11
0
    def test_physic_power(self):
        self.set_values(self.account_1, physic_power=9)
        self.set_values(self.account_2, physic_power=10)
        self.set_values(self.account_3, physic_power=7)
        self.set_values(self.account_4, physic_power=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.physic_power
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [9, 10, 7, 1])
Пример #12
0
    def test_gifts_returned(self):
        self.set_values(self.account_1, gifts_returned=9)
        self.set_values(self.account_2, gifts_returned=10)
        self.set_values(self.account_3, gifts_returned=7)
        self.set_values(self.account_4, gifts_returned=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.gifts_returned
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [9, 10, 7, 1])
Пример #13
0
 def test_initialize(self):
     RatingValuesPrototype.recalculate()
     self.assertEqual([
         rv.account_id
         for rv in RatingValues.objects.all().order_by('account__id')
     ], [
         self.account_1.id,
         self.account_2.id,
         self.account_3.id,
         self.account_4.id,
     ])
Пример #14
0
    def test_might(self):
        self.set_values(self.account_1, might=10)
        self.set_values(self.account_2, might=1)
        self.set_values(self.account_3, might=17)
        self.set_values(self.account_4, might=5)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.might
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [10.0, 1.0, 17.0, 5.0])
Пример #15
0
    def test_phrases_count(self):
        self.create_linguistic_contribution(account=self.account_1, type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE, entity_id=1)
        self.create_linguistic_contribution(account=self.account_1, type=linguistics_relations.CONTRIBUTION_TYPE.WORD, entity_id=1)
        self.create_linguistic_contribution(account=self.account_1, type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE, entity_id=2)
        self.create_linguistic_contribution(account=self.account_3, type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE, entity_id=2)
        self.create_linguistic_contribution(account=self.account_3, type=linguistics_relations.CONTRIBUTION_TYPE.WORD, entity_id=2)
        self.create_linguistic_contribution(account=self.account_2, type=linguistics_relations.CONTRIBUTION_TYPE.WORD, entity_id=3)

        RatingValuesPrototype.recalculate()
        self.assertEqual([rv.phrases_count for rv in RatingValues.objects.all().order_by('account__id')],
                         [2, 0, 1, 0])
Пример #16
0
    def test_level(self):
        self.set_values(self.account_1, level=10)
        self.set_values(self.account_2, level=9)
        self.set_values(self.account_3, level=7)
        self.set_values(self.account_4, level=1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.level
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [10, 9, 7, 1])
Пример #17
0
    def test_help_count(self):
        self.set_values(self.account_1, help_count=10)
        self.set_values(self.account_2, help_count=1)
        self.set_values(self.account_3, help_count=17)
        self.set_values(self.account_4, help_count=5)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.help_count
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [10, 1, 17, 5])
Пример #18
0
 def test_fast_accounts_filtration(self):
     register_user('user_5')
     RatingValuesPrototype.recalculate()
     self.assertEqual([
         rv.account_id
         for rv in RatingValues.objects.all().order_by('account__id')
     ], [
         self.account_1.id,
         self.account_2.id,
         self.account_3.id,
         self.account_4.id,
     ])
Пример #19
0
 def test_fast_accounts_filtration(self):
     self.accounts_factory.create_account(is_fast=True)
     RatingValuesPrototype.recalculate()
     self.assertEqual([
         rv.account_id
         for rv in RatingValues.objects.all().order_by('account__id')
     ], [
         self.account_1.id,
         self.account_2.id,
         self.account_3.id,
         self.account_4.id,
     ])
Пример #20
0
    def test_pvp(self):
        self.set_values(self.account_1, pvp_battles_1x1_number=0, pvp_battles_1x1_victories=0)
        self.set_values(self.account_2, pvp_battles_1x1_number=5, pvp_battles_1x1_victories=1)
        self.set_values(self.account_3, pvp_battles_1x1_number=100, pvp_battles_1x1_victories=2)
        self.set_values(self.account_4, pvp_battles_1x1_number=200, pvp_battles_1x1_victories=3)

        RatingValuesPrototype.recalculate()

        self.assertEqual(heroes_settings.MIN_PVP_BATTLES, 25)

        self.assertEqual([rv.pvp_battles_1x1_number for rv in RatingValues.objects.all().order_by('account__id')],
                         [0, 5, 100, 200 ])

        self.assertEqual([rv.pvp_battles_1x1_victories for rv in RatingValues.objects.all().order_by('account__id')],
                         [0, 0.0, 0.02, 0.015])
Пример #21
0
    def test_banned_accounts_filtration(self):
        register_user('user_5', '*****@*****.**', '111111')
        account_5 = AccountPrototype.get_by_nick('user_5')

        account_5.ban_game(1)

        RatingValuesPrototype.recalculate()
        self.assertEqual([
            rv.account_id
            for rv in RatingValues.objects.all().order_by('account__id')
        ], [
            self.account_1.id,
            self.account_2.id,
            self.account_3.id,
            self.account_4.id,
        ])
Пример #22
0
 def test_initialize(self):
     RatingValuesPrototype.recalculate()
     self.assertEqual(
         [rv.account_id for rv in RatingValues.objects.all().order_by("account__id")],
         [self.account_1.id, self.account_2.id, self.account_3.id, self.account_4.id],
     )
Пример #23
0
    def show(self, page=1):  # pylint: disable=R0914

        ratings_updated_at_timestamp = settings.get(
            ratings_settings.SETTINGS_UPDATE_TIMESTEMP_KEY, None)

        ratings_query = RatingPlaces.objects.all().select_related()

        place_getter = None
        value_getter = None

        if self.rating_type.is_MIGHT:
            ratings_query = ratings_query.filter(
                account__ratingvalues__might__gt=0).order_by('might_place')
            place_getter = lambda places: places.might_place
            value_getter = lambda values: '%.2f' % values.might

        elif self.rating_type.is_BILLS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__bills_count__gt=0).order_by(
                    'bills_count_place')
            place_getter = lambda places: places.bills_count_place
            value_getter = lambda values: values.bills_count

        elif self.rating_type.is_MAGIC_POWER:
            ratings_query = ratings_query.order_by('magic_power_place')
            place_getter = lambda places: places.magic_power_place
            value_getter = lambda values: values.magic_power

        elif self.rating_type.is_PHYSIC_POWER:
            ratings_query = ratings_query.order_by('physic_power_place')
            place_getter = lambda places: places.physic_power_place
            value_getter = lambda values: values.physic_power

        elif self.rating_type.is_LEVEL:
            ratings_query = ratings_query.order_by('level_place')
            place_getter = lambda places: places.level_place
            value_getter = lambda values: values.level

        elif self.rating_type.is_PHRASES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__phrases_count__gt=0).order_by(
                    'phrases_count_place')
            place_getter = lambda places: places.phrases_count_place
            value_getter = lambda values: values.phrases_count

        elif self.rating_type.is_PVP_BATTLES_1x1_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_number__gt=0).order_by(
                    'pvp_battles_1x1_number_place')
            place_getter = lambda places: places.pvp_battles_1x1_number_place
            value_getter = lambda values: values.pvp_battles_1x1_number

        elif self.rating_type.is_PVP_BATTLES_1x1_VICTORIES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_victories__gt=0
            ).order_by('pvp_battles_1x1_victories_place')
            place_getter = lambda places: places.pvp_battles_1x1_victories_place
            value_getter = lambda values: '%.2f%%' % (
                values.pvp_battles_1x1_victories * 100)

        elif self.rating_type.is_REFERRALS_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__referrals_number__gt=0).order_by(
                    'referrals_number_place')
            place_getter = lambda places: places.referrals_number_place
            value_getter = lambda values: values.referrals_number

        elif self.rating_type.is_ACHIEVEMENTS_POINTS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__achievements_points__gt=0).order_by(
                    'achievements_points_place')
            place_getter = lambda places: places.achievements_points_place
            value_getter = lambda values: values.achievements_points

        elif self.rating_type.is_HELP_COUNT:
            ratings_query = ratings_query.order_by('help_count_place')
            place_getter = lambda places: places.help_count_place
            value_getter = lambda values: values.help_count

        elif self.rating_type.is_GIFTS_RETURNED:
            ratings_query = ratings_query.filter(
                account__ratingvalues__gifts_returned__gt=0).order_by(
                    'gifts_returned_place')
            place_getter = lambda places: places.gifts_returned_place
            value_getter = lambda values: values.gifts_returned

        elif self.rating_type.is_POLITICS_POWER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__politics_power__gt=0).order_by(
                    'politics_power_place')
            place_getter = lambda places: places.politics_power_place
            value_getter = lambda values: '%.2f%%' % (values.politics_power *
                                                      100)

        ratings_count = ratings_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(reverse('game:ratings:show',
                                         args=[self.rating_type.value]),
                                 arguments={'page': page})

        paginator = Paginator(page, ratings_count,
                              ratings_settings.ACCOUNTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        rating_from, rating_to = paginator.page_borders(page)

        ratings = [
            RatingPlacesPrototype(rating_model)
            for rating_model in ratings_query[rating_from:rating_to]
        ]

        accounts_ids = [rating.account_id for rating in ratings]
        clans_ids = set(
            AccountPrototype._db_filter(id__in=accounts_ids).exclude(
                clan_id=None).values_list('clan_id', flat=True))

        heroes = {
            hero.account_id: hero
            for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)
        }

        values = dict(
            (values_model.account_id, RatingValuesPrototype(values_model))
            for values_model in RatingValues.objects.filter(
                account_id__in=accounts_ids))

        clans = {
            clan.id: clan
            for clan in ClanPrototype.get_list_by_id(list(clans_ids))
        }

        return self.template(
            'ratings/show.html', {
                'ratings': ratings,
                'ratings_updated_at_timestamp': ratings_updated_at_timestamp,
                'heroes': heroes,
                'values': values,
                'clans': clans,
                'paginator': paginator,
                'place_getter': place_getter,
                'value_getter': value_getter,
                'rating_type': self.rating_type,
                'RATING_TYPE': RATING_TYPE,
                'rating_from': rating_from,
                'rating_to': rating_to
            })