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


Python Whale.decide_from_reasons方法代码示例

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


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

示例1: TestHailWhale

# 需要导入模块: from whale import Whale [as 别名]
# 或者: from whale.Whale import decide_from_reasons [as 别名]

#.........这里部分代码省略.........
    def testRankSubdimensionsRatio(self):
        t = str(time.time())
        pk = 'test_ratio_rank'
        # OVERALL STATS: 529,994 value, 50,000 visitors, 10.6 value per visitor
        # Not important, too close to overall
        self.whale.count_now(pk, [t, 'a', 'asub1'],
            {'value': 54989, 'visitors': 4999})  # 11 value per visitor
        # Important, high relative ratio
        self.whale.count_now(pk, [t, 'a', 'asub2'],
            {'value': 375000, 'visitors': 25000})  # 15 value per visitor
        # Important, low relative ratio
        self.whale.count_now(pk, [t, 'b'],
            {'value': 100000, 'visitors': 20000})  # 5 value per visitor
        # Not important, not enough visitors
        self.whale.count_now(pk, [t, 'c'],
            {'value': 5, 'visitors': 1})  # 5 value per visitor

        one_level = self.whale.rank_subdimensions_ratio('test_rank_ratio', 'value', 'visitors',
            t, recursive=False)

        all_levels = self.whale.rank_subdimensions_ratio(pk, 'value', 'visitors', t)
        self.assertEqual(True, maybe_dumps([t, 'a', 'asub1']) not in one_level)
        self.assertEqual(all_levels[maybe_dumps([t, 'a', 'asub1'])]['important'], False)
        self.assertEqual(all_levels[maybe_dumps([t, 'a', 'asub2'])]['important'], True)
        self.assertEqual(all_levels[maybe_dumps([t, 'b'])]['important'], True)
        self.assertEqual(all_levels[maybe_dumps([t, 'c'])]['important'], False)

    def testBasicDecision(self):
        pk = 'test_basic_decision'
        decision = str(time.time())
        # Make a decision, any decision, from no information whatsoever
        good, bad, test = self.whale.weighted_reasons(pk, 'random', [1,2,3])
        #_print_reasons(good, bad, test)
        any_one = self.whale.decide_from_reasons(good, bad, test)
        self.assertEqual(True, any_one in [1, 2, 3])

        # OK, now how about something somewhat informed?
        # This will be easy. Slogan A makes us huge profit. Products B and C suck.
        # D looks promissing but isn't yet significant
        opts = ['a', 'b', 'c', 'd']
        self.whale.count_now([pk, decision, 'a'], None, dict(dollars=5000, visitors=1000))
        self.whale.count_now([pk, decision, 'b'], None, dict(dollars=0, visitors=2000))
        self.whale.count_now([pk, decision, 'c'], None, dict(dollars=0, visitors=2000))
        self.whale.count_now([pk, decision, 'd'], None, dict(dollars=50, visitors=10))

        good, bad, test = self.whale.weighted_reasons(pk, decision, opts, formula='dollars/visitors')
        #_print_reasons(good, bad, test)

        self.assertEqual(True, 'a' in good.keys())
        self.assertEqual(True, 'b' in  bad.keys())
        self.assertEqual(True, 'c' in bad.keys())
        self.assertEqual(True, 'd' in test.keys())
        which_one = self.whale.decide(pk, decision, opts, formula='dollars/visitors',
            bad_idea_threshold=0, test_idea_threshold=0)
        self.assertEqual(which_one, 'a')

    def testInformedDecision(self):
        pk = 'test_informed_decision'
        decision = str(time.time())

        # A is the clear winner, except when country=UK, in which case B wins
        opts = ['a', 'b', 'c', 'd']
        self.whale.count_now([pk, decision, 'a'], None, dict(dollars=50000, visitors=10000))
        self.whale.count_now([pk, decision, 'b'], None, dict(dollars=0, visitors=2000))
        self.whale.count_now([pk, decision, 'b'], {'country': 'uk'}, dict(dollars=10000, visitors=2000))
        self.whale.count_now([pk, decision, 'c'], None, dict(dollars=0, visitors=7500))
开发者ID:johann8384,项目名称:hailwhale,代码行数:70,代码来源:test.py


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