如何获取时间序列数据库的最新记录?
我有一个只有三列的时间序列数据库。第一列用于 id,第二列用于时间戳,第三列用于 iOT 的输出。 我正在我的 Ubuntu 机器上运行 griddb python 客户端。我需要从数据库中获取最新的记录。最新记录应该是在查询运行当天刚刚添加的记录。 无论是 SQL 查询还是函数,我只需要一种方法让它工作。 以下是我在 GridDB 容器中存储时间序列数据库的方式以及数据库的概述。
python
##...
factory = griddb.StoreFactory.get_instance()
## Initializing the container
try:
gridstore = factory.get_store(host="127.0.0.1",
port=59111,
cluster_name="cluster_one",
username="admin",
password="")
conInfo = griddb.ContainerInfo("iOT_Project",
[["id", griddb.Type.INTEGER],
["time_stamp", griddb.Type.TIMESTAMP],
["output", griddb.Type.FLOAT]],
griddb.ContainerType.COLLECTION, True)
container = gridstore.put_container(conInfo)
## Reading the database with pandas
data = pd.read_csv("database.csv")
## Adding the database to the container
for i in range(len(data)):
ret = container.put(data.iloc[i, :])
print("Data added successfully")
except Exception as e:
print("Error: ", e)
iot_database
id | time_stamp | 输出 |
---|---|---|
232 | 01/01/2019 11:20 | 85309.52 |
233 | 02/01/2019 12:52 | 6398.54 |
234 | 03/01/2019 23:45 | 97583.63 |
235 | 04/01/2019 22:21 | 86533.11 |
236 | 2019年5月1日 13:42 | 12421.35 |
I have a time series database with just three columns. The first column is for the id, the second is for the time stamps, and the third column is for the output of the iOT.
I am running the griddb python client on my Ubuntu machine. I need to get the most recent records from the database. The most recent records should be the ones just added on the day the query is run.
Whether it’s an SQL query or a function, I just need a way to make it work.
Here is how I stored the timeseries database in my GridDB container and an overview of the database.
python
##...
factory = griddb.StoreFactory.get_instance()
## Initializing the container
try:
gridstore = factory.get_store(host="127.0.0.1",
port=59111,
cluster_name="cluster_one",
username="admin",
password="")
conInfo = griddb.ContainerInfo("iOT_Project",
[["id", griddb.Type.INTEGER],
["time_stamp", griddb.Type.TIMESTAMP],
["output", griddb.Type.FLOAT]],
griddb.ContainerType.COLLECTION, True)
container = gridstore.put_container(conInfo)
## Reading the database with pandas
data = pd.read_csv("database.csv")
## Adding the database to the container
for i in range(len(data)):
ret = container.put(data.iloc[i, :])
print("Data added successfully")
except Exception as e:
print("Error: ", e)
iot_database
id | time_stamp | output |
---|---|---|
232 | 01/01/2019 11:20 | 85309.52 |
233 | 02/01/2019 12:52 | 6398.54 |
234 | 03/01/2019 23:45 | 97583.63 |
235 | 04/01/2019 22:21 | 86533.11 |
236 | 05/01/2019 13:42 | 12421.35 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论