diff --git a/contributor_helper.py b/contributor_helper.py index 474309b..51f2f95 100644 --- a/contributor_helper.py +++ b/contributor_helper.py @@ -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) diff --git a/util.py b/util.py index 27969ee..ba794f1 100644 --- a/util.py +++ b/util.py @@ -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)