Updated non-test function + minor UI fix

pull/3/head
Sami Mokaddem 2017-11-09 10:58:18 +01:00
parent 97a9020716
commit cc766d7b04
3 changed files with 46 additions and 27 deletions

View File

@ -58,7 +58,7 @@ class Contributor_helper:
''' HELPER ''' ''' HELPER '''
def getOrgLogoFromRedis(self, org): def getOrgLogoFromMISP(self, org):
return "{}/img/orgs/{}.png".format(self.misp_web_url, org) return "{}/img/orgs/{}.png".format(self.misp_web_url, org)
def getZrange(self, keyCateg, date, topNum, endSubkey=""): def getZrange(self, keyCateg, date, topNum, endSubkey=""):
@ -84,7 +84,7 @@ class Contributor_helper:
final_rank += 1 final_rank += 1
num_of_previous_req_not_fulfilled = len([x for x in requirement_not_fulfilled if x<final_rank]) num_of_previous_req_not_fulfilled = len([x for x in requirement_not_fulfilled if x<final_rank])
final_rank = final_rank - num_of_previous_req_not_fulfilled final_rank = final_rank - num_of_previous_req_not_fulfilled
return [final_rank, requirement_fulfilled, requirement_not_fulfilled] return {'final_rank': final_rank, 'req_fulfilled': requirement_fulfilled, 'req_not_fulfilled': requirement_not_fulfilled}
def giveContribRankToOrg(self, org, rankNum): def giveContribRankToOrg(self, org, rankNum):
keyname = 'CONTRIB_ORG:{org}:{orgCateg}' keyname = 'CONTRIB_ORG:{org}:{orgCateg}'
@ -96,7 +96,10 @@ class Contributor_helper:
# 1 for fulfilled, 0 for not fulfilled, -1 for not relevant # 1 for fulfilled, 0 for not fulfilled, -1 for not relevant
def getCurrentContributionStatus(self, org): def getCurrentContributionStatus(self, org):
final_rank, requirement_fulfilled, requirement_not_fulfilled = self.getOrgContributionRank(org) temp = self.getOrgContributionRank(org)
final_rank = temp['final_rank']
requirement_fulfilled = temp['req_fulfilled']
requirement_not_fulfilled = temp['req_not_fulfilled']
to_ret = {} to_ret = {}
for i in range(1, self.org_rank_maxLevel+1): for i in range(1, self.org_rank_maxLevel+1):
if i in requirement_fulfilled: if i in requirement_fulfilled:
@ -198,7 +201,9 @@ class Contributor_helper:
for org, sec in last_contrib_org: for org, sec in last_contrib_org:
dic = {} dic = {}
dic['rank'] = self.getOrgRankFromRedis(org, date) dic['rank'] = self.getOrgRankFromRedis(org, date)
dic['logo_path'] = self.getOrgLogoFromRedis(org) dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org dic['org'] = org
dic['pnts'] = self.getOrgPntFromRedis(org, date) dic['pnts'] = self.getOrgPntFromRedis(org, date)
dic['epoch'] = sec dic['epoch'] = sec
@ -210,7 +215,9 @@ class Contributor_helper:
epoch = self.serv_redis_db.zscore("CONTRIB_LAST", org) epoch = self.serv_redis_db.zscore("CONTRIB_LAST", org)
dic = {} dic = {}
dic['rank'] = self.getOrgRankFromRedis(org, date) dic['rank'] = self.getOrgRankFromRedis(org, date)
dic['logo_path'] = self.getOrgLogoFromRedis(org) dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org dic['org'] = org
dic['pnts'] = self.getOrgPntFromRedis(org, date) dic['pnts'] = self.getOrgPntFromRedis(org, date)
dic['epoch'] = epoch dic['epoch'] = epoch
@ -231,7 +238,9 @@ class Contributor_helper:
for org, pnts in orgDicoPnts.items(): for org, pnts in orgDicoPnts.items():
dic = {} dic = {}
dic['rank'] = self.getTrueRank(pnts) dic['rank'] = self.getTrueRank(pnts)
dic['logo_path'] = self.getOrgLogoFromRedis(org) dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org dic['org'] = org
dic['pnts'] = pnts dic['pnts'] = pnts
data.append(dic) data.append(dic)
@ -247,17 +256,23 @@ class Contributor_helper:
for dic in topSortedOrg[0:5]: for dic in topSortedOrg[0:5]:
org = dic['org'] org = dic['org']
overtime = [] overtime = []
for deltaD in range(1,6,1): to_append = self.getOrgOvertime(org)
date = (datetime.datetime(today.year, today.month, today.day) - datetime.timedelta(days=deltaD))
keyname = 'CONTRIB_DAY:'+util.getDateStrFormat(date)
org_score = self.serv_redis_db.zscore(keyname, org)
if org_score is None:
org_score = 0
overtime.append([deltaD, org_score])
to_append = {'label': org, 'data': overtime}
data.append(to_append) data.append(to_append)
return data return data
def getOrgOvertime(self, org):
overtime = []
today = datetime.datetime.now()
for deltaD in range(1,6,1):
date = (datetime.datetime(today.year, today.month, today.day) - datetime.timedelta(days=deltaD))
keyname = 'CONTRIB_DAY:'+util.getDateStrFormat(date)
org_score = self.serv_redis_db.zscore(keyname, org)
if org_score is None:
org_score = 0
overtime.append([deltaD, org_score])
to_return = {'label': org, 'data': overtime}
return to_return
def getCategPerContribFromRedis(self, date): def getCategPerContribFromRedis(self, date):
keyCateg = "CONTRIB_DAY" keyCateg = "CONTRIB_DAY"
topNum = 0 # all topNum = 0 # all
@ -266,7 +281,9 @@ class Contributor_helper:
for org, pnts in contrib_org: for org, pnts in contrib_org:
dic = {} dic = {}
dic['rank'] = self.getTrueRank(pnts) dic['rank'] = self.getTrueRank(pnts)
dic['logo_path'] = self.getOrgLogoFromRedis(org) dic['orgRank'] = self.getOrgContributionRank(org)['final_rank']
dic['honorBadge'] = self.getOrgHonorBadges(org)
dic['logo_path'] = self.getOrgLogoFromMISP(org)
dic['org'] = org dic['org'] = org
dic['pnts'] = pnts dic['pnts'] = pnts
for categ in self.categories_in_datatable: for categ in self.categories_in_datatable:
@ -291,6 +308,8 @@ class Contributor_helper:
'org': org, 'org': org,
'points': points, 'points': points,
'rank': self.getRankLevel(points), 'rank': self.getRankLevel(points),
'orgRank': self.getOrgContributionRank(org)['final_rank'],
'honorBadge': self.getOrgHonorBadges(org),
'remainingPts': remainingPts['remainingPts'], 'remainingPts': remainingPts['remainingPts'],
'stepPts': remainingPts['stepPts'], 'stepPts': remainingPts['stepPts'],
} }
@ -363,7 +382,7 @@ class Contributor_helper:
'rank': random.randint(1,self.levelMax), 'rank': random.randint(1,self.levelMax),
'orgRank': random.randint(1,self.levelMax), 'orgRank': random.randint(1,self.levelMax),
'honorBadge': [1,2], 'honorBadge': [1,2],
'logo_path': self.getOrgLogoFromRedis('MISP'), 'logo_path': self.getOrgLogoFromMISP('MISP'),
'org': 'MISP', 'org': 'MISP',
'pnts': random.randint(1,2**self.levelMax) 'pnts': random.randint(1,2**self.levelMax)
}, },
@ -417,7 +436,7 @@ class Contributor_helper:
'rank': random.randint(1,self.levelMax), 'rank': random.randint(1,self.levelMax),
'orgRank': random.randint(1,self.levelMax), 'orgRank': random.randint(1,self.levelMax),
'honorBadge': [1,2], 'honorBadge': [1,2],
'logo_path': self.getOrgLogoFromRedis('MISP'), 'logo_path': self.getOrgLogoFromMISP('MISP'),
'org': 'MISP', 'org': 'MISP',
'pnts': random.randint(1,2**self.levelMax), 'pnts': random.randint(1,2**self.levelMax),
'epoch': time.time() - random.randint(0, 10000) 'epoch': time.time() - random.randint(0, 10000)

View File

@ -286,7 +286,7 @@ def getCoordsByRadius():
@app.route("/_getLastContributors") @app.route("/_getLastContributors")
def getLastContributors(): def getLastContributors():
return jsonify(contributor_helper.TEST_getLastContributorsFromRedis()) return jsonify(contributor_helper.getLastContributorsFromRedis())
@app.route("/_eventStreamLastContributor") @app.route("/_eventStreamLastContributor")
def getLastContributor(): def getLastContributor():
@ -313,7 +313,7 @@ def getTopContributor(suppliedDate=None):
else: else:
date = suppliedDate date = suppliedDate
data = contributor_helper.TEST_getTopContributorFromRedis(date) data = contributor_helper.getTopContributorFromRedis(date)
return jsonify(data) return jsonify(data)
@app.route("/_getFameContributor") @app.route("/_getFameContributor")
@ -329,7 +329,7 @@ def getFameContributor():
@app.route("/_getTop5Overtime") @app.route("/_getTop5Overtime")
def getTop5Overtime(): def getTop5Overtime():
return jsonify(contributor_helper.TEST_getTop5OvertimeFromRedis()) return jsonify(contributor_helper.getTop5OvertimeFromRedis())
@app.route("/_getOrgOvertime") @app.route("/_getOrgOvertime")
def getOrgOvertime(): def getOrgOvertime():
@ -337,7 +337,7 @@ def getOrgOvertime():
org = request.args.get('org') org = request.args.get('org')
except: except:
org = '' org = ''
return jsonify(contributor_helper.TEST_getOrgOvertime(org)) return jsonify(contributor_helper.getOrgOvertime(org))
@app.route("/_getCategPerContrib") @app.route("/_getCategPerContrib")
def getCategPerContrib(): def getCategPerContrib():
@ -346,11 +346,11 @@ def getCategPerContrib():
except: except:
date = datetime.datetime.now() date = datetime.datetime.now()
return jsonify(contributor_helper.TEST_getCategPerContribFromRedis(date)) return jsonify(contributor_helper.getCategPerContribFromRedis(date))
@app.route("/_getAllOrg") @app.route("/_getAllOrg")
def getAllOrg(): def getAllOrg():
return jsonify(contributor_helper.TEST_getAllOrgFromRedis()) return jsonify(contributor_helper.getAllOrgFromRedis())
@app.route("/_getOrgRank") @app.route("/_getOrgRank")
def getOrgRank(): def getOrgRank():
@ -358,7 +358,7 @@ def getOrgRank():
org = request.args.get('org') org = request.args.get('org')
except: except:
org = '' org = ''
return jsonify(contributor_helper.TEST_getCurrentOrgRankFromRedis(org)) return jsonify(contributor_helper.getCurrentOrgRankFromRedis(org))
@app.route("/_getContributionOrgStatus") @app.route("/_getContributionOrgStatus")
def getContributionOrgStatus(): def getContributionOrgStatus():
@ -366,7 +366,7 @@ def getContributionOrgStatus():
org = request.args.get('org') org = request.args.get('org')
except: except:
org = '' org = ''
return jsonify(contributor_helper.TEST_getCurrentContributionStatus(org)) return jsonify(contributor_helper.getCurrentContributionStatus(org))
@app.route("/_getHonorBadges") @app.route("/_getHonorBadges")
def getHonorBadges(): def getHonorBadges():
@ -374,7 +374,7 @@ def getHonorBadges():
org = request.args.get('org') org = request.args.get('org')
except: except:
org = '' org = ''
return jsonify(contributor_helper.TEST_getOrgHonorBadges(org)) return jsonify(contributor_helper.getOrgHonorBadges(org))
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='localhost', port=8001, threaded=True) app.run(host='localhost', port=8001, threaded=True)

View File

@ -408,7 +408,7 @@ function updateProgressHeader(org) {
var orgRowPnts = this.data()[0] var orgRowPnts = this.data()[0]
if(orgRowName == currOrg) { if(orgRowName == currOrg) {
if(prevOrgName == ""){ //already first if(prevOrgName == ""){ //already first
$('#orgToOverTake').text(this.data()[5]); $('#orgToOverTake').text(orgRowName);
$('#pntsToOvertakeNext').text(0); $('#pntsToOvertakeNext').text(0);
} else { } else {
$('#orgToOverTake').text(prevOrgName); $('#orgToOverTake').text(prevOrgName);