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

目录

前言

一、历史时序数据字段介绍

二、点名查询历史时序数据

三、点ID查询历史时序数据


前言

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值