From 813cc7031a99713d4ab64332cd9c77454f7e8326 Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Thu, 25 Aug 2016 17:48:12 +0200 Subject: [PATCH] Changed lots of code into zrank --- bin/WebStats.py | 20 +------------------- var/www/Flask_server.py | 17 ++++------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/bin/WebStats.py b/bin/WebStats.py index 20c1f489..d8ff0876 100755 --- a/bin/WebStats.py +++ b/bin/WebStats.py @@ -66,25 +66,7 @@ def compute_progression(server, field_name, num_day, url_parsed): # filter if (keyword_total_sum > threshold_total_sum) and (keyword_increase > threshold_increase): - if server.sismember(redis_progression_name_set, keyword): #if keyword is in the set - server.hset(redis_progression_name, keyword, keyword_increase) #update its value - - elif (server.scard(redis_progression_name_set) < max_set_cardinality): - server.sadd(redis_progression_name_set, keyword) - - else: #not in the set - #Check value for all members - member_set = [] - for keyw in server.smembers(redis_progression_name_set): - member_set.append((keyw, int(server.hget(redis_progression_name, keyw)))) - member_set.sort(key=lambda tup: tup[1]) - if member_set[0][1] < keyword_increase: - print 'removing', member_set[0][0] + '('+str(member_set[0][1])+')', 'and adding', keyword, str(keyword_increase) - #remove min from set and add the new one - server.srem(redis_progression_name_set, member_set[0][0]) - server.sadd(redis_progression_name_set, keyword) - server.hdel(redis_progression_name, member_set[0][0]) - server.hset(redis_progression_name, keyword, keyword_increase) + server.zadd("z_top_progression_"+field_name, float(keyword_increase), keyword) if __name__ == '__main__': diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 14bb8474..925ed369 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -160,6 +160,7 @@ def showpaste(content_range): p_lineinfo = paste.get_lines_info() p_content = paste.get_p_content().decode('utf-8', 'ignore') p_duplicate_full_list = parseStringToList2(paste._get_p_duplicate()) + p_duplicate_full_list = json.load(paste._get_p_duplicate()) p_duplicate_list = [] p_simil_list = [] p_hashtype_list = [] @@ -290,19 +291,9 @@ def progressionCharts(): return jsonify(bar_values) else: - redis_progression_name = 'top_progression_'+trending_name - redis_progression_name_set = 'top_progression_'+trending_name+'_set' - - # Iterate over element in top_x_set and retreive their value - member_set = [] - for keyw in r_serv_charts.smembers(redis_progression_name_set): - keyw_value = r_serv_charts.hget(redis_progression_name, keyw) - keyw_value = keyw_value if keyw_value is not None else 0 - member_set.append((keyw, int(keyw_value))) - member_set.sort(key=lambda tup: tup[1], reverse=True) - if len(member_set) == 0: - member_set.append(("No relevant data", int(100))) - return jsonify(member_set) + redis_progression_name = "z_top_progression_" + trending_name + keyw_value = r_serv_charts.zrevrangebyscore(redis_progression_name, '+inf', '-inf', withscores=True, start=0, num=10) + return jsonify(keyw_value) @app.route("/_moduleCharts", methods=['GET']) def modulesCharts():