修复电池计算bug,version 5.2
This commit is contained in:
parent
c3ec574d56
commit
b820734282
@ -813,8 +813,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
memset(selectSql, 0x00, sizeof(selectSql));
|
memset(selectSql, 0x00, sizeof(selectSql));
|
||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
int res = 0;
|
int res = 0;
|
||||||
//数据关联使用MeasurementID字段
|
sprintf(selectSql, " MeasurementID,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower ");
|
||||||
sprintf(selectSql, " dataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower,MeasurementID ");
|
|
||||||
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL);
|
||||||
zlog_info(zct, "Size = %d", vecRes.size());
|
zlog_info(zct, "Size = %d", vecRes.size());
|
||||||
if (vecRes.size() > 0) {
|
if (vecRes.size() > 0) {
|
||||||
@ -822,29 +821,30 @@ int SqliteDB::CalculateBattery() {
|
|||||||
float capacity = 0.0, startCapacity = 0.0;
|
float capacity = 0.0, startCapacity = 0.0;
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
memset(selectSql, 0x00, sizeof(selectSql));
|
memset(selectSql, 0x00, sizeof(selectSql));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
||||||
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
std::vector<std::string> vParam;
|
std::vector<std::string> vParam;
|
||||||
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
||||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算
|
if (vParam.size() <= 0 || vecResSig.size() <= 0) { // 第一次计算
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str());
|
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
||||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||||
if (Dip == "") {
|
if (Dip == "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh //电池总量
|
capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh 电池总量
|
||||||
startCapacity = capacity;
|
startCapacity = capacity;
|
||||||
|
|
||||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, startCapacity);
|
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, startCapacity);
|
||||||
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
|
sprintf(whereCon, "MeasurementID = '%s' ", vecRes[i][0].c_str());
|
||||||
res = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
res = UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][7].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][0].c_str());
|
||||||
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
if (vecResSig.size() <= 0) { // 一条数据都没有
|
if (vecResSig.size() <= 0) { // 一条数据都没有
|
||||||
continue;
|
continue;
|
||||||
@ -856,7 +856,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
zlog_info(zct, "dip = %d", atoi(vecResSig[1].c_str()));
|
zlog_info(zct, "dip = %d", atoi(vecResSig[1].c_str()));
|
||||||
|
|
||||||
zlog_info(zct, "capacity = %f", capacity);
|
zlog_info(zct, "capacity = %f", capacity);
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][7].c_str(), vecResSig[8].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][0].c_str(), vecResSig[8].c_str());
|
||||||
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
zlog_info(zct, "vecResbattery size = %d", vecResbattery.size());
|
zlog_info(zct, "vecResbattery size = %d", vecResbattery.size());
|
||||||
if (vecResbattery.size() <= 0) {
|
if (vecResbattery.size() <= 0) {
|
||||||
@ -908,36 +908,36 @@ int SqliteDB::CalculateBattery() {
|
|||||||
remainBattery = 10;
|
remainBattery = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][7].c_str(), atof(vecResSig[6].c_str()), remainBattery);
|
zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][0].c_str(), atof(vecResSig[6].c_str()), remainBattery);
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str());
|
||||||
std::string strtimeStamp = GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
std::string strtimeStamp = GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon);
|
||||||
|
|
||||||
sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery);
|
sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery);
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][7].c_str(), strtimeStamp.c_str());
|
sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][0].c_str(), strtimeStamp.c_str());
|
||||||
res = UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
res = UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
memset(updateSql, 0x00, sizeof(updateSql));
|
memset(updateSql, 0x00, sizeof(updateSql));
|
||||||
|
|
||||||
char insertSql[1024] = {0x00}, deleteSql[1024] = {0x00};
|
char insertSql[1024] = {0x00}, deleteSql[1024] = {0x00};
|
||||||
sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str());
|
sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str());
|
||||||
res = ExeSql(insertSql);
|
res = ExeSql(insertSql);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str());
|
sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str());
|
||||||
res = ExeSql(deleteSql);
|
res = ExeSql(deleteSql);
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "res = %d", res);
|
zlog_error(zct, "res = %d", res);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str());
|
sprintf(whereCon, "MeasurementID = '%s' ", vecRes[i][0].c_str());
|
||||||
if (startCapacity > 0) {
|
if (startCapacity > 0) {
|
||||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery);
|
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery);
|
||||||
} else {
|
} else {
|
||||||
@ -949,7 +949,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
res = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
res = data_publish(strData.c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
|
||||||
if(res !=0 ){
|
if(res !=0 ){
|
||||||
zlog_error(zct, "data_publish res = %d", res);
|
zlog_error(zct, "data_publish res = %d", res);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user