Python 面向社会网络的RFID-f2f邻近性分析

Python 面向社会网络的RFID-f2f邻近性分析,python,datetime,networking,rfid,proximity,Python,Datetime,Networking,Rfid,Proximity,我正在寻找一种在我的40个rfid标签数据集中快速创建时间间隔/偏移的方法。芯片仅测量电池安装时的时间(芯片来自)。在实验中,40个人在键盘上安装了rfid芯片,并记录了他们之间的互动(每秒,我都不知道rfid芯片在周围,数据集中不会创建任何事件,但计时器将继续) 来自其中一个芯片的数据集的示例行如下所示: { "tag_me": "0x6979EF0C", "tag_them": "0x597E5627", "time_local_s": 2, "time_remote_s":

我正在寻找一种在我的40个rfid标签数据集中快速创建时间间隔/偏移的方法。芯片仅测量电池安装时的时间(芯片来自)。在实验中,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标签。通常情况下,“累计时间”和“总联系时间”不会通过芯片存储在数据集中,但我在excel中手动添加了它们,以显示我希望的最终结果

我的实验在20:16:00开始,所以“时间”是20:16:00+2=20:16:02。“累计_时间”应将“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

创建累积时间应该很容易,所以我不打算在这里写

total\u contact\u time
,然而,这很难。
tag\u me
似乎总是一样的,所以我们可以忽略这一点。假设您已将每一行读取为JSON,并将其转换为Python
dict
,存储在变量
data
指向的类似于
列表的对象中:

past_interactions = []
interactions = []
now = -1
new_data = [dict(entry) for entry in data]
for index, entry in enumerate(data):
    if entry["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

我还没有完成它,因为我没有时间来做这件事。不过这应该足够让你开始了。

谢谢你的回复!这看起来很好,但我得到的错误是列表索引应该是整数或切片,而不是第14行的str(如果数据[“time\u local\s”]>现在。@StefanBloemheuvel你做了一件非常奇怪的事情。你能发布其中一个条目的
repr
吗?我已经将该文件修改为csv文件,以使其对我来说更简单。使用repr是什么意思?@StefanBloemheuvel csv文件可能更难处理。通过
repr
我的意思是运行
repr
功能我已经更新了代码来修复您遇到的问题。