|
|
@@ -1021,9 +1021,15 @@ int dev_search_power_trend_info(sqlite3 *db,int product_id,int product_ch_id,Glo
|
|
|
|
|
|
for(int i=0;i < nCount; i++)
|
|
|
{
|
|
|
- _globalPowerInfo ->_power_trend_info.ydata[POWER_MERITORIOUS_TYPE][i] = atof(pResult[(nCount-i)*ncolumn+6]);
|
|
|
- _globalPowerInfo ->_power_trend_info.ydata[POWER_REACTIVE_TYPE][i] =atof(pResult[(nCount-i)*ncolumn+6])*atof(pResult[(nCount-i)*ncolumn+9]) - atof(pResult[(nCount-i)*ncolumn+6]);
|
|
|
- _globalPowerInfo ->_power_trend_info.ydata[POWER_APPARENT_TYPE][i] = atof(pResult[(nCount-i)*ncolumn+6])*atof(pResult[(nCount-i)*ncolumn+9]);
|
|
|
+ float PowerTemp=atof(pResult[(nCount-i)*ncolumn+6]);
|
|
|
+ float PowerFactor=atof(pResult[(nCount-i)*ncolumn+9]);
|
|
|
+ if (PowerFactor<0.05)
|
|
|
+ {
|
|
|
+ PowerFactor=1.0;
|
|
|
+ }
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_MERITORIOUS_TYPE][i] = PowerTemp;
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_REACTIVE_TYPE][i] = PowerTemp / PowerFactor - PowerTemp;
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_APPARENT_TYPE][i] = PowerTemp / PowerFactor;
|
|
|
strcpy(_globalPowerInfo ->_power_trend_info.xAxis[i],pResult[(nCount-i)*ncolumn+0]);
|
|
|
#if DEBUG_TEST
|
|
|
sprintf(data_time_str,"2023-01-23:%d",i+4);
|
|
|
@@ -1041,6 +1047,103 @@ int dev_search_power_trend_info(sqlite3 *db,int product_id,int product_ch_id,Glo
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/// @brief 三相功率趋势图接口(有功功率、无功功率以及视在功率)
|
|
|
+/// @param db
|
|
|
+/// @param product_id
|
|
|
+/// @param product_ch_id
|
|
|
+/// @param total_type
|
|
|
+/// @param _globalPowerInfo
|
|
|
+/// @return
|
|
|
+int dev_search_power_AC_trend_info(sqlite3 *db,int product_id,int product_ch_id,int product_ph_id,GlobalPowerInfo* _globalPowerInfo,char* start_time,char* end_time)
|
|
|
+{
|
|
|
+ int res ;
|
|
|
+ char select_sql[1024] = {0};
|
|
|
+ char *errorMsg = NULL;
|
|
|
+ int nrow = 0; //满足条件的记录数目
|
|
|
+ int ncolumn = 0; //每条记录包含的字段数据
|
|
|
+ char** pResult = NULL; //用来指向sql执行结果的指针
|
|
|
+ char* err_msg=NULL;
|
|
|
+
|
|
|
+ // SELECT *
|
|
|
+ // FROM Table_PowerInfo
|
|
|
+ // WHERE product_id = 1 AND product_ch_id = 0
|
|
|
+ // ORDER BY product_samp_time DESC
|
|
|
+ // LIMIT 1;
|
|
|
+
|
|
|
+ // sprintf(select_sql,"SELECT * FROM Table_PowerInfo WHERE product_id=%d AND product_ch_id=%d ORDER BY strftime('%%Y-%%m-%%d %%H:%%M:%%S',product_samp_time || '.000') DESC LIMIT 1;",
|
|
|
+ // product_id,
|
|
|
+ // product_ch_id);
|
|
|
+
|
|
|
+ // 数据库查询 1MIN一个点
|
|
|
+ snprintf(select_sql, sizeof(select_sql), "SELECT * FROM Table_PhasePowerInfo WHERE (product_id=%d) AND (product_ph_id=%d) AND (product_ch_id_belong=%d) AND (product_ph_samp_time BETWEEN '%s' AND '%s') ORDER BY product_index DESC LIMIT 60;",
|
|
|
+ product_id,
|
|
|
+ product_ph_id,
|
|
|
+ product_ch_id,
|
|
|
+ start_time,
|
|
|
+ end_time);
|
|
|
+
|
|
|
+ //300是秒数,即5分钟的秒数为300秒,这个间隔数可以自己定义
|
|
|
+ // select id,cameraName,checkPointName,datetime(strftime('%s', countTime)/300*300,'unixepoch')
|
|
|
+ // as countTime,sum(todayCount) as 'todaycount'
|
|
|
+ // from cardetectinfo where countTime>='2022-04-01 01:01:01' and countTime<='2022-08-31 01:01:01' group by strftime('%s', countTime)/300 order by countTime limit 0,20
|
|
|
+
|
|
|
+ // SELECT TO_CHAR(TRUNC(SYSDATE, 'DD') + (1 / (24 * 60) * ROWNUM),
|
|
|
+ // 'YYYY-MM-DD hh24:MI:SS')
|
|
|
+ // FROM ALL_OBJECTS
|
|
|
+ // WHERE ROWNUM <= 1440 / 1;
|
|
|
+
|
|
|
+
|
|
|
+ res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
|
|
|
+ if(res != SQLITE_OK)
|
|
|
+ {
|
|
|
+ log_e("sqlite handle error: %s \n%s\n", err_msg,select_sql); sqlite3_free(err_msg);
|
|
|
+ return -1 ;
|
|
|
+ }
|
|
|
+ if(nrow==0)
|
|
|
+ {
|
|
|
+ log_e("sqlite search no data.");
|
|
|
+ sqlite3_free_table(pResult);
|
|
|
+ return -1 ;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nCount=1;
|
|
|
+ if (nrow<=TOTAL_COUNT)
|
|
|
+ {
|
|
|
+ nCount=nrow;
|
|
|
+ }
|
|
|
+ else nCount=TOTAL_COUNT;
|
|
|
+
|
|
|
+ char data_time_str[32]={0};
|
|
|
+
|
|
|
+ for(int i=0;i < nCount; i++)
|
|
|
+ {
|
|
|
+ float PowerTemp=atof(pResult[(nCount-i)*ncolumn+6]);
|
|
|
+ float PowerFactor=atof(pResult[(nCount-i)*ncolumn+9]);
|
|
|
+ if (PowerFactor<0.05)
|
|
|
+ {
|
|
|
+ PowerFactor=1.0;
|
|
|
+ }
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_MERITORIOUS_TYPE][i] = PowerTemp;
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_REACTIVE_TYPE][i] = PowerTemp / PowerFactor - PowerTemp;
|
|
|
+ _globalPowerInfo->_power_trend_info.ydata[POWER_APPARENT_TYPE][i] = PowerTemp / PowerFactor;
|
|
|
+ strcpy(_globalPowerInfo ->_power_trend_info.xAxis[i],pResult[(nCount-i)*ncolumn+0]);
|
|
|
+ #if DEBUG_TEST
|
|
|
+ sprintf(data_time_str,"2023-01-23:%d",i+4);
|
|
|
+ strcpy(&_globalPowerInfo ->_power_trend_info.xAxis[i][0],data_time_str);
|
|
|
+
|
|
|
+ _globalPowerInfo ->_power_trend_info.ydata[POWER_MERITORIOUS_TYPE][i] = i+1.5;
|
|
|
+ _globalPowerInfo ->_power_trend_info.ydata[POWER_REACTIVE_TYPE][i] = i+2;
|
|
|
+ _globalPowerInfo ->_power_trend_info.ydata[POWER_APPARENT_TYPE][i] = i+2.5;
|
|
|
+ #endif
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlite3_free_table(pResult);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/// @brief 查询电源监控信息表 查询条件 时间与ID号
|
|
|
/// @param db
|