本文整理匯總了Python中whale.Whale.cached_plotpoints方法的典型用法代碼示例。如果您正苦於以下問題:Python Whale.cached_plotpoints方法的具體用法?Python Whale.cached_plotpoints怎麽用?Python Whale.cached_plotpoints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whale.Whale
的用法示例。
在下文中一共展示了Whale.cached_plotpoints方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestHailWhale
# 需要導入模塊: from whale import Whale [as 別名]
# 或者: from whale.Whale import cached_plotpoints [as 別名]
#.........這裏部分代碼省略.........
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))
self.whale.count_now([pk, decision, 'd'], None, dict(dollars=5, visitors=1))
# Here's a visitor with no info -- 'A' should win by far.
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())
# How about when we know the country is "UK"?
good, bad, test = self.whale.weighted_reasons(pk, decision, opts, formula='dollars/visitors',
known_data={'country': 'uk'})
#_print_reasons(good, bad, test)
self.assertEqual(True, 'a' in good.keys())
self.assertEqual(True, 'b' in good.keys())
self.assertEqual(True, 'c' in bad.keys())
self.assertEqual(True, 'd' in test.keys())
chosen = {'a': 0, 'b': 0}
for k in range(100):
choose = self.whale.decide(pk, decision, opts, formula='dollars/visitors',
known_data={'country': 'uk'}, bad_idea_threshold=0, test_idea_threshold=0)
chosen[choose] += 1
self.assertEqual(True, chosen['b'] > 70,
"""A decision made 100 times between weights .15 vs .85 should have around 85 votes for 'b',
we got %s, which is unlikely enough to fail a test, but not definitely
indicative of a problem. If this test passes again on the next run, ignore the failure.""" % chosen)
def testTrickyDecision(self):
pk = 'test_tricky_decision'
decision = str(time.time())
opts = ['en', 'sp', 'pt']
def count(geo, lang, dollars, visitors):
self.whale.count_decided_now(pk, decision, lang, geo,
{'dollars': dollars, 'visitors': visitors})
def justify(geo):
#print
#print 'Picking reasons for ', geo
good, bad, test = self.whale.weighted_reasons(pk, decision, opts,
'dollars/visitors', geo)
#print good.keys(), bad.keys(), test.keys()
#_print_reasons(good, bad, test)
return self.whale.decide(pk, decision, opts, 'dollars/visitors', geo,
bad_idea_threshold=0, test_idea_threshold=0)
k = 1000
m = k * k
# Sure, these results seem predictable to a human
# But what will our philosopher whale friend make of it?
count('us', 'en', 1.5 * m, 300 * k) # $5/visitor, alright!
count('us', 'sp', 1 * k, 10 * k) # $.10/visitor, well that is not surprising
count('us', 'pt', 300, 5 * k) # $.06/visitor, :(
count('mx', 'en', 100 * k, 100 * k) # $1/visitor, this almost works
count('mx', 'sp', 200 * k, 100 * k) # $2/visitor aww yah!
count('mx', 'pt', 200, 10 * k) # $.02/visitor lol
count('br', 'en', 300 * k, 100 * k) # $3/visitor is good
count('br', 'sp', 150 * k, 50 * k) # $3/visitor as well
count('br', 'pt', 500 * k, 50 * k) # $10 JACKPOT
self.assertEqual('en', justify('us'))
self.assertEqual(True, justify('mx') in ['sp', 'en'])
self.assertEqual('pt', justify('br'))
def testWhaleCacheWrapper(self):
t = str(time.time())
count = lambda: self.whale.count_now('test_cached', t)
cached_sum = lambda clear=False: sum(self.whale.cached_plotpoints('test_cached',
t, period='fivemin', unmemoize=clear)[t]['hits'].values())
# Set hits to 1
count()
self.assertEqual(cached_sum(), 1)
# Should stay 1 for a while
for i in range(3):
count()
self.assertEqual(cached_sum(), 1)
self.assertEqual(cached_sum(clear=True), 4)