mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改现场设备联调问题
This commit is contained in:
@@ -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]; }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user