目录
前言
ProcessDB实时/时序数据库支持Python语言开发,本文将针对Python操作ProcessDB库的历史统计数据的相关操作进行介绍
一、历史统计数据字段介绍
字段 | 注释 |
tmTag | 历史数据时间 |
nQuality | 质量是否完好 |
dSum | 累计值 |
dMax | 最大值 |
dMin | 最小值 |
dFirst | 第一值 |
dLast | 最后值 |
tmFirst | 第一值时间 |
tmLast | 最后时间 |
nUltraLimitCount | 超限制数 |
nUltraLimitDuration | 超限制时间 |
dOutput | 产量 |
dFlow | 流量值 |
nCount | 统计数据数量 |
Duration | 持续时间 |
tmMin | 最小值时间 |
tmMax | 最大值时间 |
二、点名查询历史统计数据
示例代码:
# 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 = '127.0.0.1'
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-21 00:00:00'
end_time = '2022-10-21 23:59:59'
interval = 3600
#点名查询统计历史数据
for n in range(len(pointNameList)):
count, errCode, resultSet = processdbDriver.query_stat_his_data_by_pointName(start_time, end_time, pointNameList[n], interval)
if errCode == 0:
if count != 0 and count != 'null':
for j in range(count):
statHisData = processdbDriver.get_stat_his_data(j, resultSet)
print('query_stat_his_data_by_pointName succeed.')
print(' Stat_his_data-pointName:', pointNameList[n])
print(' Stat_his_data-tmTag:', statHisData.tmTag)
print(' Stat_his_data-Quality:', statHisData.nQuality)
print(' Stat_his_data-Sum:', statHisData.dSum)
print(' Stat_his_data-Max:', statHisData.dMax)
print(' Stat_his_data-Min:', statHisData.dMin)
print(' Stat_his_data-Count:', statHisData.nCount)
print(' Stat_his_data-Duration:', statHisData.nDuration)
else:
print('pointId:', pointNameList[n], ',','no statistical history data')
else:
print('query_stat_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 = '127.0.0.1'
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-21 00:00:00'
end_time = '2022-10-21 23:59:59'
interval = 3600
#点id查询统计历史数据
for n in range(len(pointIdList)):
count, errCode, resultSet = processdbDriver.query_stat_his_data_by_pointId(start_time, end_time, pointIdList[n], interval)
if errCode == 0:
if count != 0 and count != 'null':
for j in range(count):
statHisData = processdbDriver.get_stat_his_data(j, resultSet)
print('query_stat_his_data_by_pointId succeed.')
print(' Stat_his_data-pointId:', pointIdList[n])
print(' Stat_his_data-tmTag:', statHisData.tmTag)
print(' Stat_his_data-Quality:', statHisData.nQuality)
print(' Stat_his_data-Sum:', statHisData.dSum)
print(' Stat_his_data-Max:', statHisData.dMax)
print(' Stat_his_data-Min:', statHisData.dMin)
print(' Stat_his_data-Count:', statHisData.nCount)
print(' Stat_his_data-Duration:', statHisData.nDuration)
else:
print('pointId:', pointIdList[n], ',','no statistical history data')
else:
print('query_stat_his_data_by_pointId failed, errorCode: ', errCode)