mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
新增策略运行效益接口
This commit is contained in:
@@ -54,6 +54,11 @@ public:
|
||||
std::string dump();
|
||||
};
|
||||
|
||||
class StateGrid
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
class AppData
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -377,11 +377,8 @@ void Station::readEnergyData(int deviceNo, string addr, int val)
|
||||
{
|
||||
statData.ts = Utils::time();
|
||||
|
||||
if (addr == "0x000B") { this->storage.voltage = val; } // A相电压 R uint32 1V 0x000B
|
||||
else if (addr == "0x0011") { this->storage.current = val; } // A相电流 R int32 1A 0x0011
|
||||
else if (addr == "0x0023") { this->storage.power = val; } // 三相总有功 R int32 1kW 0x0023
|
||||
// 功率因数 ?? 电表没有功率因数数据
|
||||
else if (addr == "0x002F") { statData.dayElectIn = val; } // 日充电电量 R uint32 1kWh 0x002F
|
||||
if (addr == "0x002F") { statData.dayElectIn = val; } // 日充电电量 R uint32 1kWh 0x002F
|
||||
else if (addr == "0x0031") { statData.dayElectOut = val; } //日放电电量 R uint32 1kWh 0x0031
|
||||
else if (addr == "0x0033") { statData.dayFeeIn = val; } //日充电费用 R uint32 1RMB 0x0033
|
||||
else if (addr == "0x0035") { statData.dayFeeOut = val; } //日放电费用 R uint32 1RMB 0x0035
|
||||
@@ -416,6 +413,21 @@ void Station::readEnergyData(int deviceNo, string addr, int val)
|
||||
else if (addr == "0x0069") { statData.totalElectOut_Total = val; } //总反向总有功电能 R uint32 1kWh 0x0069
|
||||
}
|
||||
}
|
||||
|
||||
void Station::readEMSData(int deviceNo, string addr, int val)
|
||||
{
|
||||
// ["A相电压", "0x107E", "0.0", " V", "1"] ,
|
||||
// ["A相电流", "0x1084", "0.0", " A"],
|
||||
// ["总有功功率", "0x1096", "0.0", " kW"]
|
||||
}
|
||||
|
||||
void Station::readBMSData(int deviceNo, string addr, int val)
|
||||
{
|
||||
if (addr == "0x0003") { this->storage.voltage = val * 0.1; } // ["电压", "0x0003", "0.0", " V", "0.1"],
|
||||
else if (addr == "0x0005") { this->storage.current = val * 0.1; } // ["电流", "0x0005", "0.0", " A", "0.1"] ,
|
||||
else if (addr == "0x000F") { this->storage.power = val; } // ["堆功率", "0x000F", "0.0", " kW"] ,
|
||||
}
|
||||
|
||||
// 充电桩
|
||||
void Station::readChargeData(int deviceNo, string addr, int val)
|
||||
{
|
||||
@@ -745,6 +757,7 @@ void Station::writeStatistic()
|
||||
}
|
||||
|
||||
{
|
||||
// stat_total
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(statData.ts));
|
||||
fields.set("station_id", this->stationId);
|
||||
@@ -771,7 +784,8 @@ void Station::writeStatistic()
|
||||
}
|
||||
if (statData.ts > 0)
|
||||
{
|
||||
{ // stat_day
|
||||
{
|
||||
// stat_day
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(statData.ts));
|
||||
fields.set("station_id", this->stationId);
|
||||
@@ -783,6 +797,7 @@ void Station::writeStatistic()
|
||||
|
||||
if (statData.dayElectIn > 0.0f || statData.dayElectOut > 0.0f)
|
||||
{
|
||||
//stat_total_day
|
||||
Fields fields;
|
||||
fields.set("dt", Utils::dateStr(statData.ts));
|
||||
fields.set("station_id", this->stationId);
|
||||
|
||||
@@ -119,7 +119,9 @@ public:
|
||||
string getGatewayParam();
|
||||
|
||||
void readAlert(std::shared_ptr<Device> device, std::string addr, int v, std::string text);
|
||||
void readEnergyData(int deviceNo, string addr, int val);
|
||||
void readEnergyData(int deviceNo, string addr, int val); // 电表
|
||||
void readEMSData(int deviceNo, string addr, int val);
|
||||
void readBMSData(int deviceNo, string addr, int val);
|
||||
void readChargeData(int deviceNo, string addr, int val);
|
||||
void readTHData(int deviceNo, string addr, int val);
|
||||
void readFire40Data(int deviceNo, string addr, int val);
|
||||
|
||||
@@ -194,6 +194,8 @@ static std::map<std::string, HandlerOptions> g_mapHttpHandlerGet =
|
||||
{"/queryServiceApiList", HandlerOptions(&HttpEntity::queryServiceApiList, {})},
|
||||
{"/deleteServiceApi", HandlerOptions(&HttpEntity::deleteServiceApi, {"api_id"})},
|
||||
|
||||
{"/queryEGridPeriod", HandlerOptions(&HttpEntity::queryEGridPeriod, {})},
|
||||
|
||||
//{"/insert", HandlerOptions(&HttpEntity::insert, {})},
|
||||
//{"/update", HandlerOptions(&HttpEntity::update, {})},
|
||||
//{"/delete", HandlerOptions(&HttpEntity::delete, {})},
|
||||
@@ -1896,3 +1898,123 @@ Errcode HttpEntity::updateGatewayParams(const httplib::Request& req, njson& json
|
||||
}
|
||||
return Errcode::ERR_PARAM;
|
||||
}
|
||||
|
||||
|
||||
static float SetPeriodRowJson(njson& jsonrow, std::string period, int eIn, int eOut, float priceIn, float priceOut, std::string dt)
|
||||
{
|
||||
jsonrow["dt"] = dt;
|
||||
jsonrow["period"] = period;
|
||||
jsonrow["E_in"] = eIn;
|
||||
jsonrow["E_out"] = eOut;
|
||||
jsonrow["grid_price"] = Utils::toStr(priceIn);
|
||||
jsonrow["charge_price"] = Utils::toStr(priceOut);
|
||||
return eOut * priceOut - eIn * priceIn;
|
||||
}
|
||||
|
||||
Errcode HttpEntity::queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg)
|
||||
{
|
||||
Fields params;
|
||||
GetRequestParams(req, {"dt", "station_id"}, params);
|
||||
|
||||
int stationId = params.get<int>("station_id");
|
||||
std::string dt = params.value("dt");
|
||||
//int year = 0;
|
||||
//int month = 0;
|
||||
//int day = 0;
|
||||
//int ret = sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day); // 解析3个值,成功返回3
|
||||
//if (ret != 3)
|
||||
//{
|
||||
// return Errcode::ERR_PARAM;
|
||||
//}
|
||||
if (stationId == 0 || dt.empty())
|
||||
{
|
||||
return Errcode::ERR_PARAM;
|
||||
}
|
||||
|
||||
float priceJ = 0.0;
|
||||
float priceF = 0.0;
|
||||
float priceP = 0.0;
|
||||
float priceG = 0.0;
|
||||
float priceC = 0.0;
|
||||
|
||||
std::vector<Fields> result;
|
||||
auto err = DAO::exec(NULL, "select * from egrid_price;", result);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
if (result.size() > 0)
|
||||
{
|
||||
for (auto& item: result)
|
||||
{
|
||||
int etype = item.get<int>("etype");
|
||||
float price = item.get<float>("price", 2);
|
||||
if (etype == 1) { priceJ = price; }
|
||||
else if (etype == 2) { priceF = price; }
|
||||
else if (etype == 3) { priceP = price; }
|
||||
else if (etype == 4) { priceG = price; }
|
||||
else if (etype == 9) { priceC = price; }
|
||||
}
|
||||
}
|
||||
|
||||
//std::string sql = std::format("SELECT ep.*, ep2.price FROM egrid_period ep LEFT JOIN egrid_price ep2 ON ep.etype=ep2.etype WHERE ep.`month`={};", month);
|
||||
std::string sql = std::format("select * from stat_total_day WHERE dt='{}' AND station_id='{}';", dt, stationId);
|
||||
err = DAO::exec(NULL, sql, result);
|
||||
if (err != Errcode::OK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
njson jsondata = njson::array();
|
||||
if (result.size() > 0)
|
||||
{
|
||||
auto& item = result[0];
|
||||
float incomeTotal = 0.0f;
|
||||
// 谷
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "谷", item.get<int>("E_in_G"), item.get<int>("E_out_G"), priceG, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 平
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "平", item.get<int>("E_in_P"), item.get<int>("E_out_P"), priceP, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 峰
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "峰", item.get<int>("E_in_F"), item.get<int>("E_out_F"), priceF, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 尖
|
||||
{
|
||||
njson jsonrow;
|
||||
float income = SetPeriodRowJson(jsonrow, "尖", item.get<int>("E_in_J"), item.get<int>("E_out_J"), priceJ, priceC, dt);
|
||||
jsonrow["income"] = Utils::toStr(income);
|
||||
jsondata.push_back(jsonrow);
|
||||
incomeTotal += income;
|
||||
}
|
||||
// 总计
|
||||
{
|
||||
njson jsonrow;
|
||||
jsonrow["dt"] = dt;
|
||||
jsonrow["period"] = "总计";
|
||||
jsonrow["E_in"] = item.get<int>("E_in");
|
||||
jsonrow["E_out"] = item.get<int>("E_out");
|
||||
jsonrow["grid_price"] = "";
|
||||
jsonrow["charge_price"] = "";
|
||||
jsonrow["income"] = Utils::toStr(incomeTotal);
|
||||
jsondata.push_back(jsonrow);
|
||||
}
|
||||
}
|
||||
json["data"] = jsondata;
|
||||
return Errcode::OK;
|
||||
}
|
||||
@@ -126,4 +126,9 @@ public:
|
||||
Errcode deleteServiceApi(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
|
||||
Errcode updateGatewayParams(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
|
||||
/// ===========================================================================================
|
||||
// 查询电网的时段(尖、峰、平、谷)
|
||||
// 参数: 日期(年-月-日)
|
||||
Errcode queryEGridPeriod(const httplib::Request& req, njson& json, std::string& errmsg);
|
||||
};
|
||||
@@ -415,6 +415,8 @@ void MqttClient::ParseArrivedMessage(njson& json, string command, std::shared_pt
|
||||
device->setParam(addr, val);
|
||||
|
||||
if (command == "MEM_YC") { station->readEnergyData(deviceNo, addr, val); }
|
||||
else if (command == "EMS_YC") {}
|
||||
else if (command == "BMS_YC") { station->readBMSData(deviceNo, addr, val); }
|
||||
else if (command == "Charger_YC") { station->readChargeData(deviceNo, addr, val); }
|
||||
else if (command == "Fire40_YX") { station->readFire40Data(deviceNo, addr, val); }
|
||||
else if (command == "TH_YC") { station->readTHData(deviceNo, addr, val); }
|
||||
|
||||
Reference in New Issue
Block a user