mirror of https://github.com/MISP/misp-dashboard
Better support of custom scale ranking
parent
cb674a770d
commit
eb9719e5ff
10
server.py
10
server.py
|
@ -103,14 +103,14 @@ def getRankLevel(points):
|
||||||
if points == 0:
|
if points == 0:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return float("{:.2f}".format(math.log(points, cfg.getint('CONTRIB' ,'rankMultiplier'))))
|
return float("{:.2f}".format(math.log(points, cfg.getfloat('CONTRIB' ,'rankMultiplier'))))
|
||||||
def getRemainingPoints(points):
|
def getRemainingPoints(points):
|
||||||
prev = 0
|
prev = 0
|
||||||
for i in [cfg.getint('CONTRIB' ,'rankMultiplier')**x for x in range(1,17)]:
|
for i in [math.floor(cfg.getfloat('CONTRIB' ,'rankMultiplier')**x) for x in range(1,17)]:
|
||||||
if prev <= points < i:
|
if prev <= points < i:
|
||||||
return { 'remainingPts': i-points, 'stepPts': prev }
|
return { 'remainingPts': i-points, 'stepPts': prev }
|
||||||
prev = i
|
prev = i
|
||||||
return 0
|
return { 'remainingPts': 0, 'stepPts': cfg.getfloat('CONTRIB' ,'rankMultiplier')**16 }
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
@ -145,7 +145,7 @@ def geo():
|
||||||
def contrib():
|
def contrib():
|
||||||
return render_template('contrib.html',
|
return render_template('contrib.html',
|
||||||
currOrg="",
|
currOrg="",
|
||||||
rankMultiplier=cfg.getint('CONTRIB' ,'rankMultiplier')
|
rankMultiplier=cfg.getfloat('CONTRIB' ,'rankMultiplier')
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route("/_getLastContributor")
|
@app.route("/_getLastContributor")
|
||||||
|
@ -272,7 +272,7 @@ def getOrgRank():
|
||||||
org = request.args.get('org')
|
org = request.args.get('org')
|
||||||
except:
|
except:
|
||||||
org = ''
|
org = ''
|
||||||
points = random.randint(1,2**16)
|
points = random.randint(1,math.floor(cfg.getfloat('CONTRIB' ,'rankMultiplier')**16))
|
||||||
#FIXME put 0 if org has no points
|
#FIXME put 0 if org has no points
|
||||||
remainingPts = getRemainingPoints(points)
|
remainingPts = getRemainingPoints(points)
|
||||||
data = {'org': org, 'points': points, 'rank': getRankLevel(points), 'remainingPts': remainingPts['remainingPts'], 'stepPts': remainingPts['stepPts']}
|
data = {'org': org, 'points': points, 'rank': getRankLevel(points), 'remainingPts': remainingPts['remainingPts'], 'stepPts': remainingPts['stepPts']}
|
||||||
|
|
|
@ -79,7 +79,11 @@ var typeaheadOption = {
|
||||||
|
|
||||||
/* FUNCTIONS */
|
/* FUNCTIONS */
|
||||||
function getRankIcon(rank, size, header) {
|
function getRankIcon(rank, size, header) {
|
||||||
rankLogoPath = url_baseRankLogo+rank+'.png';
|
if (rank > 16) {
|
||||||
|
rankLogoPath = url_baseRankLogo+0+'.png';
|
||||||
|
} else {
|
||||||
|
rankLogoPath = url_baseRankLogo+rank+'.png';
|
||||||
|
}
|
||||||
var img = document.createElement('img');
|
var img = document.createElement('img');
|
||||||
img.src = rankLogoPath;
|
img.src = rankLogoPath;
|
||||||
if(size == undefined) {
|
if(size == undefined) {
|
||||||
|
@ -141,18 +145,22 @@ function generateRankingSheet(rank, stepPnt, pnt, Rpnt) {
|
||||||
var tbody = document.createElement('tbody');
|
var tbody = document.createElement('tbody');
|
||||||
for (var i=1; i<=maxRank; i++) {
|
for (var i=1; i<=maxRank; i++) {
|
||||||
var tr = document.createElement('tr');
|
var tr = document.createElement('tr');
|
||||||
var td = document.createElement('td');
|
var td1 = document.createElement('td');
|
||||||
td.innerHTML = getRankIcon(i, 20);
|
td1.innerHTML = getRankIcon(i, 20);
|
||||||
td.style.padding = "2px";
|
td1.style.padding = "2px";
|
||||||
tr.appendChild(td);
|
var td2 = document.createElement('td');
|
||||||
var td = document.createElement('td');
|
td2.innerHTML = Math.floor(Math.pow(rankMultiplier, i));
|
||||||
td.innerHTML = Math.pow(rankMultiplier, i);
|
td2.style.padding = "2px";
|
||||||
td.style.padding = "2px";
|
|
||||||
tr.style.textAlign = "center";
|
tr.style.textAlign = "center";
|
||||||
if (i == rank) { // current org rank
|
if (i == rank) { // current org rank
|
||||||
tr.classList.add('info')
|
tr.style.backgroundColor = "#337ab7";
|
||||||
|
tr.style.color = "white";
|
||||||
|
} else if (i == rank+1) {
|
||||||
|
tr.style.backgroundColor = "#f0ad4e";
|
||||||
|
tr.style.color = "white";
|
||||||
}
|
}
|
||||||
tr.appendChild(td);
|
tr.appendChild(td1);
|
||||||
|
tr.appendChild(td2);
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
}
|
||||||
table.appendChild(thead);
|
table.appendChild(thead);
|
||||||
|
|
Loading…
Reference in New Issue