本文整理匯總了Python中whale.Whale類的典型用法代碼示例。如果您正苦於以下問題:Python Whale類的具體用法?Python Whale怎麽用?Python Whale使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Whale類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: dump_now
def dump_now(cls):
""" Flush hits to Whale and increment """
# Get the incoming hits from Hail
r=cls.hail_driver()
set_number_name = 'hail_number'
r.setnx(set_number_name, 0)
set_number = r.incr(set_number_name) - 1
set_name = 'hail_%s' % set_number
try: keys_from_hail = r.smembers(set_name)
except: return
if not len(keys_from_hail):
r.delete(set_name)
return
def get_keys_from_json(k):
try:
class_name, pk, dimensions, metrics, at = json.loads(r[k])
#at = datetime.datetime.fromtimestamp(float(t))
return (pk, dimensions, metrics, at)
except Exception as e:
print e
return False
keys_to_update = map(get_keys_from_json, keys_from_hail)
for packed in keys_to_update:
if packed:
pk, dimensions, metrics, at = packed
Whale.count_now(pk, dimensions, metrics, at=at)
# Delete the hits
map(r.delete, keys_from_hail)
r.delete(set_name)
示例2: reset
def reset():
whale = Whale()
try:
whale.reset(**default_params())
except Exception as e:
return str(e)
return 'OK'
示例3: totals
def totals():
whale = Whale()
params = default_params()
params['periods'] = g('periods', None)
if type(params['metrics']) == dict:
params['metrics'] = params['metrics'].keys()
return whale.totals(**params)
示例4: dump_now
def dump_now(cls):
""" Flush hits to Whale and increment """
# Get the incoming hits from Hail
from whale import Whale
whale = Whale()
r=cls.driver()
_s_n_n = 'hail_number'
r.setnx(_s_n_n, 0)
set_number = r.incr(_s_n_n) - 1
set_name = 'hail_%s'%set_number
try: keys_from_hail = r.smembers(set_name)
except: return
if len(keys_from_hail) is 0:
r.delete(set_name)
return
def get_keys_from_json(k):
try:
class_name, categories, dimensions, metrics, t = json.loads(r[k])
at = datetime.datetime.fromtimestamp(float(t))
return (categories, dimensions, metrics, at)
except Exception as e:
print e
return False
keys_to_update = map(get_keys_from_json, keys_from_hail)
for packed in keys_to_update:
if not packed: continue
categories, dimensions, metrics, at = packed
whale.count_now(categories, dimensions, metrics, at=at)
# Delete the hits
map(r.delete, keys_to_update)
r.delete(set_name)
示例5: plotpoints
def plotpoints():
whale = Whale()
params = default_params()
params['depth'] = g('depth', 0)
params['period'] = g('period', None)
params['flot_time'] = True
return whale.plotpoints(**params)
'''
示例6: plotpoints
def plotpoints():
whale = Whale()
params = default_params()
params['depth'] = g('depth', 0)
params['period'] = g('period', None)
params['sort'] = g('sort', None)
params['limit'] = g('limit', 10)
params['tzoffset'] = g('tzoffset', 0.0)
params['flot_time'] = True
return whale.plotpoints(**params)
示例7: count_now
def count_now():
whale = Whale()
vals = default_params()
at = vals.get("at")#g('at', False)
tzoffset = None
if not at:
at = times.now()
else:
from dateutil.parser import parse
at = parse(at)
val = whale.count_now(at= at, pk=vals.get("pk"), metrics=vals.get("metrics"), dimensions=vals.get("dimensions"))
return 'OK'
示例8: plotpointsGraph
def plotpointsGraph():
whale = Whale()
params = default_params()
params['depth'] = g('depth', 0)
params['period'] = g('period', None)
params['sort'] = g('sort', None)
params['limit'] = g('limit', 10)
params['tzoffset'] = g('tzoffset', 0.0)
params['flot_time'] = True
#print whale.plotpointsGraph(**params)
ret = whale.plotpointsGraph(**params)
return json.dumps(ret)
示例9: count_now
def count_now():
whale = Whale()
at = g('at', False)
tzoffset = None
if not at:
at = times.now()
else:
from dateutil.parser import parse
at = parse(g('at'))
at = at.replace(tzinfo=None)
val = whale.count_now(at=at, **default_params())
return 'OK'
示例10: __init__
def __init__(self, whale=None, enemies=None):
super().__init__()
self.background = 210, 210, 210
heart_path = os.path.join(os.path.realpath(''), 'Images', 'heart.gif')
self.heart = pygame.image.load(heart_path).convert()
halfheart_path = os.path.join(os.path.realpath(''), 'Images', 'halfheart.gif')
self.halfheart = pygame.image.load(halfheart_path).convert()
self.healthbar = pygame.sprite.Group()
if whale == None:
self.whale = Whale()
else:
self.whale = whale
if enemies == None:
enemies = [Octopus()]
self.set_enemies(enemies)
self.whale_is_dead = False
self.player_projectiles = pygame.sprite.Group()
self.enemy_projectiles = pygame.sprite.Group()
self.sprites = pygame.sprite.Group(self.whale, self.enemy_sprites,
self.player_projectiles, self.enemy_projectiles, self.healthbar)
self.update_healthbar()
self.next_state = "LevelOne"
示例11: update_count_to
def update_count_to():
whale = Whale()
at = g('at', False)
tzoffset = None
if not at:
at = times.now()
else:
from dateutil.parser import parse
at = parse(g('at'))
at = at.replace(tzinfo=None)
params = dict(at=at,
period=g('period', None),
**default_params())
val = whale.update_count_to(**params)
return 'OK'
示例12: tracker
def tracker():
from periods import Period
import random
params = default_params()
# LOLOL THIS SHOULD REALLY CHANGE
key = hashlib.sha256('hailwhale_weak_key').digest()
if 'pk' not in req.GET and 'pixel' in req.GET:
from Crypto.Cipher import AES
from base64 import b64encode, b64decode
from urllib import quote_plus
mode = AES.MODE_CBC
encryptor = AES.new(key, mode)
text = g('pixel')
INTERRUPT = u'\u0001'
PAD = u'\u0000'
# Since you need to pad your data before encryption,
# create a padding function as well
# Similarly, create a function to strip off the padding after decryption
def AddPadding(data, interrupt, pad, block_size):
new_data = ''.join([data, interrupt])
new_data_len = len(new_data)
remaining_len = block_size - new_data_len
to_pad_len = remaining_len % block_size
pad_string = pad * to_pad_len
return ''.join([new_data, pad_string])
def StripPadding(data, interrupt, pad):
return data.rstrip(pad).rstrip(interrupt)
def hw_encoded(t):
return quote_plus(b64encode(encryptor.encrypt(AddPadding(t, INTERRUPT, PAD, 32))))
def hw_decoded(t):
return StripPadding(encryptor.decrypt(b64decode(t)), INTERRUPT, PAD)
params['pk'] = hw_decoded(text)
pk = params['pk']
whale = Whale()
hail = Hail()
val = whale.count_now(at=times.now(), **params)
#val = whale.count_now(**params)
uid = g('uid')
if not uid or uid == '_new':
default = random.randrange(10**6,10**9)
uid = str(req.get_cookie('uid', str(default), key))
hail.spy_log(uid, params)
response.set_cookie('uid', uid, key)
return str(uid)
示例13: graph
def graph():
whale = Whale()
points = whale.plotpoints(**default_params())
params = {'script_tag': util.JS_TAG,
'flotpoints': json.dumps(points),
'random_name': 'graph_psuedorandom',
}
return """
<div id="%(random_name)s" style="width:97%%;height:97%%;"> </div>
%(script_tag)s
<script type="text/javascript">
dimensions = %(flotpoints)s;
first_dimension = get_keys(dimensions)[0];
first_metric = get_keys(dimensions[first_dimension])[0];
//data = dimensions['[\"empty\"]']['hits'];
data = dimensions[first_dimension][first_metric];
$.plot($("#%(random_name)s"), [
{data: data, lines: {show: true}},
], { xaxis: { mode: "time" } });
</script>"""%params
示例14: count_now
def count_now():
from datetime import datetime
whale = Whale()
val = whale.count_now(at=datetime.utcnow(), **default_params())
return 'OK'
示例15: plotpoints
def plotpoints():
whale = Whale()
params = default_params()
params["depth"] = g("depth", 0)
params["period"] = g("period", None)
return json.dumps(whale.plotpoints(**params))