Same for util function (move into section)

pull/3/head
Sami Mokaddem 2017-11-03 09:38:11 +01:00
parent 2ca318b68e
commit ac90101fc2
1 changed files with 17 additions and 6 deletions

View File

@ -36,6 +36,11 @@ subscriber_map = redis_server_map.pubsub(ignore_subscribe_messages=True)
subscriber_map.psubscribe(cfg.get('RedisMap', 'channelDisp')) subscriber_map.psubscribe(cfg.get('RedisMap', 'channelDisp'))
eventNumber = 0 eventNumber = 0
##########
## UTIL ##
##########
''' INDEX '''
class LogItem(): class LogItem():
FIELDNAME_ORDER = [] FIELDNAME_ORDER = []
@ -93,12 +98,7 @@ class EventMessage():
to_ret = { 'log': self.feed, 'feedName': self.feedName, 'zmqName': self.zmqName } to_ret = { 'log': self.feed, 'feedName': self.feedName, 'zmqName': self.zmqName }
return 'data: {}\n\n'.format(json.dumps(to_ret)) return 'data: {}\n\n'.format(json.dumps(to_ret))
def getZrange(keyCateg, date, topNum): ''' CONTRIB '''
date_str = str(date.year)+str(date.month)+str(date.day)
keyname = "{}:{}".format(keyCateg, date_str)
data = serv_redis_db.zrange(keyname, 0, 5, desc=True, withscores=True)
data = [ [record[0].decode('utf8'), record[1]] for record in data ]
return data
# max lvl is 16 # max lvl is 16
def getRankLevel(points): def getRankLevel(points):
@ -106,6 +106,7 @@ def getRankLevel(points):
return 0 return 0
else: else:
return float("{:.2f}".format(math.log(points, cfg.getfloat('CONTRIB' ,'rankMultiplier')))) return float("{:.2f}".format(math.log(points, cfg.getfloat('CONTRIB' ,'rankMultiplier'))))
def getRemainingPoints(points): def getRemainingPoints(points):
prev = 0 prev = 0
for i in [math.floor(cfg.getfloat('CONTRIB' ,'rankMultiplier')**x) for x in range(1,17)]: for i in [math.floor(cfg.getfloat('CONTRIB' ,'rankMultiplier')**x) for x in range(1,17)]:
@ -114,6 +115,16 @@ def getRemainingPoints(points):
prev = i prev = i
return { 'remainingPts': 0, 'stepPts': cfg.getfloat('CONTRIB' ,'rankMultiplier')**16 } return { 'remainingPts': 0, 'stepPts': cfg.getfloat('CONTRIB' ,'rankMultiplier')**16 }
''' GENERAL '''
def getZrange(keyCateg, date, topNum):
date_str = str(date.year)+str(date.month).zfill(2)+str(date.day).zfill(2)
keyname = "{}:{}".format(keyCateg, date_str)
data = serv_redis_db.zrange(keyname, 0, 5, desc=True, withscores=True)
data = [ [record[0].decode('utf8'), record[1]] for record in data ]
return data
########### ###########
## ROUTE ## ## ROUTE ##
########### ###########