From 8eae00f6b5b30e17a852b41011026893a3f48938 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Tue, 14 Nov 2017 14:56:15 +0100 Subject: [PATCH] Fixed bug json parsing in server + continuation of trophy support in zmq --- contributor_helper.py | 14 ++++++++++++++ server.py | 8 ++++---- static/js/contrib.js | 16 +++++++++++++--- templates/contrib.html | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/contributor_helper.py b/contributor_helper.py index d4509aa..edb574a 100644 --- a/contributor_helper.py +++ b/contributor_helper.py @@ -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 ''' diff --git a/server.py b/server.py index 12ccaae..1152fca 100755 --- a/server.py +++ b/server.py @@ -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") diff --git a/static/js/contrib.js b/static/js/contrib.js index 59fd372..9cc302d 100644 --- a/static/js/contrib.js +++ b/static/js/contrib.js @@ -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); }; }); diff --git a/templates/contrib.html b/templates/contrib.html index f16bd5a..4aa4b45 100644 --- a/templates/contrib.html +++ b/templates/contrib.html @@ -399,7 +399,7 @@
- Hall Of Fame - Quantity (previous month) + Hall Of Fame (previous month)