ProcessDB实时/时序数据库——Python查询历史统计数据

目录

前言

一、历史统计数据字段介绍

二、点名查询历史统计数据

三、点ID查询历史统计数据


前言

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值