diff --git a/config/ranking.cfg b/config/ranking.cfg index 32788aa..b0119fb 100644 --- a/config/ranking.cfg +++ b/config/ranking.cfg @@ -35,6 +35,11 @@ maxLevel=16 15=32768 16=65536 +[rankRequirementsMisc] +heavilyCount=10 +recentDays=31 +regularlyDays=7 + [rankRequirementsText] 1=Contributing via sighting at least once a year 2=Contributing via attributes or objects to events at least once a year diff --git a/contributor_helper.py b/contributor_helper.py index 6252302..ee1cad4 100644 --- a/contributor_helper.py +++ b/contributor_helper.py @@ -13,8 +13,13 @@ class Contributor_helper: self.cfg_org_rank.read(os.path.join(os.environ['DASH_CONFIG'], 'ranking.cfg')) #honorBadge + self.honorBadgeNum = len(self.cfg_org_rank.options('HonorBadge')) + self.heavilyCount = self.cfg_org_rank.getint('rankRequirementsMisc', 'heavilyCount') + self.recentDays = self.cfg_org_rank.getint('rankRequirementsMisc', 'recentDays') + self.regularlyDays = self.cfg_org_rank.getint('rankRequirementsMisc', 'regularlyDays') + self.org_honor_badge_title = {} - for badgeNum in range(1, len(self.cfg_org_rank.options('HonorBadge'))+1): #get Num of honorBadge + for badgeNum in range(1, self.honorBadgeNum+1): #get Num of honorBadge self.org_honor_badge_title[badgeNum] = self.cfg_org_rank.get('HonorBadge', str(badgeNum)) #GLOBAL RANKING @@ -51,6 +56,11 @@ class Contributor_helper: self.rankMultiplier = cfg.getfloat('CONTRIB' ,'rankMultiplier') self.levelMax = 16 + + ''' HELPER ''' + def getOrgLogoFromRedis(self, org): + return "{}/img/orgs/{}.png".format(self.misp_web_url, org) + def getZrange(self, keyCateg, date, topNum, endSubkey=""): date_str = util.getDateStrFormat(date) keyname = "{}:{}{}".format(keyCateg, date_str, endSubkey) @@ -58,6 +68,64 @@ class Contributor_helper: data = [ [record[0].decode('utf8'), record[1]] for record in data ] return data + ''' CONTRIBUTION RANK ''' + # return: [final_rank, requirement_fulfilled, requirement_not_fulfilled] + def getOrgContributionRank(self, org): + keyname = 'CONTRIB_ORG:{org}:{orgCateg}' + final_rank = 0 + requirement_fulfilled = [] + requirement_not_fulfilled = [] + for i in range(1, self.org_rank_maxLevel+1): + key = keyname.format(org=org, orgCateg='CONTRIB_REQ_'+str(i)) + if self.serv_redis_db.get(key) is None: #non existing + requirement_not_fulfilled.append(i) + else: + requirement_fulfilled.append(i) + final_rank += 1 + num_of_previous_req_not_fulfilled = len([x for x in requirement_not_fulfilled if xContribution requirement - + {% for item in org_rank_list %} - + {{ item[1] }} {{ item[2] }} @@ -121,7 +121,7 @@ {% for item in org_honor_badge_title_list %} -
+
@@ -171,6 +171,7 @@