当前位置: 首页>>代码示例>>Python>>正文


Python KarmaManager.recalculate_points方法代码示例

本文整理汇总了Python中karma.manager.KarmaManager.recalculate_points方法的典型用法代码示例。如果您正苦于以下问题:Python KarmaManager.recalculate_points方法的具体用法?Python KarmaManager.recalculate_points怎么用?Python KarmaManager.recalculate_points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karma.manager.KarmaManager的用法示例。


在下文中一共展示了KarmaManager.recalculate_points方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _process_recalculate_chunk

# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import recalculate_points [as 别名]
def _process_recalculate_chunk(data, **kwargs):
    """Recalculate karma points for a chunk of user ids."""
    mgr = KarmaManager()
    actions = [AnswerAction, AnswerMarkedHelpfulAction, AnswerMarkedNotHelpfulAction, FirstAnswerAction, SolutionAction]
    actions_dict = dict((a.action_type, a.points) for a in actions)

    for userid in data:
        mgr.recalculate_points(userid, actions_dict)
开发者ID:codeadict,项目名称:kitsune,代码行数:10,代码来源:tasks.py

示例2: KarmaManagerTests

# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import recalculate_points [as 别名]
class KarmaManagerTests(TestCase):
    def setUp(self):
        super(KarmaManagerTests, self).setUp()
        self.user = user(save=True)
        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

    @mock.patch.object(waffle, 'switch_is_active')
    def test_recalculate_points(self, switch_is_active):
        """Test the recalculate_points method."""
        switch_is_active.return_value = True
        TestAction1(user=self.user).save()  # 3pts
        TestAction1(user=self.user).save()  # 3pts
        TestAction2(user=self.user).save()  # 7pts
        eq_(13, self.mgr.total_points(self.user))
        new_pts = {
            'test-action-1': 15,
            'test-action-2': 12
        }
        self.mgr.recalculate_points(self.user, new_pts)
        eq_(42, self.mgr.total_points(self.user))
开发者ID:codeadict,项目名称:kitsune,代码行数:26,代码来源:test_manager.py

示例3: KarmaManagerTests

# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import recalculate_points [as 别名]
class KarmaManagerTests(TestCase):
    @mock.patch.object(waffle, 'switch_is_active')
    def setUp(self, switch_is_active):
        switch_is_active.return_value = True

        super(KarmaManagerTests, self).setUp()

        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

        self.user1 = user(save=True)
        self.user2 = user(save=True)
        self.user3 = user(save=True)

        today = date.today()

        # user1 actions (3 + 3 + 7):
        TestAction1(user=self.user1, day=today).save()
        TestAction1(user=self.user1, day=today).save()
        TestAction2(user=self.user1, day=today).save()

        # user2 actions (3 + 7 + 7):
        TestAction1(user=self.user2, day=today - timedelta(days=8)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=32)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=360)).save()

        # user3 actions (3 + 3 + 3 + 7):
        TestAction1(user=self.user3, day=today - timedelta(days=10)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=40)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=190)).save()
        TestAction2(user=self.user3, day=today - timedelta(days=3)).save()

    @mock.patch.object(waffle, 'switch_is_active')
    def test_count(self, switch_is_active):
        """Test count method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        eq_(13, self.mgr.count(self.user1, type='points'))
        eq_(2, self.mgr.count(self.user1, type=TestAction1.action_type))
        eq_(1, self.mgr.count(self.user1, type=TestAction2.action_type))
        eq_(0, self.mgr.count(self.user2, type='points', daterange='1w'))
        eq_(3, self.mgr.count(self.user2, type='points', daterange='1m'))
        eq_(2, self.mgr.count(self.user2, type=TestAction2.action_type,
                              daterange='1y'))
        eq_(2, self.mgr.count(self.user3, type=TestAction1.action_type,
                              daterange='6m'))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_top_users(self, switch_is_active):
        """Test top_users method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        u1, u2, u3 = self.user1, self.user2, self.user3
        eq_([u2, u3, u1], self.mgr.top_users())
        eq_([u3, u1, u2], self.mgr.top_users(type=TestAction1.action_type))
        eq_([u3, u1, u2], self.mgr.top_users(type=TestAction1.action_type))
        eq_([u1], self.mgr.top_users(type=TestAction1.action_type,
                                     daterange='1w'))
        eq_([u1, u3], self.mgr.top_users(daterange='1w'))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_ranking(self, switch_is_active):
        """Test ranking method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        eq_(1, self.mgr.ranking(self.user2))
        eq_(3, self.mgr.ranking(self.user1))
        eq_(1, self.mgr.ranking(self.user1, daterange='1w'))
        eq_(1, self.mgr.ranking(self.user3, type=TestAction1.action_type))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_recalculate_points(self, switch_is_active):
        """Test the recalculate_points method."""
        switch_is_active.return_value = True

        # Create Points with new point values.
        p1 = Points.objects.create(action='test-action-1', points=15)
        Points.objects.create(action='test-action-2', points=12)

        self.mgr.recalculate_points(self.user1)
        eq_(42, self.mgr.count(self.user1, type='points'))

        # Update one of the Point values.
        p1.points = 30
        p1.save()

        self.mgr.recalculate_points(self.user1)
        eq_(72, self.mgr.count(self.user1, type='points'))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_overview_counts(self, switch_is_active):
        """Verify the overview counts are correct."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        eq_(46, self.mgr.count(type='points'))
        eq_(6, self.mgr.count(type=TestAction1.action_type))
        eq_(4, self.mgr.count(type=TestAction2.action_type))
#.........这里部分代码省略.........
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:103,代码来源:test_manager.py

示例4: _process_recalculate_chunk

# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import recalculate_points [as 别名]
def _process_recalculate_chunk(data):
    """Recalculate karma points for a chunk of user ids."""
    mgr = KarmaManager()
    for userid in data:
        mgr.recalculate_points(userid)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:7,代码来源:tasks.py

示例5: KarmaManagerTests

# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import recalculate_points [as 别名]
class KarmaManagerTests(TestCase):
    @mock.patch.object(waffle, 'switch_is_active')
    def setUp(self, switch_is_active):
        switch_is_active.return_value = True

        super(KarmaManagerTests, self).setUp()

        try:
            self.mgr = KarmaManager()
            redis_client('karma').flushdb()
        except RedisError:
            raise SkipTest

        self.user1 = user(save=True)
        self.user2 = user(save=True)
        self.user3 = user(save=True)

        today = date.today()

        # user1 actions (3 + 3 + 7):
        TestAction1(user=self.user1, day=today).save()
        TestAction1(user=self.user1, day=today).save()
        TestAction2(user=self.user1, day=today).save()

        # user2 actions (3 + 7 + 7):
        TestAction1(user=self.user2, day=today - timedelta(days=8)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=32)).save()
        TestAction2(user=self.user2, day=today - timedelta(days=360)).save()

        # user3 actions (3 + 3 + 3 + 7):
        TestAction1(user=self.user3, day=today - timedelta(days=10)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=40)).save()
        TestAction1(user=self.user3, day=today - timedelta(days=190)).save()
        TestAction2(user=self.user3, day=today - timedelta(days=3)).save()

    @mock.patch.object(waffle, 'switch_is_active')
    def test_count(self, switch_is_active):
        """Test count method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        eq_(13, self.mgr.count(self.user1, type='points'))
        eq_(2, self.mgr.count(self.user1, type=TestAction1.action_type))
        eq_(1, self.mgr.count(self.user1, type=TestAction2.action_type))
        eq_(0, self.mgr.count(self.user2, type='points', daterange='1w'))
        eq_(3, self.mgr.count(self.user2, type='points', daterange='1m'))
        eq_(2, self.mgr.count(self.user2, type=TestAction2.action_type,
                              daterange='1y'))
        eq_(2, self.mgr.count(self.user3, type=TestAction1.action_type,
                              daterange='6m'))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_top_users(self, switch_is_active):
        """Test top_users method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        u1, u2, u3 = self.user1, self.user2, self.user3
        eq_([u2, u3, u1], self.mgr.top_users())
        eq_([u3, u1, u2], self.mgr.top_users(type=TestAction1.action_type))
        eq_([u3, u1, u2], self.mgr.top_users(type=TestAction1.action_type))
        eq_([u1], self.mgr.top_users(type=TestAction1.action_type,
                                     daterange='1w'))
        eq_([u1, u3], self.mgr.top_users(daterange='1w'))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_ranking(self, switch_is_active):
        """Test ranking method."""
        switch_is_active.return_value = True
        self.mgr.update_top()
        eq_(1, self.mgr.ranking(self.user2))
        eq_(3, self.mgr.ranking(self.user1))
        eq_(1, self.mgr.ranking(self.user1, daterange='1w'))
        eq_(1, self.mgr.ranking(self.user3, type=TestAction1.action_type))

    @mock.patch.object(waffle, 'switch_is_active')
    def test_recalculate_points(self, switch_is_active):
        """Test the recalculate_points method."""
        switch_is_active.return_value = True
        KarmaManager.action_types = {
            'test-action-1': 15,
            'test-action-2': 12
        }
        self.mgr.recalculate_points(self.user1)
        eq_(42, self.mgr.count(self.user1, type='points'))
开发者ID:muratmeran,项目名称:kitsune,代码行数:85,代码来源:test_manager.py


注:本文中的karma.manager.KarmaManager.recalculate_points方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。