code: Validated parsing copenhagen data set
This commit is contained in:
parent
04fdbb7c83
commit
fae40756d0
@ -3,6 +3,7 @@
|
|||||||
import sys
|
import sys
|
||||||
sys.path.insert(1, 'lib')
|
sys.path.insert(1, 'lib')
|
||||||
import argparse
|
import argparse
|
||||||
|
import ast
|
||||||
import csv
|
import csv
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from geopy.distance import distance
|
from geopy.distance import distance
|
||||||
@ -31,6 +32,9 @@ rssi = 3
|
|||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
'''
|
||||||
|
Load data
|
||||||
|
'''
|
||||||
# Get contacts from previous parsing
|
# Get contacts from previous parsing
|
||||||
cont_data = lmdk_lib.load_data(args, 'cont')
|
cont_data = lmdk_lib.load_data(args, 'cont')
|
||||||
if cont_data.size == 0:
|
if cont_data.size == 0:
|
||||||
@ -57,50 +61,75 @@ def main(args):
|
|||||||
print('[Error: %s]' %(e))
|
print('[Error: %s]' %(e))
|
||||||
# Save to results
|
# Save to results
|
||||||
lmdk_lib.save_data(args, np.array(cont, np.float32), 'cont')
|
lmdk_lib.save_data(args, np.array(cont, np.float32), 'cont')
|
||||||
|
'''
|
||||||
|
Get users' landmarks
|
||||||
|
'''
|
||||||
# Get all users
|
# Get all users
|
||||||
usrs = np.unique(np.concatenate((cont_data[:, uid_a], cont_data[:, uid_b]), 0))
|
usrs = np.unique(np.concatenate((cont_data[:, uid_a], cont_data[:, uid_b]), 0))
|
||||||
# Check each user
|
# Check each user
|
||||||
goal = [.2, .4, .6, .8]
|
goal = [.2, .4, .6, .8]
|
||||||
# Users suitable for experiments
|
# Get users' data from previous parsing
|
||||||
usrs_expt = []
|
usrs_expt = lmdk_lib.load_data(args, 'usrs_expt')
|
||||||
for usr_i, usr in enumerate(usrs):
|
if usrs_expt.size == 0:
|
||||||
print('Checking %d (%d%%: %d/%d)... ' %(usr, (usr_i + 1)*100/len(usrs), usr_i + 1, len(usrs)), end='', flush=True)
|
# Users suitable for experiments
|
||||||
usrs_expt_cur = []
|
usrs_expt = []
|
||||||
# User's contacts
|
for usr_i, usr in enumerate(usrs):
|
||||||
usr_cont = cont_data[(cont_data[:, uid_a] == usr) | (cont_data[:, uid_b] == usr)]
|
print('Checking %d (%d%%: %d/%d)... ' %(usr, (usr_i + 1)*100/len(usrs), usr_i + 1, len(usrs)), end='', flush=True)
|
||||||
# For each goal
|
usrs_expt_cur = []
|
||||||
for_expt = True
|
# User's contacts
|
||||||
for g in goal:
|
usr_cont = cont_data[(cont_data[:, uid_a] == usr) | (cont_data[:, uid_b] == usr)]
|
||||||
if for_expt:
|
# For each goal
|
||||||
# Possible contacts
|
for_expt = True
|
||||||
pos_cont = []
|
for g in goal:
|
||||||
usrs_cur = list(usrs)
|
if for_expt:
|
||||||
# Remove user
|
# Possible contacts
|
||||||
usrs_cur.remove(usr)
|
pos_cont = []
|
||||||
# Check for every possible contact
|
usrs_cur = list(usrs)
|
||||||
for u in usrs_cur:
|
# Remove user
|
||||||
# Add possible contacts gradually
|
usrs_cur.remove(usr)
|
||||||
pos_cont.append(int(u))
|
# Check for every possible contact
|
||||||
# Remove from user contacts
|
for u in usrs_cur:
|
||||||
usr_cont_cur = np.copy(usr_cont)
|
# Add possible contacts gradually
|
||||||
for pos_c in pos_cont:
|
pos_cont.append(int(u))
|
||||||
usr_cont_cur = usr_cont_cur[(usr_cont_cur[:, uid_a] != pos_c) & (usr_cont_cur[:, uid_b] != pos_c)]
|
# Remove from user contacts
|
||||||
# Compare the difference
|
usr_cont_cur = np.copy(usr_cont)
|
||||||
diff = (len(usr_cont) - len(usr_cont_cur))/len(usr_cont)
|
for pos_c in pos_cont:
|
||||||
# Check if it is close enough to what we need
|
usr_cont_cur = usr_cont_cur[(usr_cont_cur[:, uid_a] != pos_c) & (usr_cont_cur[:, uid_b] != pos_c)]
|
||||||
if abs(diff - g)/g < .01:
|
# Compare the difference
|
||||||
usrs_expt_cur.append([int(usr), g, str(pos_cont)])
|
diff = (len(usr_cont) - len(usr_cont_cur))/len(usr_cont)
|
||||||
if g == goal[len(goal) - 1]:
|
# Check if it is close enough to what we need
|
||||||
# That's a keeper
|
if abs(diff - g)/g < .01:
|
||||||
print('[OK]')
|
usrs_expt_cur.append([int(usr), g, str(pos_cont)])
|
||||||
usrs_expt += usrs_expt_cur
|
if g == goal[len(goal) - 1]:
|
||||||
break
|
# That's a keeper
|
||||||
elif diff > g:
|
print('[OK]')
|
||||||
print('[NOK]')
|
usrs_expt += usrs_expt_cur
|
||||||
for_expt = False
|
break
|
||||||
break
|
elif diff > g:
|
||||||
# Save to results
|
print('[NOK]')
|
||||||
lmdk_lib.save_data(args, np.array(usrs_expt, str), 'usrs_expt')
|
for_expt = False
|
||||||
|
break
|
||||||
|
# Save to results
|
||||||
|
lmdk_lib.save_data(args, np.array(usrs_expt, str), 'usrs_expt')
|
||||||
|
'''
|
||||||
|
Get contacts for uid 14
|
||||||
|
'''
|
||||||
|
usr = '14'
|
||||||
|
# All user contacts
|
||||||
|
usr_cont = cont_data[(cont_data[:, uid_a] == float(usr)) | (cont_data[:, uid_b] == float(usr))]
|
||||||
|
# All user landmarks for different goals
|
||||||
|
usr_lmdk = usrs_expt[usrs_expt[:, 0] == usr]
|
||||||
|
for g in goal:
|
||||||
|
# Get goal landmarks
|
||||||
|
cont = ast.literal_eval(usr_lmdk[usr_lmdk[:, 1] == str(g)][0][2])
|
||||||
|
usr_cont_cur = np.copy(usr_cont)
|
||||||
|
# Remove goal landmarks from contacts
|
||||||
|
for c in cont:
|
||||||
|
# print(usr_cont)
|
||||||
|
# exit()
|
||||||
|
usr_cont_cur = usr_cont_cur[(usr_cont_cur[:, uid_a] != c) & (usr_cont_cur[:, uid_b] != c)]
|
||||||
|
# Check
|
||||||
|
print(g, (len(usr_cont) - len(usr_cont_cur))/len(usr_cont))
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user