Added support of rank from org points

pull/3/head
Sami Mokaddem 2017-11-02 11:36:23 +01:00
parent 8e2b5477f2
commit 2685a08019
3 changed files with 19 additions and 5 deletions

View File

@ -98,6 +98,16 @@ def getZrange(keyCateg, date, topNum):
data = [ [record[0].decode('utf8'), record[1]] for record in data ]
return data
# max lvl is 16
def getRankLevel(points):
return float("{:.2f}".format(math.log(points, 2)))
def getRemainingPoints(points):
prev = 0
for i in [2**x for x in range(1,17)]:
if prev <= points < i:
return i-points
prev = i
return 0
@app.route("/")
def index():
@ -258,7 +268,8 @@ def getOrgRank():
org = request.args.get('org')
except:
org = ''
data = {'org': org, 'rank': random.randint(1,16)}
points = random.randint(1,2**16)
data = {'org': org, 'points': points, 'rank': getRankLevel(points), 'remainingPts': getRemainingPoints(points)}
return jsonify(data)
@app.route("/_getTopCoord")

View File

@ -160,12 +160,15 @@ function addToTableFromJson(datatable, url) {
function updateProgressHeader(org) {
// get Org rank
$.getJSON( url_getOrgRank+'?org='+org, function( data ) {
console.log(data);
var rank = Math.floor(data.rank);
$('#btnCurrRank').show();
$('#orgText').text(data.org);
var popoverRank = $('#btnCurrRank').data('bs.popover');
popoverRank.options.content = generateRankingSheet(data.rank);
$('#orgRankDiv').html(getRankIcon(data.rank, 40, true));
$('#orgNextRankDiv').html(getRankIcon(data.rank+1, 40, true));
popoverRank.options.content = generateRankingSheet(rank);
$('#orgRankDiv').html(getRankIcon(rank, 40, true));
$('#orgNextRankDiv').html(getRankIcon(rank+1, 40, true));
$('#progressBarDiv').width((data.rank - rank)*150); //150 is empty bar width
});
}

View File

@ -71,7 +71,7 @@
<div id="orgRankDiv" class='textTopHeader' style="padding-top: 0px; position: relative; width: 40px; height: 40px;"></div>
<div class='' style="float: left; padding: 10px;">
<div class="progress" style=''>
<div id="progressBarDiv" class="progress-bar progress-bar-striped" role="progressbar" style="width:70%">
<div id="progressBarDiv" class="progress-bar progress-bar-striped" role="progressbar" style="width:0%">
</div>
</div>
</div>