Fixed bug in case of null elements arrising because of a new month

This commit is contained in:
Mokaddem 2016-08-01 10:32:24 +02:00
parent a9637ec7cf
commit a1b2329a9b

View file

@ -93,6 +93,7 @@ def compute_provider_info(server, path):
else: else:
ok = server.hset(paste_provider+'_num', paste_date, 1) ok = server.hset(paste_provider+'_num', paste_date, 1)
prev_num_paste = 0
# #
# Compute Most Posted # Compute Most Posted
@ -129,14 +130,17 @@ def compute_provider_info(server, path):
#Check value for all members #Check value for all members
member_set = [] member_set = []
for provider in server.smembers(redis_providers_name_set): for provider in server.smembers(redis_providers_name_set):
curr_num = 0
curr_num = server.hget(provider+'_num', paste_date) curr_num = server.hget(provider+'_num', paste_date)
member_set.append((provider, int(curr_num))) if curr_num is not None:
member_set.append((provider, int(curr_num)))
member_set.sort(key=lambda tup: tup[1]) member_set.sort(key=lambda tup: tup[1])
if member_set[0][1] < int(prev_num_paste)+1: if len(member_set) > 0:
#remove min from set and add the new one if member_set[0][1] < int(prev_num_paste)+1:
print 'Num - adding ' +paste_provider+ '(' +str(int(prev_num_paste)+1)+') in set and removing '+member_set[0][0]+'('+str(member_set[0][1])+')' #remove min from set and add the new one
server.srem(redis_providers_name_set, member_set[0][0]) print 'Num - adding ' +paste_provider+ '(' +str(int(prev_num_paste)+1)+') in set and removing '+member_set[0][0]+'('+str(member_set[0][1])+')'
server.sadd(redis_providers_name_set, paste_provider) server.srem(redis_providers_name_set, member_set[0][0])
server.sadd(redis_providers_name_set, paste_provider)
if __name__ == '__main__': if __name__ == '__main__':
# If you wish to use an other port of channel, do not forget to run a subscriber accordingly (see launch_logs.sh) # If you wish to use an other port of channel, do not forget to run a subscriber accordingly (see launch_logs.sh)