From 0bc06839244b609d94f88103198ff8c39e0ed842 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 13 Nov 2017 12:57:05 +0100 Subject: [PATCH] Started support of organisation trophies --- config/ranking.cfg | 19 ++++++++++ contributor_helper.py | 26 +++++++++++++ server.py | 18 ++++++++- static/css/ranking.css | 24 +++++++++++- static/js/contrib.js | 21 +++++++++++ templates/contrib.html | 83 ++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 185 insertions(+), 6 deletions(-) diff --git a/config/ranking.cfg b/config/ranking.cfg index 8adeb93..8bef4c7 100644 --- a/config/ranking.cfg +++ b/config/ranking.cfg @@ -65,6 +65,25 @@ regularlyDays=7 [HonorBadge] 1=Has made at least one pull request on the MISP project 2=Is a donator for the MISP project +3=Has published content upvoted by the community +4=Has published valuable content for the community +5=Has published loads of valuable content for the community + +[HonorTrophy] +0=No trophy +1=Novice +2=Beginner +3=Intermediate +4=Competent +5=Experienced +6=Talented +7=Skilled +8=Advanced +9=Expert +10=Master + +[HonorTrophyCateg] +categ=["internal_reference", "targeting_data", "antivirus_detection", "payload_delivery", "artifacts_dropped", "payload_installation", "persistence_mechanism", "network_activity", "payload_type", "attribution", "external_analysis", "financial_fraud", "support_Tool", "social_network", "person", "other" ] [additionalInfo] textsArray=["Proposals means either edition, acceptation or rejection", "Recent events means event aged of one month at max", "Regularly means at least one per week" ,"Heavily means at least 10 per week", "Classification means correct tagging", "The contribution rank is set such that it equals to: rank=requirement_fulfilled-requirement_not_fulfilled"] diff --git a/contributor_helper.py b/contributor_helper.py index c8009dc..c06e074 100644 --- a/contributor_helper.py +++ b/contributor_helper.py @@ -22,6 +22,12 @@ class Contributor_helper: 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)) + self.trophyNum = len(self.cfg_org_rank.options('HonorTrophyCateg')) + self.categories_in_trophy = json.loads(self.cfg_org_rank.get('HonorTrophyCateg', 'categ')) + self.trophy_title = {} + for trophyNum in range(0, len(self.cfg_org_rank.options('HonorTrophy'))): #get Num of trophy + self.trophy_title[trophyNum] = self.cfg_org_rank.get('HonorTrophy', str(trophyNum)) + #GLOBAL RANKING self.org_rank_maxLevel = self.cfg_org_rank.getint('rankTitle', 'maxLevel') self.org_rank = {} @@ -218,6 +224,17 @@ class Contributor_helper: keyname = 'CONTRIB_ORG:{org}:{orgCateg}' self.serv_redis_db.delete(keyname.format(org=org, orgCateg='BADGE_'+str(badgeNum))) + ''' TROPHIES ''' + def getOrgTrophies(self, org): + keyname = 'CONTRIB_ORG:{org}:{orgCateg}' + trophy = [] + for i in range(1, self.trophyNum+1): + key = keyname.format(org=org, orgCateg='TROPHY_'+str(i)) + trophy_Pnts = self.serv_redis_db.get(key) + if trophy_Pnts is not None: #existing + trophy.append(trophy_Pnts) + return trophy + ''' MONTHLY CONTRIBUTION ''' def getOrgPntFromRedis(self, org, date): keyCateg = 'CONTRIB_DAY' @@ -583,3 +600,12 @@ class Contributor_helper: else: honorBadge.append(0) return honorBadge + + def TEST_getOrgTrophies(self, org): + keyname = 'CONTRIB_ORG:{org}:{orgCateg}' + trophy = [] + for categ in self.categories_in_trophy: + key = keyname.format(org=org, orgCateg='TROPHY_'+categ) + trophy_Pnts = random.randint(0,10) + trophy.append({'categName': categ, 'rank': trophy_Pnts}) + return trophy diff --git a/server.py b/server.py index aede14a..2301ccc 100755 --- a/server.py +++ b/server.py @@ -149,7 +149,7 @@ def geo(): @app.route("/contrib") def contrib(): categ_list = contributor_helper.categories_in_datatable - categ_list_str = [ s[0].upper() + s[1:].replace('_', ' ') for s in contributor_helper.categories_in_datatable] + categ_list_str = [ s[0].upper() + s[1:].replace('_', ' ') for s in categ_list] categ_list_points = [contributor_helper.DICO_PNTS_REWARD[categ] for categ in categ_list] org_rank = contributor_helper.org_rank @@ -163,6 +163,10 @@ def contrib(): org_honor_badge_title_list = [ [num, text] for num, text in contributor_helper.org_honor_badge_title.items()] org_honor_badge_title_list.sort(key=lambda x: x[0]) + trophy_categ_list = contributor_helper.categories_in_trophy + trophy_categ_list_str = [ s[0].upper() + s[1:].replace('_', ' ') for s in trophy_categ_list] + trophy_title = contributor_helper.trophy_title + currOrg = request.args.get('org') if currOrg is None: currOrg = "" @@ -179,6 +183,10 @@ def contrib(): org_rank_additional_text=org_rank_additional_text, org_honor_badge_title=json.dumps(org_honor_badge_title), org_honor_badge_title_list=org_honor_badge_title_list, + trophy_categ_list=json.dumps(trophy_categ_list), + trophy_categ_list_id=trophy_categ_list, + trophy_categ_list_str=trophy_categ_list_str, + trophy_title=json.dumps(trophy_title), min_between_reload=cfg.getint('CONTRIB', 'min_between_reload') ) @@ -376,5 +384,13 @@ def getHonorBadges(): org = '' return jsonify(contributor_helper.getOrgHonorBadges(org)) +@app.route("/_getTrophies") +def getTrophies(): + try: + org = request.args.get('org') + except: + org = '' + return jsonify(contributor_helper.TEST_getOrgTrophies(org)) + if __name__ == '__main__': app.run(host='localhost', port=8001, threaded=True) diff --git a/static/css/ranking.css b/static/css/ranking.css index c5c4149..b9a5e63 100644 --- a/static/css/ranking.css +++ b/static/css/ranking.css @@ -3,6 +3,12 @@ height: auto; } +tr > td > label > input.radioTrophy { + margin: auto; + margin-bottom: 5px; + display: block; +} + .successCell { background-color: #dff0d8 !important } @@ -16,8 +22,24 @@ border: 1px solid #caccce; } +.circleBadgeSmall { + width: 40px; + height: 40px; + text-align: center; + border-radius: 25px; + background-color: #e1e1e1; + border: 1px solid #caccce; + vertical-align: middle; + margin-left: auto; + margin-right: auto; +} + + +.grayscale { filter: grayscale(100%); } + .circlBadgeAcquired { - box-shadow: 0px 0px 15px #0000ff + /*box-shadow: 0px 0px 15px #0000ff*/ + box-shadow: 0px 0px 3px #1b6a92, 0px 0px 10px #2fa1db; } .questionBadgeText { diff --git a/static/js/contrib.js b/static/js/contrib.js index 4f9ee03..ba27b31 100644 --- a/static/js/contrib.js +++ b/static/js/contrib.js @@ -452,6 +452,23 @@ function updateProgressHeader(org) { } }); + // set trophies if acquired + $.getJSON( url_getTrophies+'?org='+org, function( data ) { + var source = url_baseTrophyLogo+0+'.png' + for(var i=0; i - - + + + + +
@@ -190,7 +258,8 @@
- + +