From 06f443b30c4f7c5c08ed6f8ee3d3a651e2a23e64 Mon Sep 17 00:00:00 2001 From: HappyZ Date: Wed, 15 May 2019 11:49:19 -0500 Subject: [PATCH] speed up the processing --- libs/parser_post.py | 39 ++++++++++++++++----------------------- pull_data_from_phone.sh | 16 ++++++++++++++++ visualize.m | 2 +- 3 files changed, 33 insertions(+), 24 deletions(-) create mode 100755 pull_data_from_phone.sh diff --git a/libs/parser_post.py b/libs/parser_post.py index a6ab953..124d372 100644 --- a/libs/parser_post.py +++ b/libs/parser_post.py @@ -14,8 +14,7 @@ def extract_dev_from_combined(fp, minimalCounts=100, cleanup=True): ''' extract each device data from combined file `fp` ''' - files = [] - counters = [] + files = {} folderpath, ext = os.path.splitext(fp) try: @@ -32,31 +31,25 @@ def extract_dev_from_combined(fp, minimalCounts=100, cleanup=True): tmp = line.rstrip().split(",") addr = tmp[2].replace(":", "") if addr not in files: - files.append(addr) - counters.append(1) - else: - counters[files.index(addr)] += 1 + files[addr] = [] + files[addr].append(",".join(tmp[:2] + tmp[3:])) - for i in range(len(counters)-1, -1, -1): - if counters[i] < minimalCounts: - counters.pop(i) - files.pop(i) + for addr in list(files.keys()): + if len(files[addr]) < minimalCounts: + del files[addr] title = lines[0].rstrip().split(",") - filepaths = ["{}/{}.csv".format(folderpath, file) for file in files] - for filepath in filepaths: - with open(filepath, "w") as f: - f.write(",".join(title[:2] + title[3:]) + "\n") + headline = ",".join(title[:2] + title[3:]) + "\n" + filepaths = [] + + for addr in files.keys(): + filepath = "{}/{}.csv".format(folderpath, addr) + filepaths.append(filepath) + with open(filepath, "w") as f: + f.write(headline) + for line in files[addr]: + f.write("{}\n".format(line)) - for line in lines[1:]: - tmp = line.rstrip().split(",") - addr = tmp[2].replace(":", "") - if addr not in files: - continue - filepath = filepaths[files.index(addr)] - with open(filepath, "a+") as f: - f.write(",".join(tmp[:2] + tmp[3:]) + "\n") - if len(files) > 0 and cleanup: os.remove(fp) diff --git a/pull_data_from_phone.sh b/pull_data_from_phone.sh new file mode 100755 index 0000000..265657d --- /dev/null +++ b/pull_data_from_phone.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +PHONEPATH=$1 +LOCALFOLDER=$2 + +mkdir -p $LOCALFOLDER + +for file in $(adb shell "ls $PHONEPATH" | tr -d '\r'); do + if [[ $PHONEPATH = *"*" ]]; then + adb pull "${PHONEPATH%%/*}/$file" $LOCALFOLDER/ + adb shell rm "${PHONEPATH%%/*}/$file" + else + adb pull "$PHONEPATH/$file" $LOCALFOLDER/ + adb shell rm "$PHONEPATH/$file" + fi +done diff --git a/visualize.m b/visualize.m index da5fc19..8179cdc 100644 --- a/visualize.m +++ b/visualize.m @@ -1,4 +1,4 @@ -rawdata = readtable('./example/20190505_170223_sig/98fc11691fc5.csv'); +rawdata = readtable('./example/20190505_170223_sig/98ded0624482.csv'); data = table2array(rawdata(:, [1,2,4,5,9])); unique_types = unique(data(:,5));