Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
data_fusion_p1/1) split_location.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
63 lines (57 sloc)
2.27 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#"" latitude longitude senseStartTimeMillis uid phq9 accuracy depressed period | |
import os | |
interval = 14 #quids interval, change to 14 if phq9 | |
# map uid to os_ | |
map_uid_os_ = dict() | |
for l in open('mapping.csv').readlines(): | |
if len(l)>0: | |
ll = l.split(',') | |
if len(ll)>1: | |
uid = ll[0] | |
os_ = ll[2][:-1] | |
map_uid_os_[uid]=os_ | |
# map uid to phq9 | |
map_uid_phq9 = dict() | |
for l in open('phq9_convert.csv').readlines(): | |
if len(l)>0: | |
ll = l.split(',') | |
if len(ll)>3: | |
uid = ll[0] | |
ts = ll[1] | |
phq9 = ll[2] | |
depressed = ll[3][:-1] | |
if uid not in map_uid_phq9.keys(): | |
map_uid_phq9[uid] = [] | |
map_uid_phq9[uid].append([ts,phq9,depressed]) | |
#print(map_uid_phq9) | |
firstline=',latitude,longitude,senseStartTimeMillis,uid,phq9,accuracy,depressed,period\n' | |
owdict = dict() | |
with open('location.csv') as file: | |
for line in file: | |
ll = line.split(',') | |
if len(ll)>9: | |
if ll[12] == 'gps' or ll[12] == 'GPS': | |
uid = ll[1] | |
ts = ll[4] # sensing time | |
lat = ll[10] # latitude | |
long = ll[11] | |
acc = ll[13] # accuracy | |
if uid in map_uid_os_.keys(): | |
os_ = map_uid_os_[uid] | |
if not os.path.exists(os_): | |
os.makedirs(os_) | |
if uid in map_uid_phq9.keys(): | |
phq9list = map_uid_phq9[uid] | |
for qts,phq9,depressed in phq9list: | |
#print(int(qts)-int(ts)) | |
if int(qts)-int(ts)>0 and int(qts)-int(ts)<interval*86400*1000: | |
fn = os_+'\\'+uid+'_Location.csv' | |
if fn not in owdict.keys(): | |
ow = open(fn,'a+') | |
owdict[fn]=ow | |
ow.write(firstline) | |
else: | |
ow = owdict[fn] | |
ow.write(','.join(['',lat,long,ts,uid,phq9,acc,depressed,qts])+'\n') | |
for k in owdict.keys(): | |
owdict[k].close() |