예제 #1
0
    def test_folclor_might(self):
        old_might = calculate_might(self.account)

        post = BlogPostPrototype.create(author=self.account,
                                        caption='caption',
                                        text='text')

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        new_might = calculate_might(self.account)

        self.assertTrue(new_might > old_might)

        post = BlogPostPrototype.create(author=self.account_2,
                                        caption='caption',
                                        text='text')

        Post.objects.all().delete()
        # Thread.objects.all().delete()
        Vote.objects.all().delete()

        post.state = BLOG_POST_STATE.ACCEPTED
        post._model.votes = 1
        post.save()

        self.assertEqual(new_might, calculate_might(self.account))
예제 #2
0
def calculate_might(account): # pylint: disable=R0914

    MIGHT_FROM_REFERRAL = 0.1

    might = 0

    might += Post.objects.filter(thread__subcategory__restricted=False,
                                 author_id=account.id,
                                 state=POST_STATE.DEFAULT).count() * relations.MIGHT_AMOUNT.FOR_FORUM_POST.amount
    might += Thread.objects.filter(subcategory__restricted=False,
                                   author_id=account.id).count() * relations.MIGHT_AMOUNT.FOR_FORUM_THREAD.amount

    might += Vote.objects.filter(owner_id=account.id).exclude(type=VOTE_TYPE.REFRAINED).count() * relations.MIGHT_AMOUNT.FOR_BILL_VOTE.amount
    might += Bill.objects.filter(owner_id=account.id, state=BILL_STATE.ACCEPTED).count() * relations.MIGHT_AMOUNT.FOR_BILL_ACCEPTED.amount

    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.WORD,
                                         might_per_added_entity=relations.MIGHT_AMOUNT.FOR_ADDED_WORD_FOR_PLAYER.amount,
                                         might_per_edited_entity=relations.MIGHT_AMOUNT.FOR_EDITED_WORD_FOR_PLAYER.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.PLAYER)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.WORD,
                                         might_per_added_entity=relations.MIGHT_AMOUNT.FOR_ADDED_WORD_FOR_MODERATOR.amount,
                                         might_per_edited_entity=relations.MIGHT_AMOUNT.FOR_EDITED_WORD_FOR_MODERATOR.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.MODERATOR)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE,
                                         might_per_added_entity=relations.MIGHT_AMOUNT.FOR_ADDED_TEMPLATE_FOR_PLAYER.amount,
                                         might_per_edited_entity=relations.MIGHT_AMOUNT.FOR_EDITED_TEMPLATE_FOR_PLAYER.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.PLAYER)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE,
                                         might_per_added_entity=relations.MIGHT_AMOUNT.FOR_ADDED_TEMPLATE_FOR_MODERATOR.amount,
                                         might_per_edited_entity=relations.MIGHT_AMOUNT.FOR_EDITED_TEMPLATE_FOR_MODERATOR.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.MODERATOR)

    folclor_posts = BlogPostProtype.from_query(BlogPostProtype._db_filter(author_id=account.id, state=BLOG_POST_STATE.ACCEPTED))
    folclor_texts = (strip_tags(post.text_html) for post in folclor_posts)

    for text in folclor_texts:
        characters_count = len(text)
        might += folclor_post_might(characters_count)

    referrals_mights = AccountPrototype._model_class.objects.filter(referral_of=account.id).aggregate(models.Sum('might'))['might__sum']

    might += referrals_mights * MIGHT_FROM_REFERRAL if referrals_mights else 0

    for award_type in relations.AWARD_TYPE.records:
        might += Award.objects.filter(account_id=account.id, type=award_type).count() * relations.MIGHT_AMOUNT.index_award[award_type][0].amount

    return might
예제 #3
0
    def test_folclor_might__only_text(self):
        self.assertEqual(calculate_might(self.account), 0)

        BlogPostPrototype.create(author=self.account, caption='caption', text='text')

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        might = calculate_might(self.account)

        BlogPostPrototype.create(author=self.account, caption='caption', text='[b]text[/b]')

        self.assertEqual(calculate_might(self.account), might * 2)
예제 #4
0
def calculate_might(account): # pylint: disable=R0914

    MIGHT_FROM_REFERRAL = 0.1

    might = 0

    might += Post.objects.filter(thread__subcategory__restricted=False,
                                 author_id=account.id,
                                 state=POST_STATE.DEFAULT).count() * relations.MIGHT_AMOUNT.FOR_FORUM_POST.amount
    might += Thread.objects.filter(subcategory__restricted=False,
                                   author_id=account.id).count() * relations.MIGHT_AMOUNT.FOR_FORUM_THREAD.amount

    might += Vote.objects.filter(owner_id=account.id).exclude(type=VOTE_TYPE.REFRAINED).count() * relations.MIGHT_AMOUNT.FOR_BILL_VOTE.amount
    might += Bill.objects.filter(owner_id=account.id, state=BILL_STATE.ACCEPTED).count() * relations.MIGHT_AMOUNT.FOR_BILL_ACCEPTED.amount

    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.WORD,
                                         might_per_entity=relations.MIGHT_AMOUNT.FOR_ADDED_WORD_FOR_PLAYER.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.PLAYER)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.WORD,
                                         might_per_entity=relations.MIGHT_AMOUNT.FOR_ADDED_WORD_FOR_MODERATOR.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.MODERATOR)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE,
                                         might_per_entity=relations.MIGHT_AMOUNT.FOR_ADDED_TEMPLATE_FOR_PLAYER.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.PLAYER)
    might += calculate_linguistics_migth(account.id,
                                         contribution_type=linguistics_relations.CONTRIBUTION_TYPE.TEMPLATE,
                                         might_per_entity=relations.MIGHT_AMOUNT.FOR_ADDED_TEMPLATE_FOR_MODERATOR.amount,
                                         source=linguistics_relations.CONTRIBUTION_SOURCE.MODERATOR)

    folclor_posts = BlogPostProtype.from_query(BlogPostProtype._db_filter(author_id=account.id, state=BLOG_POST_STATE.ACCEPTED))
    folclor_texts = (strip_tags(post.text_html) for post in folclor_posts)

    for text in folclor_texts:
        characters_count = len(text)
        might += folclor_post_might(characters_count)

    referrals_mights = AccountPrototype._model_class.objects.filter(referral_of=account.id).aggregate(models.Sum('might'))['might__sum']

    might += referrals_mights * MIGHT_FROM_REFERRAL if referrals_mights else 0

    for award_type in relations.AWARD_TYPE.records:
        might += Award.objects.filter(account_id=account.id, type=award_type).count() * relations.MIGHT_AMOUNT.index_award[award_type][0].amount

    return might
예제 #5
0
    def test_folclor_might(self):
        old_might = calculate_might(self.account)

        post = BlogPostPrototype.create(author=self.account, caption='caption', text='text')

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        new_might = calculate_might(self.account)

        self.assertTrue(new_might > old_might)

        post = BlogPostPrototype.create(author=self.account_2, caption='caption', text='text')

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        post.state = BLOG_POST_STATE.ACCEPTED
        post._model.votes = 1
        post.save()

        self.assertEqual(new_might, calculate_might(self.account))
예제 #6
0
    def test_folclor_might__from_characters(self):

        with self.check_delta(lambda: calculate_might(self.account), relations.MIGHT_AMOUNT.FOR_MIN_FOLCLOR_POST.amount*(1 + 1.5 + 2.1)):

            BlogPostPrototype.create(author=self.account, caption='caption', text='x'*blogs_conf.settings.MIN_TEXT_LENGTH)
            BlogPostPrototype.create(author=self.account, caption='caption-2', text='y'*blogs_conf.settings.MIN_TEXT_LENGTH*2)
            BlogPostPrototype.create(author=self.account, caption='caption-3', text='z'*blogs_conf.settings.MIN_TEXT_LENGTH*4)

            Post.objects.all().delete()
            Thread.objects.all().delete()
            Vote.objects.all().delete()