修改现场设备联调问题

This commit is contained in:
lixiaoyuan
2025-10-26 20:43:51 +08:00
parent 5f6511a3f0
commit ac17c41900
13 changed files with 175 additions and 144 deletions

View File

@@ -674,12 +674,11 @@ void Station::writeStatistic()
}
}
{
int pos = npos;
if (tOffset > 20) { pos += 1; }
mapCacheElectIn[pos] = statData.dayElectIn;
mapCacheElectOut[pos] = statData.dayElectOut;
mapCacheElectIn[pos] = (pos == 0) ? 0 : statData.dayElectIn;
mapCacheElectOut[pos] = (pos == 0) ? 0 : statData.dayElectOut;
mapCacheElectCharger[pos] = 0;
// 预测数据源记录
@@ -703,57 +702,61 @@ void Station::writeStatistic()
}
void Station::predict()
{
int64_t tNow = Utils::time();
string dt1 = Utils::dateStr(tNow-86400*7);
int days = 7;
string dt1 = Utils::dateStr(tNow-86400*days);
string dt2 = Utils::dateStr(tNow-86400);
/// 预测实现方案:
// 查询前7天的历史数据根据历史数据计算今日数据每10分钟一个数据一天共144个数据点
// 查询前7天的历史数据(不包含今天)根据历史数据计算今日数据每10分钟一个数据一天共144个数据点
string sql = "SELECT * FROM predict_day pd WHERE pd.station_id='" + std::to_string(stationId)
+ "'AND dt>='" + dt1 + "' AND dt<='" + dt2 + "'";
+ "' AND dt>='" + dt1 + " AND dt<'" + dt2 + "';";
vector<Fields> result;
DAO::exec(NULL, sql, result);
// 数据源的条数1天的数据算作1条
int countStorageIn = 0;
int countStorageOut = 0;
int countCharge = 0;
// 数据源的每个时刻数据点的个数
vector<int> countStorageIn(predictStorageIn.size(), 0);
vector<int> countStorageOut(predictStorageOut.size(), 0);
vector<int> countCharge(predictCharge.size(), 0);
for (int row=0; row<result.size(); ++row)
{
// 如果数据全是0则不参与计算
auto& fields = result[row];
vector<int>* vdptr = NULL;
int datatype = fields.get<int>("datatype"); // 1储能充电2储能放电3充电桩充电4发电
if (datatype == 1)
{
countStorageIn++;
vdptr = &predictStorageIn;
}
else if (datatype == 2)
{
countStorageOut++;
vdptr = &predictStorageOut;
}
else if (datatype == 3)
{
countCharge++;
vdptr = &predictCharge;
}
if (datatype == 1) { vdptr = &predictStorageIn; }
else if (datatype == 2) { vdptr = &predictStorageOut; }
else if (datatype == 3) { vdptr = &predictCharge; }
if (vdptr)
{
string& strval = fields.value("value");
std::vector<int> vec;
JSON::parseArray(strval, vec);
for (int i = 0; i<vdptr->size() && i<vec.size(); ++i)
{
(*vdptr)[i] += vec[i];
auto& v0 = vec[i];
if (v0 > 0)
{
(*vdptr)[i] += v0;
if (datatype == 1) { countStorageIn[i]++; }
else if (datatype == 2) { countStorageOut[i]++; }
else if (datatype == 3) { countCharge[i]++; }
}
}
}
}
for (int i = 0; i<predictStorageIn.size(); ++i)
{
if (countStorageIn[i] > 0) { predictStorageIn[i] = predictStorageIn[i] / countStorageIn[i]; }
if (countStorageOut[i] > 0) { predictStorageOut[i] = predictStorageOut[i] / countStorageOut[i]; }
if (countCharge[i] > 0) { predictCharge[i] = predictCharge[i] / countCharge[i]; }
}
}