目录
前言
ProcessDB实时/时序数据库支持Python语言开发,本文将针对Python操作ProcessDB库的历史时序数据的相关操作进行介绍
一、历史时序数据字段介绍
字段 | 注释 |
id | 数据点id |
name | 数据点名 |
nvalue | 历史采样数据值 |
nTagType | 数据类型 |
nQuality | 数据质量 |
nMilliSecond | 数据时间(毫秒) |
nSecond | 数据时间(秒) |
二、点名查询历史时序数据
示例代码:
# coding:utf8
import ProcessDBDriver as processdbDriver
import numpy as np
# 点的数据类型
# float32--0 digital--1 bBool--2 uInt8--3 Int8--4 uInt16--5 Int16--6 nuInt32--7 nInt32--8 nuInt64--9 nInt64--10 fFloat64--11 nTime--12
pointNameList = [
'PUBLIC.SYS.PDB_OS_CPU_USAGE', 'PUBLIC.SAMPLE.SAMPLE_DIGITAL', 'PUBLIC.SAMPLE.SAMPLE_BOOL','PUBLIC.SAMPLE.SAMPLE_UINT8',\
'PUBLIC.SAMPLE.SAMPLE_INT8', 'PUBLIC.SAMPLE.SAMPLE_UINT16','PUBLIC.SAMPLE.SAMPLE_INT16', 'PUBLIC.SAMPLE.SAMPLE_UINT32','PUBLIC.SAMPLE.SAMPLE_INT32',\
'PUBLIC.SAMPLE.SAMPLE_UINT64', 'PUBLIC.SAMPLE.SAMPLE_INT64','PUBLIC.SAMPLE.SAMPLE_FLOAT64','PUBLIC.SAMPLE.SAMPLE_TIME'
]
#连接
connectName = '117.78.33.41'
port = 8399
processdbDriver.connect(connectName, port)
#登录
userName = 'root'
password = 'root'
wErrCode = processdbDriver.login(userName, password)
#登录成功
if wErrCode != 0:
print('login failed. errorCode: ', wErrCode)
else:
start_time = '2022-10-27 00:00:00'
end_time = '2022-10-27 23:59:59'
filterLow = 11
filterHigh = 21
step = 0
#点名查询历史时序数据
for m in range(len(pointNameList)):
count, errCode, resultSet = processdbDriver.query_sample_his_data_by_pointName(start_time, end_time, pointNameList[m],step, 0,0, filterLow, filterHigh,0,0,0,0,0,0)
if errCode == 0:
if count != 0 and count != 'null':
for i in range(count):
historyData = processdbDriver.get_sample_his_data(i, resultSet)
print('query_sample_his_data_by_pointName succeed.')
print(' His_sample_data-pointName:',pointNameList[m])
print(' His_sample_data-Second:',historyData.nSecond) #时间戳
print(' His_sample_data-MilliSecond:',historyData.nMilliSecond)
print(' His_sample_data-Quality:',historyData.nQuality) # 0:good 1:bad
print(' His_sample_data-TagType:',historyData.nTagType) # 数据类型:0 float32
print(' His_sample_data-value:',historyData.nValue)
else:
print('pointName:', pointNameList[m], ',','no sampling history data.')
else:
print('query_sample_his_data_by_pointName failed, errorCode: ', errCode)
三、点ID查询历史时序数据
示例代码:
# coding:utf8
import ProcessDBDriver as processdbDriver
import numpy as np
# 点的数据类型
# float32--0 digital--1 bBool--2 uInt8--3 Int8--4 uInt16--5 Int16--6 nuInt32--7 nInt32--8 nuInt64--9 nInt64--10 fFloat64--11 nTime--12
pointIdList = [1001000001, 1001000101, 1001000102, 1001000103, 1001000104, 1001000105, 1001000106, 1001000107, 1001000108, 1001000109, 1001000110, 1001000111, 1001000112]
#连接
connectName = '117.78.33.41'
port = 8399
processdbDriver.connect(connectName, port)
#登录
userName = 'root'
password = 'root'
wErrCode = processdbDriver.login(userName, password)
#登录成功
if wErrCode != 0:
print('login failed. errorCode: ', wErrCode)
else:
start_time = '2022-10-27 00:00:00'
end_time = '2022-10-27 23:59:59'
filterLow = 11
filterHigh = 21
step = 0
#点id查询历史时序数据
for m in range(len(pointIdList)):
count, errCode, resultSet = processdbDriver.query_sample_his_data_by_pointId(start_time, end_time, pointIdList[m],step, 0,0, filterLow, filterHigh,0,0,0,0,0,0)
if errCode == 0:
if count != 0 and count != 'null':
for i in range(count):
historyData = processdbDriver.get_sample_his_data(i, resultSet)
print('query_sample_his_data_by_pointId succeed.')
print(' His_sample_data-pointId:',pointIdList[m])
print(' His_sample_data-Second:',historyData.nSecond) #时间戳
print(' His_sample_data-MilliSecond:',historyData.nMilliSecond)
print(' His_sample_data-Quality:',historyData.nQuality) # 0:good 1:bad
print(' His_sample_data-TagType:',historyData.nTagType) # 数据类型:0 float32
print(' His_sample_data-value:',historyData.nValue)
else:
print('pointId:', pointIdList[m], ',','no sampling history data.')
else:
print('query_sample_his_data_by_pointId failed, errorCode: ', errCode)