Browse Source

1、修改三相24H耗电量、有功无功视在功率计算错误bug

liyuezong 2 years ago
parent
commit
dc4147fda4
3 changed files with 135 additions and 6 deletions
  1. 28 3
      pro/src/appweb_handle.c
  2. 106 3
      pro/src/sqlite_handle.c
  3. 1 0
      pro/src/sqlite_handle.h

+ 28 - 3
pro/src/appweb_handle.c

@@ -955,10 +955,35 @@ static void overallStatusMonitoring(void* conn)
         //清0
         memset(&__PowerTrendInfo,0,sizeof(GlobalPowerInfo));
         #if 1
-        //查询数据库总电源信息 传给所申请的参数结构体
-        if(dev_search_power_trend_info(__globalDeviceManage.db,__globalDeviceManage._globalDevInfo.product_id,0,&__PowerTrendInfo,_over_all_sts_monitor.start_time,_over_all_sts_monitor.end_time)!=0)
+         if (_over_all_sts_monitor.lType && (strcmp(_over_all_sts_monitor.lType,"L1")==0 || strcmp(_over_all_sts_monitor.lType,"L2")==0 || strcmp(_over_all_sts_monitor.lType,"L3")==0))
         {
-            log_e("serach total power consumption err.");
+            int ph_id=-1;
+            if (strcmp(_over_all_sts_monitor.lType,"L1")==0)
+            {
+                ph_id=0;
+            }
+            else if (strcmp(_over_all_sts_monitor.lType,"L2")==0 )
+            {
+                ph_id=1;
+            }
+            else if(strcmp(_over_all_sts_monitor.lType,"L3")==0 )
+            {
+                ph_id=2;
+            }
+
+            // 查询数据库总电源信息 传给所申请的参数结构体
+            if (dev_search_power_AC_trend_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 0, ph_id, &__PowerTrendInfo, _over_all_sts_monitor.start_time, _over_all_sts_monitor.end_time) != 0)
+            {
+                log_e("serach total power consumption err.");
+            }
+        }
+        else
+        {
+            // 查询数据库总电源信息 传给所申请的参数结构体
+            if (dev_search_power_trend_info(__globalDeviceManage.db, __globalDeviceManage._globalDevInfo.product_id, 0, &__PowerTrendInfo, _over_all_sts_monitor.start_time, _over_all_sts_monitor.end_time) != 0)
+            {
+                log_e("serach total power consumption err.");
+            }
         }
 
         //传值给总管理结构体

+ 106 - 3
pro/src/sqlite_handle.c

@@ -996,9 +996,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);
@@ -1016,6 +1022,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 

+ 1 - 0
pro/src/sqlite_handle.h

@@ -30,6 +30,7 @@ int dev_search_time_power_info(sqlite3 *db,int product_id,int product_ch_id,int
 int dev_search_time_t_ac_power_info(sqlite3 *db,int product_id,int product_ch_id,int product_ph_id,int total_type,GlobalPowerInfo* _globalPowerInfo,char* start_time,char* end_time);
 int dev_get_system_total_info(sqlite3 *db,int product_id,int product_ch_id, SystemTotalInfo* __SystemTotalInfo,char* start_time,char* end_time);
 int dev_search_power_trend_info(sqlite3 *db,int product_id,int product_ch_id,GlobalPowerInfo* _globalPowerInfo,char* start_time,char* end_time);
+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 dev_search_power_info(sqlite3 *db,
                         int product_id,
                         int product_ch_id,