Fixed bug json parsing in server + continuation of trophy support in zmq

pull/7/head
Sami Mokaddem 2017-11-14 14:56:15 +01:00
parent f22aaee21d
commit 8eae00f6b5
4 changed files with 32 additions and 8 deletions

View File

@ -137,6 +137,7 @@ class Contributor_helper:
ContributionStatus = self.getCurrentContributionStatus(orgName)
oldContributionStatus = ContributionStatus['status']
oldHonorBadges = self.getOrgHonorBadges(orgName)
oldTrophy = self.getOrgTrophies(orgName)
keyname = 'CONTRIB_ORG:{org}:{orgCateg}'
# update total points
totOrgPnts = self.serv_redis_db.incrby(keyname.format(org=orgName, orgCateg='points'), pnts_to_add)
@ -214,7 +215,9 @@ class Contributor_helper:
ContributionStatus = self.getCurrentContributionStatus(orgName)
newContributionStatus = ContributionStatus['status']
newHonorBadges = self.getOrgHonorBadges(orgName)
newTrophy = self.getOrgTrophies(orgName)
# awards to publish
awards_given = []
for i in newContributionStatus.keys():
if oldContributionStatus[i] < newContributionStatus[i] and i != ContributionStatus['rank']:
@ -224,6 +227,17 @@ class Contributor_helper:
if badgeNum not in oldHonorBadges:
awards_given.append(['badge', badgeNum])
temp = {}
for item in oldTrophy:
categ = item['categ']
rank = item['trophy_true_rank']
temp[categ] = rank
for item in newTrophy:
categ = item['categ']
rank = item['trophy_true_rank']
if rank > temp[categ]:
awards_given.append(['trophy', [categ, rank]])
return awards_given
''' HONOR BADGES '''

View File

@ -322,12 +322,12 @@ def eventStreamAwards():
for msg in subscriber_lastAwards.listen():
content = msg['data'].decode('utf8')
contentJson = json.loads(content)
data = json.loads(contentJson['data'])
org = data['org']
lastAwardJson = json.loads(contentJson['log'])
org = lastAwardJson['org']
to_return = contributor_helper.getContributorFromRedis(org)
epoch = data['epoch']
epoch = lastAwardJson['epoch']
to_return['epoch'] = epoch
to_return['award'] = data['award']
to_return['award'] = lastAwardJson['award']
yield 'data: {}\n\n'.format(json.dumps(to_return))
@app.route("/_getTopContributor")

View File

@ -3,6 +3,7 @@ var allOrg = [];
var datatableTop;
var datatableFameQuant;
var refresh_speed = min_between_reload*60;
var next_effect = new Date();
var will_reload = $("#reloadCheckbox").is(':checked');
var sec_before_reload = refresh_speed;
var plotLineChart;
@ -355,6 +356,10 @@ function addLastContributor(datatable, data, update) {
if($(this.data()[6])[0].text == data.org) {
var node = $(datatable.row( this ).node());
datatable.row( this ).data( to_add );
if(next_effect <= new Date()) {
node.effect("slide", 500);
next_effect.setSeconds(next_effect.getSeconds() + 5);
}
row_added = true;
}
datatable.draw();
@ -554,8 +559,6 @@ function updateTimer() {
if ($("#reloadCheckbox").is(':checked')) {
sec_before_reload--;
if (sec_before_reload < 1) {
source_lastContrib.close();
source_awards.close();
location.reload();
} else {
$('#labelRemainingTime').text(timeToString(sec_before_reload));
@ -575,6 +578,12 @@ $(document).ready(function() {
updateTimer();
$('#orgName').typeahead(typeaheadOption);
$('#btnCurrRank').popover(popOverOption);
$(window).on("beforeunload", function() {
source_lastContrib.close();
source_awards.close();
});
datatableTop = $('#topContribTable').DataTable(optionDatatable_top);
datatableFameQuant = $('#fameTableQuantity').DataTable(optionDatatable_fame);
datatableFameQual = $('#fameTableQuality').DataTable(optionDatatable_fame);
@ -617,7 +626,7 @@ $(document).ready(function() {
if(currOrg != "") // currOrg selected
//FIXME: timeout used to wait that all datatables are draw.
setTimeout( function() { updateProgressHeader(currOrg); }, 500);
setTimeout( function() { updateProgressHeader(currOrg); }, 700);
source_lastContrib = new EventSource(url_eventStreamLastContributor);
source_lastContrib.onmessage = function(event) {
@ -632,5 +641,6 @@ $(document).ready(function() {
source_awards.onmessage = function(event) {
var json = jQuery.parseJSON( event.data );
addAwards(datatableAwards, json, true);
updateProgressHeader(currOrg);
};
});

View File

@ -399,7 +399,7 @@
<div class="panel panel-default" style="height: 100%;">
<div class="panel-heading bg-info" style="font-weight: bold;">
<i class="fa fa-star" style="margin-right: 5px; color: #f0ad4e;"></i><b>Hall Of Fame - Quantity (previous month)</b>
<i class="fa fa-star" style="margin-right: 5px; color: #f0ad4e;"></i><b>Hall Of Fame (previous month)</b>
</div>
<div class="panel-body" style="height: 100%;">