1 Star 0 Fork 0

zhoub86/presence_detection_cnn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_date_conf.py 3.81 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
import os
import json
def parse_test_days(direc_prefix, total_days):
'''
Description:
generate a dictionary that stores the configurations of each day's collected data
by parsing readme.txt
Input:
direc_prefix (str):
folder directory where all the data is stored
total_days (int):
total number of experimental days
Output:
return day_conf
day_conf (dict):
key (str) -- 'day'+str(index) (index starts from 1 to total_days)
value (dict)-- test_conf (dictionary)
test_conf (dict):
key (str) -- "location"
value (str) -- where the experiment was conducted
key (str) -- 'motion'
value (int) -- total number of motion tests conducted
key (str) -- 'empty'
value (int) -- total number of tests conducted when there is nobody inside the lab
key (str) -- 'mixed'
value (int) -- total number of mixed runs
key (str) -- 'mixed_truth'
value (list) -- each entry of the list is also a list that
contains the ground truth of this mixed run.
'''
day_conf = {}
# mapping data to label
label = {'empty': 0, 'motion': 1}
for i in range(1, total_days + 1, 1):
day_index = 'day' + str(i)
d_path = direc_prefix + day_index + '/'
with open(d_path + 'readme.txt', 'r') as f:
print('processing day {}'.format(i))
location, empty_cnt, motion_cnt, mixed_cnt, mixed_state = None, -1, -1, 0, []
for l in f:
m = l.split()
if len(m) == 0:
continue
if 'Location' in m[0]:
location = m[-1]
if 'motion' in m[0]:
motion_cnt = int(m[-1])
if 'empty' in m[0]:
empty_cnt = int(m[-1])
if 'mixed' in m[0]:
mixed_cnt += 1
idx = int(m[0][-2])
mixed_index = 'mixed' + str(idx)
status = m[1:]
mixed_state.append([])
for s in status:
if 'empty' in s:
mixed_state[-1].append(label['empty'])
elif 'motion' in s:
mixed_state[-1].append(label['motion'])
else:
print('undefined status in {}'.format(m[0]))
if location == None or empty_cnt == -1 or motion_cnt == -1:
raise Exception('invalid info {} {} {}'.format(location, empty_cnt, motion_cnt))
day_conf[day_index] = {'location': location, 'motion': motion_cnt,
'empty': empty_cnt, 'mixed': mixed_cnt, 'mixed_truth': mixed_state}
print(day_conf[day_index])
print('\n')
for k, v in day_conf[day_index].items():
if k == 'location' or k == 'mixed_truth':
continue
for j in range(1, v + 1, 1):
f_name = d_path + k + str(j) + '.data'
if not os.path.exists(f_name):
print("{} doesn't exist".format(f_name))
return day_conf
def main():
total_days = 16
data_folder = '/root/share/upload_wifi_data/'
day_conf = parse_test_days(data_folder, total_days)
to_json = json.dumps(day_conf)
# json filename
save_json_filename = 'day_conf.json'
# save day_conf to json file
with open(save_json_filename, 'w') as f:
f.write(to_json)
print('json file was saved as ' + save_json_filename)
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhoub86/presence_detection_cnn.git
git@gitee.com:zhoub86/presence_detection_cnn.git
zhoub86
presence_detection_cnn
presence_detection_cnn
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385