def GET(self): if session.get('login', False): nodes_info = db_manager.get_all_nodes() points = db_manager.get_all_points() accounts = db_manager.get_all_accounts() account_caches = db_manager.get_all_account_cache() nodes_info2 = [] rank = [] points2 = [] accounts2 = [] account_cache2 = [] num_cache = 0 num_user = 0 num_movie = 0 n_nodes = [0, 0, 0] # Server / cache / user video_owned = [] for each in nodes_info: if str(each.type_of_node) == 'server': n_nodes[0] = n_nodes[0] + 1 elif str(each.type_of_node) == 'cache': n_nodes[1] = n_nodes[1] + 1 elif str(each.type_of_node) == 'user': n_nodes[2] = n_nodes[2] + 1 if each.ip.split('-')[1] == session.user_name: num_user = num_user + 1 nodes_info2.append(["user", str(each.ip), str(each.watching_video)]) for each in points: if each.user_name == session.user_name: points2.append(int(each.points)) #points earned video_owned = each.owned_videos.split("_") video_owned.pop(0) points2.append(len(video_owned)) #num of video watched points2.append(each.bytes_uploaded/1000000) #Mbs uploaded if each.owned_videos != None: num_movie = len(each.owned_videos.split("_"))-1 if each.user_name != 'admin': rank.append([each.user_name, num_movie, each.bytes_uploaded]) rank = sorted(rank, key=lambda user: user[2], reverse=True)[:5] #rank the users by points, get top 5 for each in rank: #each[2] = round(each[2]/1000000, 3) each[2] = each[2]/1000000 for each in accounts: if each.user_name == session.user_name: accounts2 = [each.id, str(each.user_name), str(each.password), str(each.email_address)] for each in account_caches: if each.user_name == session.user_name: num_cache = num_cache + 1 if each.multiplier == 0.25: speed = 'slow' elif each.multiplier == 0.5: speed = 'medium' else: speed = 'high' account_cache2.append(["cache", str(each.ip), str(each.port), str(each.bytes_uploaded), speed]) return render.user_overview(session.user_name, points2, accounts2, account_cache2, num_cache, num_user, nodes_info2, rank, n_nodes, video_owned) else: raise web.seeother('/login')
def GET(self): if session.get('login', False): raise web.seeother('/overview') else: nodes_info = db_manager.get_all_nodes() videos_info = db_manager.get_all_videos() points = db_manager.get_all_points() accounts = db_manager.get_all_accounts() n_nodes = [0, 0, 0] num_accounts = 0 num_videos_watched = 0 # Convert storages to lists for each in nodes_info: if str(each.type_of_node) == 'server': n_nodes[0] = n_nodes[0] + 1 elif str(each.type_of_node) == 'cache': n_nodes[1] = n_nodes[1] + 1 elif str(each.type_of_node) == 'user': n_nodes[2] = n_nodes[2] + 1 num_accounts = len(accounts) - 1 # not counting admin for each in points: if each.owned_videos != None: num_videos_watched = num_videos_watched + (len(each.owned_videos.split("_")) - 1) return render.index(n_nodes, num_accounts, num_videos_watched)
def GET(self): ## if session.get('login', False): print 'SUCCESSFULLY DETECTS LOGIN' nodes_info = db_manager.get_all_nodes() videos_info = db_manager.get_all_videos() points = db_manager.get_all_points() accounts = db_manager.get_all_accounts() account_caches = db_manager.get_all_account_cache() nodes_info2 = [] videos_info2 = [] points2 = [] accounts2 = [] account_cache2 = [] n_nodes = [0, 0, 0] # Server / cache / user if session.user_name == 'admin': #admin ## # Convert 'chunk indexes' to ints for each in nodes_info: each.stored_chunks = ast.literal_eval(str(each.stored_chunks)) if each.stored_chunks is not None: if len(each.stored_chunks.keys()) == 0: continue for key, val in each.stored_chunks.items(): stored_chunk_str = str(val) stored_chunk_list = map(int, ast.literal_eval(stored_chunk_str)) val = stored_chunk_list.sort() each.stored_chunks[key] = stored_chunk_list # Convert storages to lists for each in nodes_info: nodes_info2.append([each.id, str(each.type_of_node), str(each.ip), str(each.port), str(each.watching_video), each.stored_chunks]) if str(each.type_of_node) == 'server': n_nodes[0] = n_nodes[0] + 1 elif str(each.type_of_node) == 'cache': n_nodes[1] = n_nodes[1] + 1 elif str(each.type_of_node) == 'user': n_nodes[2] = n_nodes[2] + 1 for each in videos_info: videos_info2.append([each.id, str(each.vname), each.n_of_frames, each.code_param_n, each.code_param_k, each.total_size, each.chunk_size, each.last_chunk_size]) for each in points: points2.append([each.id, str(each.user_name), round(each.bytes_uploaded/1000000, 3), each.points, each.owned_videos]) for each in accounts: accounts2.append([each.id, str(each.user_name), str(each.password), str(each.email_address)]) for each in account_caches: account_cache2.append([each.id, str(each.user_name), str(each.ip), str(each.port), str(each.bytes_uploaded), str(each.multiplier)]) print '[tracker.py] nodes_info ', nodes_info2 print '[tracker.py] n_nodes ', n_nodes print '[tracker.py] videos_info ', videos_info2 print '[tracker.py] points_info ', points2 print '[tracker.py] accounts', accounts2 print '[tracker.py] account_cache', account_cache2 server_load = get_server_load() smoothing_filter = np.ones(10)/10 #controls smoothing on the load to users smoothing_filter2 = np.ones(10)/10 #controls smoothing on the load to caches server_load_user = np.convolve(server_load[0],smoothing_filter) server_load_cache = np.convolve(server_load[1],smoothing_filter2) ## filtered_server_load = [] filtered_server_load.append(server_load_user.tolist()) filtered_server_load.append(server_load_cache.tolist()) average_server_load = [sum(filtered_server_load[0])/len(filtered_server_load[0]), sum(filtered_server_load[1])/len(filtered_server_load[1])] #return 'hi' return render.overview(nodes_info2, n_nodes, videos_info2, filtered_server_load, average_server_load, points2, accounts2, account_cache2) else: #normal user rank = [] num_user = 0 num_movie = 0 num_cache = 0 for each in nodes_info: if str(each.type_of_node) == 'server': n_nodes[0] = n_nodes[0] + 1 elif str(each.type_of_node) == 'cache': n_nodes[1] = n_nodes[1] + 1 elif str(each.type_of_node) == 'user': n_nodes[2] = n_nodes[2] + 1 if each.ip.split('-')[1] == session.user_name: num_user = num_user + 1 nodes_info2.append(["user", str(each.ip), str(each.watching_video)]) for each in points: if each.user_name == session.user_name: points2.append(int(each.points)) #points earned video_owned = each.owned_videos.split("_") video_owned.pop(0) points2.append(len(video_owned)) #num of video watched points2.append(each.bytes_uploaded/1000000) #bytes uploaded if each.owned_videos != None: num_movie = len(each.owned_videos.split("_"))-1 if each.user_name != 'admin': rank.append([each.user_name, num_movie, each.bytes_uploaded]) rank = sorted(rank, key=lambda user: user[2], reverse=True)[:5] #rank the users by points, get top 5 for each in rank: #each[2] = round(each[2]/1000000, 3) each[2] = each[2]/1000000 for each in accounts: if each.user_name == session.user_name: accounts2 = [each.id, str(each.user_name), str(each.password), str(each.email_address)] for each in account_caches: if each.user_name == session.user_name: num_cache = num_cache + 1 if each.multiplier == 0.25: speed = 'slow' elif each.multiplier == 0.5: speed = 'medium' else: speed = 'high' account_cache2.append(["cache", str(each.ip), str(each.port), str(each.bytes_uploaded), speed]) return render.user_overview(session.user_name, points2, accounts2, account_cache2, num_cache, num_user, nodes_info2, rank, n_nodes, video_owned) else: raise web.seeother('/login')