195 lines
6.4 KiB
C++
195 lines
6.4 KiB
C++
#pragma once
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctime>
|
|
#include <list>
|
|
#include <map>
|
|
|
|
#include "cjson.h"
|
|
#include "PQDIF_classes.h"
|
|
#include "pqdif_ph.h"
|
|
|
|
typedef double DATE;
|
|
|
|
class CPQDIF_Element;
|
|
class CPQDIF_E_Collection;
|
|
class CPQDIF_E_Scalar;
|
|
class CPQDIF_E_Vector;
|
|
class CPQDIF_R_Observation;
|
|
class CPQDIF_R_DataSource;
|
|
class CPQDIF_R_Container;
|
|
class CPQDIF_R_Settings;
|
|
class CPQDIF_PC_FlatFile;
|
|
|
|
// ============================
|
|
// PQDIF 通道扩展信息
|
|
// 作用:把标准里的通道级标签暴露给上层
|
|
// ============================
|
|
struct PqdifChannelInfoEx
|
|
{
|
|
std::string name; // 原始 tagChannelName
|
|
long countSeries = 0; // 通道下的 series 数量
|
|
long phaseId = -1; // tagPhaseID
|
|
GUID quantityTypeId{}; // tagQuantityTypeID
|
|
long quantityMeasuredId = -1; // tagQuantityMeasuredID
|
|
};
|
|
|
|
// ============================
|
|
// PQDIF 系列扩展信息
|
|
// 作用:把标准里的系列级标签暴露给上层
|
|
// ============================
|
|
struct PqdifSeriesInfoEx
|
|
{
|
|
long quantityUnitsId = -1; // tagQuantityUnitsID
|
|
GUID quantityCharacteristicId{}; // tagQuantityCharacteristicID
|
|
GUID valueTypeId{}; // tagValueTypeID
|
|
|
|
long seriesBaseType = -1; // series 底层类型(辅助信息)
|
|
double scale = 1.0; // 缩放系数
|
|
double offset = 0.0; // 偏移
|
|
};
|
|
|
|
class CPQDIF
|
|
{
|
|
public:
|
|
CPQDIF();
|
|
~CPQDIF();
|
|
public:
|
|
void GetTime(DATE dt, time_t* tm);
|
|
void put_FlatFileName(string strFileName);
|
|
bool Read();
|
|
bool Close();
|
|
bool New();
|
|
long RecordGetCount();
|
|
bool RecordGetInfo
|
|
(
|
|
long index,
|
|
GUID* tagRecordType,
|
|
string& nameRecordType
|
|
);
|
|
bool RecordRequestRecord(long index, long* pRecord);
|
|
bool RecordRequestObservation(long index, long* pRecordObserv);
|
|
bool ObservationGetInfo(long pRecordObserv, DATE& timeStart, string& name, long& countChannels);
|
|
bool ObservationGetTriggerInfo(long pRecordObserv, long* idTriggerMethod, DATE* timeTriggered);
|
|
bool ObservationGetChannelInfo(long pRecordObserv, long idxChannel, string& name, long* countSeries);
|
|
bool ObservationGetSeriesInfo3(long pRecordObserv, long idxChannel, long idxSeries, long* idQuantityUnits, GUID* idQuantityCharacteristic, GUID* idValueType);
|
|
bool ObservationGetSeriesData(long pRecordObserv, long idxChannel, long idxSeries, double** values, long* varCount);
|
|
bool ObservationGetChannelFreq(long pRecObs, long idxChannel, double* freq);
|
|
bool ObservationGetChannelGroupID(long pRecObs, long idxChannel, int* GroupID);
|
|
bool ObservationGetSeriesPhasicType(long pRecordObserv, long idxChannel, long idxSeries, long* valuetypes);
|
|
bool ObservationGetSeriesScale(long pRecObs, long idxChannel, long idxSeries, double* scale, double* offset);
|
|
bool RecordReleaseObservation(long pRecordObserv);
|
|
|
|
// 获取 Observation 下某个通道的扩展标签信息
|
|
bool ObservationGetChannelInfoEx(long pRecordObserv, long idxChannel, PqdifChannelInfoEx* out);
|
|
|
|
// 获取 Observation 下某个 series 的扩展标签信息
|
|
bool ObservationGetSeriesInfoEx(long pRecordObserv, long idxChannel, long idxSeries, PqdifSeriesInfoEx* out);
|
|
// Internal
|
|
protected:
|
|
CPQDIF_Element* ValidateElement(long pElement);
|
|
CPQDIF_E_Collection* ValidateCollection(long pElement);
|
|
CPQDIF_E_Scalar* ValidateScalar(long pElement);
|
|
CPQDIF_E_Vector* ValidateVector(long pElement);
|
|
CPQDIF_R_Observation* ValidateObservation(long pRecObserv);
|
|
CPQDIF_R_DataSource* ValidateDataSource(long pRecDS);
|
|
CPQDIF_R_Settings* ValidateSettings(long pRecSettings);
|
|
CPQDIF_R_Container* ValidateContainer(long pRecCon);
|
|
bool SetDateFromTimeStamp(DATE& date, const TIMESTAMPPQDIF& ts);
|
|
// Member data
|
|
private:
|
|
CPQDIF_PC_FlatFile* m_percont; // Persistence controller
|
|
|
|
};
|
|
|
|
class CItem //相别下各个属性结构
|
|
{
|
|
public:
|
|
string KeyName;//入库数据名
|
|
string DateName;//解析指标名
|
|
string Type;//属性类型 MAX MIN AVG CP95 NULL
|
|
|
|
CItem(const string& kn, const string& dn, const string& tp)
|
|
: KeyName(kn), DateName(dn), Type(tp) {}
|
|
};
|
|
|
|
class CSeq //表下各个分相结构
|
|
{
|
|
public:
|
|
string seq;//相别名
|
|
string telemetryType;//分相标志
|
|
string jsonname;//josn key名称
|
|
list<CItem*> DateItemList;//属性列表
|
|
|
|
CSeq(const string& s, const string& tt, const string& tp)
|
|
: seq(s), telemetryType(tt), jsonname(tp) {}
|
|
// 析构函数
|
|
~CSeq() {
|
|
// 释放DateItemList中的CItem对象
|
|
for (std::list<CItem*>::iterator it = DateItemList.begin(); it != DateItemList.end(); ++it) {
|
|
delete* it; // 释放内存
|
|
}
|
|
DateItemList.clear(); // 清除列表中的指针
|
|
}
|
|
};
|
|
|
|
class CTable //目标入库表结构
|
|
{
|
|
public:
|
|
string TableName;//入库表名
|
|
list<CSeq*> DateSeqList;//相别列表
|
|
|
|
CTable(const string& tn)
|
|
: TableName(tn) {}
|
|
// 析构函数
|
|
~CTable() {
|
|
// 释放DateSeqList中的CSeq对象
|
|
for (std::list<CSeq*>::iterator it = DateSeqList.begin(); it != DateSeqList.end(); ++it) {
|
|
delete* it; // 释放内存
|
|
}
|
|
DateSeqList.clear(); // 清除列表中的指针
|
|
}
|
|
};
|
|
|
|
class CDeal //数据处理类
|
|
{
|
|
public:
|
|
void clear();
|
|
void CheckDataTableList();//测试DataTableList队列数据
|
|
void ResJsonCfg(char* json);//解析传入json结构的配置信息
|
|
char* AssJson(char* Id);//组装json字符串
|
|
cJSON* cJSON_GetObjectItemCaseSensitive(cJSON* object, const char* string);//json结构解析 遍历取值
|
|
bool ExtractNumbersBetweenPercent(const std::string& str, int& start, int& end);
|
|
std::string convertToDateOnly(const std::string& dateTime);
|
|
int getCurrentGroup(const std::time_t& currentTime, int min);
|
|
std::time_t stringToTimeT(const std::string& dateTime);
|
|
|
|
std::list<CTable*> DataTableList;//入库表格配置信息队列
|
|
std::string MonitorId;//待入库ID
|
|
std::string dataDate;//待入库时标
|
|
std::string dataDatePT;//待入库时标 闪变 波动
|
|
|
|
int ShortFlag = 0;//短闪启动指标
|
|
int LongFlag = 0;//长闪启动指标
|
|
int FluFlag = 0;//波动启动指标
|
|
int aggCydeMin = 3;//待入库周期 默认为3
|
|
int fluCydeMin = 10;//波动周期 默认为10
|
|
int aggCycleMinShort = 10;//短闪周期 默认为10
|
|
int aggCycleMinLong = 120;//长闪周期 默认为120
|
|
std::map< std::string, std::list<double> > AvgData;//解析文件数据存储队列 avg类型数据
|
|
std::map< std::string, std::list<double> > MaxData;//解析文件数据存储队列 Max类型数据
|
|
std::map< std::string, std::list<double> > MinData;//解析文件数据存储队列 Min类型数据
|
|
std::map< std::string, std::list<double> > CP95Data;//解析文件数据存储队列 CP95类型数据
|
|
std::map< std::string, std::list<double> > ValData;//解析文件数据存储队列 value类型数据
|
|
std::map< std::string, std::list<double> > TimeData;//解析文件数据 周期时标队列
|
|
std::map< std::string, std::string > DateData;//解析文件数据 起始时间队列
|
|
std::map< std::string, int > aggCydeMinList;
|
|
};
|
|
|
|
void testjson();
|
|
|
|
|
|
|