From 2704705ddf31e2ab29793301b20cd33d52dbec2e Mon Sep 17 00:00:00 2001 From: Manos Katsomallos Date: Wed, 22 Sep 2021 22:02:25 +0200 Subject: [PATCH] code: Get contacts from previous parsing --- code/parse_copenhagen.py | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/code/parse_copenhagen.py b/code/parse_copenhagen.py index 16ee0cc..6d27cb7 100644 --- a/code/parse_copenhagen.py +++ b/code/parse_copenhagen.py @@ -30,29 +30,30 @@ rssi = 3 def main(args): - # All the contacts [tim, uid_a, uid_b]. - cont = [] - try: - print('Extracting %s... ' %(os.path.abspath(args.arc)), end='', flush=True) - with zipfile.ZipFile(args.arc, 'r') as arc: - print('[OK]') - with io.TextIOWrapper(arc.open(args.cont), newline='\n') as dat: - try: - print('Finding contacts... ', end='', flush=True) - # Get the contacts by skipping the header - cont_l = list(csv.reader(dat, delimiter=','))[hdr:] - # Check each contact - for c in cont_l: - if c[uid_b] != '-1' and c[rssi] != '0' and c[uid_b] != '-2' and c[uid_a] != c[uid_b]: - # Add valid contact - cont.append([c[tim], c[uid_a], c[uid_b]]) - print('[OK]') - except Exception as e: - print('[Error: %s]' %(e)) - except Exception as e: - print('[Error: %s]' %(e)) - # Save to results - lmdk_lib.save_data(args, np.array(cont), 'cont') + # Get contacts [tim, uid_a, uid_b] from previous parsing + cont = lmdk_lib.load_data(args, 'cont') + if cont.size == 0: + try: + print('Extracting %s... ' %(os.path.abspath(args.arc)), end='', flush=True) + with zipfile.ZipFile(args.arc, 'r') as arc: + print('[OK]') + with io.TextIOWrapper(arc.open(args.cont), newline='\n') as dat: + try: + print('Finding contacts... ', end='', flush=True) + # Get the contacts by skipping the header + cont_l = list(csv.reader(dat, delimiter=','))[hdr:] + # Check each contact + for c in cont_l: + if c[uid_b] != '-1' and c[rssi] != '0' and c[uid_b] != '-2' and c[uid_a] != c[uid_b]: + # Add valid contact + cont.append([c[tim], c[uid_a], c[uid_b]]) + print('[OK]') + except Exception as e: + print('[Error: %s]' %(e)) + except Exception as e: + print('[Error: %s]' %(e)) + # Save to results + lmdk_lib.save_data(args, np.array(cont), 'cont') '''