3.2.5 beta 3 优化统计特征值逻辑

This commit is contained in:
zhangsheng 2024-09-25 19:54:54 +08:00
parent 4dc85b8187
commit 3f541a08df
3 changed files with 55 additions and 92 deletions

BIN
Cidn-SH

Binary file not shown.

View File

@ -24,8 +24,8 @@ enum enumZigBeeTransmitStatus {
//#define Q4G_MODULE //#define Q4G_MODULE
//#define WIFI_MODULE //#define WIFI_MODULE
//#define NR5G_MEIGE //#define NR5G_MEIGE
//#define G2UL_GATEWAY #define G2UL_GATEWAY
#define IMX6UL_GATEWAY //#define IMX6UL_GATEWAY
class GlobalConfig class GlobalConfig
{ {

View File

@ -1403,27 +1403,28 @@ int SqliteDB::CalculateData()
array_t vecRet = GetDataMultiLine(T_SENSOR_INFO(TNAME)," dataNodeNo,MeasurementID,NodeWaveSend,featureInterVal,waveInterVal,ZigbeePower ",NULL); array_t vecRet = GetDataMultiLine(T_SENSOR_INFO(TNAME)," dataNodeNo,MeasurementID,NodeWaveSend,featureInterVal,waveInterVal,ZigbeePower ",NULL);
if (vecRet.size() > 0) if (vecRet.size() > 0)
{ {
LOG_INFO("Node Count = %d\n",vecRet.size());
int planCount = 0,planCountStatistic = 0,StatisticCountTotal = 0,SixCountTotal = 0,TimingCountTotal = 0,CountWaveXTotal = 0,waveInterVal = 0,featureInterVal = 0;
int CountWaveYTotal = 0 , CountWaveZTotal = 0;
for (size_t i = 0; i < vecRet.size(); i++) for (size_t i = 0; i < vecRet.size(); i++)
{ {
int planCount = 1440 / atoi(vecRet[i][4].c_str()) ; planCount = 1440 / atoi(vecRet[i][4].c_str()) ;
planCountStatistic = 1440 / atoi(vecRet[i][3].c_str()) ;
int rate = readIntValue( "config", "waveRate",(char*)GlobalConfig::Config_G.c_str()); int rate = readIntValue( "config", "waveRate",(char*)GlobalConfig::Config_G.c_str());
char tableName[50]={0x00}; char tableName[50]={0x00};
char whereCon[128]={0x00}; char whereCon[128]={0x00};
sprintf(tableName,"t_dataStatic_%s",vecRet[i][0].c_str()); sprintf(tableName,"t_dataStatic_%s",vecRet[i][0].c_str());
const char *sql = const char *sql =
" timestamp >= strftime('%s', 'now', '-1 day', 'start of day') " " timestamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') "
"AND timestamp < strftime('%s', 'now', 'start of day') "; "AND timestamp < strftime('%s', 'now', 'start of day','utc','+24 hours') ";
int StatisticCount = GetTableRows(tableName,sql); int StatisticCount = GetTableRows(tableName,sql);
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', 'start of day','utc','+24 hours') and statisticType = '1' ";
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and statisticType = '1' ";
int SixCount = GetTableRows(tableName,sql); int SixCount = GetTableRows(tableName,sql);
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and statisticType = '1' and timing = '0'"; sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', 'start of day','utc','+24 hours') and statisticType = '1' and timing = '0'";
int TimingCount = GetTableRows(tableName,sql); int TimingCount = GetTableRows(tableName,sql);
print_info("nodeWaveSend = %swaveInterVal = %s\n",vecRet[i][2].c_str(),vecRet[i][4].c_str()); print_info("nodeWaveSend = %s,waveInterVal = %s\n",vecRet[i][2].c_str(),vecRet[i][4].c_str());
if(vecRet[i][2] == "") if(vecRet[i][2] == "")
continue; continue;
vector<string> nodeWaveSend ; vector<string> nodeWaveSend ;
@ -1436,38 +1437,30 @@ int SqliteDB::CalculateData()
{ {
continue; continue;
} }
sprintf(tableName,"t_data_waveSend");
const char *sql1 =
"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc')"
" AND timeStamp < strftime('%s', 'now','-1 day', 'start of day','utc','+24 hours')";
const char *sql2 =
"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day','utc')"
" AND timeStamp < strftime('%s', 'now','-2 day', 'start of day','utc','+24 hours')";
const char *sql3 =
"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day','utc')"
" AND timeStamp < strftime('%s', 'now','-3 day', 'start of day','utc','+24 hours')";
if (nodeWaveSend[0] == "0") if (nodeWaveSend[0] == "0")
{ {
const char *sql =
"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str());
string strsql = string(sql) + string(whereCon); string strsql = string(sql1) + string(whereCon);
printf("sql = %s\n",strsql.c_str()); printf("sql = %s\n",strsql.c_str());
CountWaveX = GetTableRows(tableName,strsql.c_str()); CountWaveX = GetTableRows(tableName,strsql.c_str());
sql =
"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql2) + string(whereCon);
CountWaveX2 = GetTableRows(tableName,strsql.c_str());
//printf(whereCon,"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-X'",vecRet[i][1].c_str());
CountWaveX2 = GetTableRows(tableName,whereCon);
sql =
"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql3) + string(whereCon);
//printf(whereCon,"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-X'",vecRet[i][1].c_str()); CountWaveX3 = GetTableRows(tableName,strsql.c_str());
CountWaveX3 = GetTableRows(tableName,whereCon);
if ((CountWaveX > 0 && (CountWaveX / planCount > rate)) && (CountWaveX2 > 0 && (CountWaveX2 / planCount > rate)) && (CountWaveX3 > 0 && (CountWaveX3 / planCount > rate))) if ((CountWaveX > 0 && (CountWaveX / planCount > rate)) && (CountWaveX2 > 0 && (CountWaveX2 / planCount > rate)) && (CountWaveX3 > 0 && (CountWaveX3 / planCount > rate)))
{ {
rateX = 1; rateX = 1;
@ -1478,33 +1471,15 @@ int SqliteDB::CalculateData()
} }
if(nodeWaveSend[1] == "0"){ if(nodeWaveSend[1] == "0"){
const char *sql =
"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str());
string strsql = string(sql) + string(whereCon); string strsql = string(sql1) + string(whereCon);
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Y",vecRet[i][1].c_str());
CountWaveY = GetTableRows(tableName,strsql.c_str()); CountWaveY = GetTableRows(tableName,strsql.c_str());
sql =
"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql2) + string(whereCon);
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Y",vecRet[i][1].c_str()); CountWaveY2 = GetTableRows(tableName,strsql.c_str());
CountWaveY2 = GetTableRows(tableName,whereCon);
sql =
"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql3) + string(whereCon);
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Y",vecRet[i][1].c_str()); CountWaveY3 = GetTableRows(tableName,strsql.c_str());
CountWaveY3 = GetTableRows(tableName,whereCon);
if ((CountWaveY > 0 && (CountWaveY / planCount > rate)) && (CountWaveY2 > 0 && (CountWaveY2 / planCount > rate)) && (CountWaveY3 > 0 && (CountWaveY3 / planCount > rate))) if ((CountWaveY > 0 && (CountWaveY / planCount > rate)) && (CountWaveY2 > 0 && (CountWaveY2 / planCount > rate)) && (CountWaveY3 > 0 && (CountWaveY3 / planCount > rate)))
{ {
@ -1516,35 +1491,15 @@ int SqliteDB::CalculateData()
} }
if(nodeWaveSend[2] == "0"){ if(nodeWaveSend[2] == "0"){
const char *sql =
"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str());
string strsql = string(sql) + string(whereCon); string strsql = string(sql1) + string(whereCon);
CountWaveZ = GetTableRows(tableName,strsql.c_str());
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-1 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Z",vecRet[i][1].c_str());
CountWaveZ = GetTableRows(tableName,whereCon);
sql =
"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql2) + string(whereCon);
CountWaveZ2 = GetTableRows(tableName,strsql.c_str());
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-2 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Z",vecRet[i][1].c_str());
CountWaveZ2 = GetTableRows(tableName,whereCon);
sql =
"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day')"
" AND timeStamp < strftime('%s', 'now', 'start of day')";
print_info("ret = %s\n",vecRet[i][1].c_str());
sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str()); sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str());
strsql = string(sql) + string(whereCon); strsql = string(sql3) + string(whereCon);
CountWaveZ3 = GetTableRows(tableName,strsql.c_str());
//sprintf(whereCon,"timeStamp >= strftime('%s', 'now', '-3 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and channelID = '%s-Z",vecRet[i][1].c_str());
CountWaveZ3 = GetTableRows(tableName,whereCon);
if ((CountWaveZ > 0 && (CountWaveZ / planCount > rate)) && (CountWaveZ2 > 0 && (CountWaveZ2 / planCount > rate)) && (CountWaveZ3 > 0 && (CountWaveZ3 / planCount > rate))) if ((CountWaveZ > 0 && (CountWaveZ / planCount > rate)) && (CountWaveZ2 > 0 && (CountWaveZ2 / planCount > rate)) && (CountWaveZ3 > 0 && (CountWaveZ3 / planCount > rate)))
{ {
@ -1553,10 +1508,14 @@ int SqliteDB::CalculateData()
rateZ = -1; rateZ = -1;
} }
} }
StatisticCountTotal += StatisticCount;
print_info("CountWaveX = %d\n",CountWaveX); SixCountTotal += SixCount;
LOG_INFO("YESTERDAY dataNodeNo = %s Statistic Count = %d,06 Count = %d Timing Count = %d,CountWaveX = %d,CountWaveY = %d,CountWaveZ = %d,featureInterVal = %s,waveInterVal = %s\n"\ TimingCountTotal += TimingCount;
,vecRet[i][0].c_str(),StatisticCount,SixCount,TimingCount,CountWaveX,CountWaveY,CountWaveZ,vecRet[i][3].c_str(),vecRet[i][4].c_str()); CountWaveXTotal += CountWaveX;
CountWaveYTotal += CountWaveY;
CountWaveZTotal += CountWaveZ;
LOG_INFO("dataNodeNo = %s , Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d , CountWaveY = %d , CountWaveZ = %d , featureInterVal = %s , waveInterVal = %s , NodeWaveSend = %s\n"\
,vecRet[i][0].c_str(),StatisticCount,SixCount,TimingCount,CountWaveX,CountWaveY,CountWaveZ,vecRet[i][3].c_str(),vecRet[i][4].c_str(),vecRet[i][2].c_str());
if (rateX == 1 && rateY == 1 && rateZ == 1 && vecRet[i][5] == "3") if (rateX == 1 && rateY == 1 && rateZ == 1 && vecRet[i][5] == "3")
{ {
@ -1568,7 +1527,7 @@ int SqliteDB::CalculateData()
LOG_INFO("update ZigbeePower 2"); LOG_INFO("update ZigbeePower 2");
} }
if ((rateX == -1 || rateY == -1 || rateZ == 1 )&& vecRet[i][5] == "2") if ((rateX == -1 || rateY == -1 || rateZ == -1 )&& vecRet[i][5] == "2")
{ {
char updateSql[50] = {0x00}; char updateSql[50] = {0x00};
sprintf(updateSql,"ZigbeePower = '3',UpdateFlag = 0 "); sprintf(updateSql,"ZigbeePower = '3',UpdateFlag = 0 ");
@ -1577,8 +1536,12 @@ int SqliteDB::CalculateData()
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
LOG_INFO("update ZigbeePower 3"); LOG_INFO("update ZigbeePower 3");
} }
featureInterVal = atoi(vecRet[i][3].c_str());
waveInterVal = atoi(vecRet[i][4].c_str());
} }
LOG_INFO("Node Count = %d , featureInterVal = %d , waveInterVal = %d\n",vecRet.size(),featureInterVal,waveInterVal);
LOG_INFO("plan Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ",planCountStatistic * vecRet.size(),planCount * vecRet.size(),planCount * vecRet.size(),planCount * vecRet.size());
LOG_INFO("reality Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ,CountWaveY = %d ,CountWaveZ = %d ",StatisticCountTotal,SixCountTotal,TimingCountTotal,CountWaveXTotal,CountWaveYTotal,CountWaveZTotal);
} }