Added support of previous date in getLastContributors

pull/3/head
Sami Mokaddem 2017-11-10 09:28:59 +01:00
parent cb53be4253
commit d8ad176b72
2 changed files with 24 additions and 11 deletions

View File

@ -229,21 +229,24 @@ class Contributor_helper:
def getLastContributorsFromRedis(self):
date = datetime.datetime.now()
keyname = "CONTRIB_LAST"
prev_days = 7
topNum = self.MAX_NUMBER_OF_LAST_CONTRIBUTOR # default Num
last_contrib_org = self.getZrange(keyname, date, topNum)
data = []
for org, sec in last_contrib_org:
dic = {}
dic['rank'] = self.getOrgRankFromRedis(org, date)
dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org
dic['pnts'] = self.getOrgPntFromRedis(org, date)
dic['epoch'] = sec
data.append(dic)
for curDate in util.getXPrevDaysSpan(date, prev_days):
last_contrib_org = self.getZrange(keyname, curDate, topNum)
for org, sec in last_contrib_org:
dic = {}
dic['rank'] = self.getOrgRankFromRedis(org, date)
dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org
dic['pnts'] = self.getOrgPntFromRedis(org, date)
dic['epoch'] = sec
data.append(dic)
return data
def getContributorFromRedis(self, org):
date = datetime.datetime.now()
epoch = self.serv_redis_db.zscore("CONTRIB_LAST", org)

10
util.py
View File

@ -14,5 +14,15 @@ def getMonthSpan(date):
to_return.append(ds + datetime.timedelta(days=i))
return to_return
def getXPrevDaysSpan(date, days):
de = date
ds = de - datetime.timedelta(days=days)
delta = de - ds
to_return = []
for i in range(delta.days+1):
to_return.append(de - datetime.timedelta(days=i))
return to_return
def getDateStrFormat(date):
return str(date.year)+str(date.month).zfill(2)+str(date.day).zfill(2)