diff --git a/Cidn-SH b/Cidn-SH index 5c4e78a..56cd397 100644 Binary files a/Cidn-SH and b/Cidn-SH differ diff --git a/common/SH_global.h b/common/SH_global.h index 835d4a9..48bcc15 100644 --- a/common/SH_global.h +++ b/common/SH_global.h @@ -24,8 +24,8 @@ enum enumZigBeeTransmitStatus { //#define Q4G_MODULE //#define WIFI_MODULE //#define NR5G_MEIGE -//#define G2UL_GATEWAY -#define IMX6UL_GATEWAY +#define G2UL_GATEWAY +//#define IMX6UL_GATEWAY class GlobalConfig { diff --git a/dbaccess/SH_SqlDB.cpp b/dbaccess/SH_SqlDB.cpp index 1b01dec..d57b8ef 100644 --- a/dbaccess/SH_SqlDB.cpp +++ b/dbaccess/SH_SqlDB.cpp @@ -1403,27 +1403,28 @@ int SqliteDB::CalculateData() array_t vecRet = GetDataMultiLine(T_SENSOR_INFO(TNAME)," dataNodeNo,MeasurementID,NodeWaveSend,featureInterVal,waveInterVal,ZigbeePower ",NULL); 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++) { - 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()); char tableName[50]={0x00}; char whereCon[128]={0x00}; sprintf(tableName,"t_dataStatic_%s",vecRet[i][0].c_str()); const char *sql = - " timestamp >= strftime('%s', 'now', '-1 day', 'start of day') " - "AND timestamp < strftime('%s', 'now', 'start of day') "; - + " timestamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') " + "AND timestamp < strftime('%s', 'now', 'start of day','utc','+24 hours') "; int StatisticCount = GetTableRows(tableName,sql); - - - sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day') AND timeStamp < strftime('%s', 'now', 'start of day') and statisticType = '1' "; + + 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' "; 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); - print_info("nodeWaveSend = %s,waveInterVal = %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] == "") continue; vector nodeWaveSend ; @@ -1436,38 +1437,30 @@ int SqliteDB::CalculateData() { 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") { - - 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()); - string strsql = string(sql) + string(whereCon); + string strsql = string(sql1) + string(whereCon); printf("sql = %s\n",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()); - strsql = string(sql) + string(whereCon); - - //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()); + strsql = string(sql2) + string(whereCon); + CountWaveX2 = GetTableRows(tableName,strsql.c_str()); sprintf(whereCon," and channelID = '%s-X'",vecRet[i][1].c_str()); - strsql = string(sql) + 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,whereCon); - + strsql = string(sql3) + string(whereCon); + CountWaveX3 = GetTableRows(tableName,strsql.c_str()); if ((CountWaveX > 0 && (CountWaveX / planCount > rate)) && (CountWaveX2 > 0 && (CountWaveX2 / planCount > rate)) && (CountWaveX3 > 0 && (CountWaveX3 / planCount > rate))) { rateX = 1; @@ -1478,33 +1471,15 @@ int SqliteDB::CalculateData() } 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()); - string strsql = string(sql) + 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()); + string strsql = string(sql1) + string(whereCon); 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()); - strsql = string(sql) + 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,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()); + strsql = string(sql2) + string(whereCon); + CountWaveY2 = GetTableRows(tableName,strsql.c_str()); sprintf(whereCon," and channelID = '%s-Y'",vecRet[i][1].c_str()); - strsql = string(sql) + 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,whereCon); + strsql = string(sql3) + string(whereCon); + CountWaveY3 = GetTableRows(tableName,strsql.c_str()); 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"){ - 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()); - string strsql = string(sql) + string(whereCon); - - //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()); + string strsql = string(sql1) + string(whereCon); + CountWaveZ = GetTableRows(tableName,strsql.c_str()); sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str()); - strsql = string(sql) + string(whereCon); - - //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()); + strsql = string(sql2) + string(whereCon); + CountWaveZ2 = GetTableRows(tableName,strsql.c_str()); sprintf(whereCon," and channelID = '%s-Z'",vecRet[i][1].c_str()); - strsql = string(sql) + string(whereCon); - - //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); + strsql = string(sql3) + string(whereCon); + CountWaveZ3 = GetTableRows(tableName,strsql.c_str()); 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; } } - - print_info("CountWaveX = %d\n",CountWaveX); - 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"\ - ,vecRet[i][0].c_str(),StatisticCount,SixCount,TimingCount,CountWaveX,CountWaveY,CountWaveZ,vecRet[i][3].c_str(),vecRet[i][4].c_str()); + StatisticCountTotal += StatisticCount; + SixCountTotal += SixCount; + TimingCountTotal += TimingCount; + 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") { @@ -1568,7 +1527,7 @@ int SqliteDB::CalculateData() 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}; sprintf(updateSql,"ZigbeePower = '3',UpdateFlag = 0 "); @@ -1577,9 +1536,13 @@ int SqliteDB::CalculateData() UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); 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); + } }