【问题标题】:RFID f2f proximity analysis for social network社交网络的 RFID f2f 接近度分析
【发布时间】: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


    【解决方案1】:

    创建cumulative_time应该很容易,所以我不打算在这里写。

    total_contact_time 然而,很难。 tag_me 似乎总是一样的,所以我们可以忽略它。假设您已将每一行读取为 JSON 并将它们转换为 Python dict,并将其存储在变量 data 指向的类似 list 的对象中:

    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 (如果 data["time_local_s"] > now.
    • @StefanBloemheuvel 你做了一些非常奇怪的事情。你能发布其中一个条目的repr 吗?
    • 我已将文件修改为 csv 文件,以方便我使用。代表是什么意思?
    • @StefanBloemheuvel CSV 文件可能更难处理。 repr 我的意思是在对象上运行 repr 函数并发布输出。
    • 我已更新代码以解决您遇到的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多