另一个程序可以连接neo4j,但就是这个程序有问题from py2neo import Graph, Node, Relationship
# SCADA数据
scada_data = [
["时间戳", "传感器1", "传感器2", "传感器3", "传感器4", "传感器5", "传感器6", "传感器7", "传感器8"],
["2023-07-11 09:00:00", 25.5, 50.2, 10.8, 75.3, 62.1, 30.6, 40.9, 55.7],
["2023-07-11 09:05:00", 25.6, 50.3, 10.9, 75.2, 62.2, 30.7, 40.8, 55.6],
["2023-07-11 09:10:00", 25.7, 50.4, 11.0, 75.1, 62.3, 30.8, 40.7, 55.5],
["2023-07-11 09:15:00", 25.8, 50.5, 11.1, 75.0, 62.4, 30.9, 40.6, 55.4]
]
# 创建与Neo4j数据库的连接
graph = Graph("bolt://localhost:7687", auth=("username", "password"))
# 清空数据库中的节点和关系(可选)
graph.delete_all()
# 创建实体节点
sensors = []
timestamps = []
for i in range(1, 9):
sensor_node = Node("Sensor", id=f"sensor{i}", name=f"传感器{i}")
graph.create(sensor_node)
sensors.append(sensor_node)
for i in range(1, 5):
timestamp_node = Node("Timestamp", id=f"timestamp{i}", value=f"2023-07-11 09:{i * 5:02d}:00")
graph.create(timestamp_node)
timestamps.append(timestamp_node)
# 创建传感器读数关系
for i, timestamp_node in enumerate(timestamps):
for j, sensor_node in enumerate(sensors):
reading_relation = Relationship(sensor_node, "SensorReading", timestamp_node, value=scada_data[i + 1][j + 1])
graph.create(reading_relation)
print("数据导入完成。")
最新发布