From 846d3870459e8c79a683929b44c5c3630065c769 Mon Sep 17 00:00:00 2001 From: Manos Katsomallos Date: Wed, 29 Sep 2021 00:12:57 +0200 Subject: [PATCH] code: Find user's landmarks timestamps --- code/lib/lmdk_lib.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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.