diff --git a/code/lib/lmdk_lib.py b/code/lib/lmdk_lib.py index bc22c25..356f69a 100644 --- a/code/lib/lmdk_lib.py +++ b/code/lib/lmdk_lib.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import ast from datetime import datetime from geopy.distance import distance import heapq @@ -873,6 +874,41 @@ def find_lmdks(usrs_data, args): return usrs_lmdks +def find_lmdks_cont(lmdk_data, seq, uid, pct): + ''' + Find user's landmarks timestamps. + + Parameters: + lmdk_data - The landmarks contacts for all users per + landmarks percentage. + 0: uid, 1: lmdk_pct, 2: contacts + seq - The users' data. + 0: uid, 1: lmdk_pct, 2: contacts + uid - The user's id that we are interested in. + pct - The landmarks percentage. + Returns: + lmdks - The user's landmarks timestamps for the given + landmarks percentage. + 0: tim, 1: uid_a, 2: uid_b, 3: rssi + ''' + # Initialize user's landmarks + lmdks = np.empty(0) + # All the sequence + if pct == 100: + # Get all timestamps + return seq[:, 1] + # Find for given percentage + elif pct != 0: + # All user's landmark contacts for all landmarks percentages + usr_lmdks = lmdk_data[lmdk_data[:, 0] == uid] + # User's landmark contacts for given percentage + pct_lmdks = ast.literal_eval(usr_lmdks[usr_lmdks[:, 1] == str(pct/100)][0][2]) + # Find landmarks timestamps + for u in pct_lmdks: + lmdks = np.concatenate((lmdks, np.array(seq[seq[:, 2] == float(u)])[:, 0])) + return lmdks + + def lmdks_stats(args, usrs_lmdks): ''' Generate landmarks' stats.