speed up the processing

This commit is contained in:
HappyZ 2019-05-15 11:49:19 -05:00
parent d498276df8
commit 06f443b30c
3 changed files with 33 additions and 24 deletions

View File

@ -14,8 +14,7 @@ def extract_dev_from_combined(fp, minimalCounts=100, cleanup=True):
''' '''
extract each device data from combined file `fp` extract each device data from combined file `fp`
''' '''
files = [] files = {}
counters = []
folderpath, ext = os.path.splitext(fp) folderpath, ext = os.path.splitext(fp)
try: try:
@ -32,30 +31,24 @@ def extract_dev_from_combined(fp, minimalCounts=100, cleanup=True):
tmp = line.rstrip().split(",") tmp = line.rstrip().split(",")
addr = tmp[2].replace(":", "") addr = tmp[2].replace(":", "")
if addr not in files: if addr not in files:
files.append(addr) files[addr] = []
counters.append(1) files[addr].append(",".join(tmp[:2] + tmp[3:]))
else:
counters[files.index(addr)] += 1
for i in range(len(counters)-1, -1, -1): for addr in list(files.keys()):
if counters[i] < minimalCounts: if len(files[addr]) < minimalCounts:
counters.pop(i) del files[addr]
files.pop(i)
title = lines[0].rstrip().split(",") title = lines[0].rstrip().split(",")
filepaths = ["{}/{}.csv".format(folderpath, file) for file in files] headline = ",".join(title[:2] + title[3:]) + "\n"
for filepath in filepaths: filepaths = []
with open(filepath, "w") as f:
f.write(",".join(title[:2] + title[3:]) + "\n")
for line in lines[1:]: for addr in files.keys():
tmp = line.rstrip().split(",") filepath = "{}/{}.csv".format(folderpath, addr)
addr = tmp[2].replace(":", "") filepaths.append(filepath)
if addr not in files: with open(filepath, "w") as f:
continue f.write(headline)
filepath = filepaths[files.index(addr)] for line in files[addr]:
with open(filepath, "a+") as f: f.write("{}\n".format(line))
f.write(",".join(tmp[:2] + tmp[3:]) + "\n")
if len(files) > 0 and cleanup: if len(files) > 0 and cleanup:
os.remove(fp) os.remove(fp)

16
pull_data_from_phone.sh Executable file
View File

@ -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

View File

@ -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])); data = table2array(rawdata(:, [1,2,4,5,9]));
unique_types = unique(data(:,5)); unique_types = unique(data(:,5));