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_wifi.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (48 sloc)
1.58 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 | |
# 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_ | |
owdict = dict() | |
# Userid,BSSID:,State,senseStartTimeMillis: | |
title = dict() | |
with open('wifi.csv', encoding='utf-8', errors='ignore') as file: | |
for line in file: | |
#print(line) | |
#break | |
ll = line.split(',') | |
if len(ll)>9: | |
uid = ll[1] | |
ts = ll[4] | |
state = ll[10] | |
bssid = ll[13] | |
if state =='Connected': | |
state = '1' | |
else: | |
state = '0' | |
if uid in map_uid_os_.keys(): | |
os_ = map_uid_os_[uid] | |
if not os.path.exists(os_): | |
os.makedirs(os_) | |
firstline='Userid,BSSID:,State,senseStartTimeMillis:\n' | |
fn = os_+'_wifiraw\\'+uid+'.csv' | |
if not os.path.exists(os_+'_wifiraw\\'): | |
os.makedirs(os_+'_wifiraw\\') | |
if fn not in owdict.keys(): | |
ow = open(fn,'a+') | |
owdict[fn]=ow | |
else: | |
ow = owdict[fn] | |
if fn not in title.keys(): | |
title[fn]=1 | |
ow.write(firstline) | |
ow.write(','.join([uid,bssid,state,ts])+'\n') | |
ow.flush() | |
for k in owdict.keys(): | |
owdict[k].close() |