RFID f2f社交网络的邻近度分析

时间:2018-04-15 13:04:57

标签: python datetime networking rfid proximity

我正在寻找一种在我的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

1 个答案:

答案 0 :(得分:0)

创建cumulative_time应该很简单,所以我不打算在这里写一下。

然而,

total_contact_time很难。 tag_me似乎总是一样的,所以我们可以忽略它。假设您已将每行读作JSON并将其转换为Python dict,并将其存储在list类似的对象中,变量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

我还没有完成它,因为我没时间工作了。不过,这应该足以让你入门。

相关问题