【发布时间】:2018-04-15 13:04:57
【问题描述】:
我正在寻找一种在我的 40 个 rfid 标签数据集中快速创建时间间隔/偏移量的方法。芯片只在安装电池的那一刻测量时间(芯片来自https://www.openbeacon.org/)。在实验中,40 人的钥匙绳上有 rfid 芯片,并记录了他们的互动(每一秒,我没有 rfid 芯片,数据集中不会创建任何事件,但计时器会继续)。
其中一个芯片的数据集的示例行如下:
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
2, "time_remote_s": 33, "rssi": -67, "angle": -90, "group": 1 }
我希望数据集看起来像这样以进行分析:
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
2, "time_remote_s": 33, "rssi": -67, "angle": -90, "group": 1,
"cumulative_time": 20:16:02, "total_contact_time" : 4 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
5, "time_remote_s": 36, "rssi": -66, "angle": -90, "group": 1,
"cumulative_time": 20:16:03, "total_contact_time" : 4 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
6, "time_remote_s": 37, "rssi": -63, "angle": -90, "group": 1,
"cumulative_time": 20:16:04, "total_contact_time" : 4 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
7, "time_remote_s": 38, "rssi": -57, "angle": -36, "group": 1,
"cumulative_time": 20:16:05, "total_contact_time" : 4 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s":
8, "time_remote_s": 39, "rssi": -53, "angle": -36, "group": 1,
"cumulative_time": 20:16:06, "total_contact_time" : 4 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5628", "time_local_s":
9, "time_remote_s": 40, "rssi": -53, "angle": -90, "group": 1,
"cumulative_time": 20:16:07, "total_contact_time" : 6 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5628", "time_local_s":
9, "time_remote_s": 40, "rssi": -53, "angle": -90, "group": 1,
"cumulative_time": 20:16:07, "total_contact_time" : 6 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5628", "time_local_s":
10, "time_remote_s": 41, "rssi": -54, "angle": -90, "group": 1,
"cumulative_time": 20:16:08, "total_contact_time" : 6 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5628", "time_local_s":
11, "time_remote_s": 42, "rssi": -53, "angle": -90, "group": 1,
"cumulative_time": 20:16:09, "total_contact_time" : 6 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5628", "time_local_s":
15, "time_remote_s": 44, "rssi": -53, "angle": -90, "group": 1,
"cumulative_time": 20:16:13, "total_contact_time" : 6 }
{ "tag_me": "0x6979EF0C", "tag_them": "0x597E5629", "time_local_s":
16, "time_remote_s": 88, "rssi": -53, "angle": -90, "group": 1,
"cumulative_time": 20:16:14, "total_contact_time" : 1 }
文件存储为 .json 文件。标签的名称是“tag_me”,“tag_them”是“tag_me”偶然发现的 rfid 标签。通常,芯片不会将“cumulative_time”和“total_contact_time”存储在数据集中,但我手动将它们添加到 excel 中以显示我希望得到的最终结果。
我的实验在 20:16:00 开始,所以“time_local_s”是 20:16:00 + 2 = 20:16:02。 “cumulative_time”应该将“time_local_s”中的数字添加到实验的开始时间,“total_contact_time”变量应该存储接触持续了多长时间(例如,与前两个芯片的接触持续时间为 20:16:02直到 20:16:06,所以还有 4 秒。
有人知道如何实现这个结果吗?我希望在 python 中找到可以帮助我的包(也许是 pandas,但我没有经验),因为我认为 excel 并不是真正适合它的工具(每个芯片几乎 9000 次交互,我有 40 个) .
我现在发现了这个,但这对我没有多大帮助:
data = []
with open('timemerger.csv') as f:
for line in f:
data.append(line)
print(data[1])
past_interactions = []
interactions = []
now = -1
new_data = []
for line in enumerate(data):
if line["time_local_s"] > now:
for tag_them, indices in past_interactions:
if tag_them not in data:
# Update new_data and remove from past_interactions
# (Can't remove whilst iterating, so record index;
# remove later.)
interactions.append(entry["tag_them"])
# Add to past_interactions
# Unconditionally update new_data
print(' ')
print(new_data[1:4])
print(interactions)
---------- 编辑
我已将文件更改为 csv 格式,以方便我使用(我以前从未使用过 json)。现在看起来像这样:
tag_me,tag_them,time_local_s
0x597E5627,0x3C992634,1356
0x597E5627,0x3C992634,1360
0x597E5627,0x3C992634,1361
0x597E5627,0x3C992634,1362
0x597E5627,0x3C992634,1363
0x597E5627,0x7DA8FFB0,1364
0x597E5627,0x3C992634,1365
0x597E5627,0x3C992634,1365
0x597E5627,0x3C992634,1366
期望的结果:
tag_me,tag_them,time_local_s,total_time
0x597E5627,0x3C992634,1356,7
0x597E5627,0x3C992634,1360,7
0x597E5627,0x3C992634,1361,7
0x597E5627,0x3C992634,1362,7
0x597E5627,0x3C992634,1363,7
0x597E5627,0x7DA8FFB0,1364,1
0x597E5627,0x3C992634,1365,1
0x597E5627,0x3C992634,1365,1
0x597E5627,0x3C992634,1366,1
【问题讨论】:
标签: python datetime networking rfid proximity