实现系统总览、统计分析的图标数据接口

This commit is contained in:
lixiaoyuan
2025-07-31 17:56:08 +08:00
parent 0958fcc224
commit 697193a7aa
19 changed files with 984 additions and 640 deletions

View File

@@ -5,6 +5,82 @@
#include "Operator.h"
struct AppData
{
/////////////////////////////////////////////
/// === 系统 ===
int64_t sysActivationTime {};
/////////////////////////////////////////////
/// === 数据库 ===
struct {
std::string host;
int port;
std::string user;
std::string passwd;
} db;
/////////////////////////////////////////////
/// === 系统统计 ===
// 累计发电量单位kWh
double electGenTatal {};
// 累计入网电量单位kWh
double electInTotal {};
// 累计收益,单位:元
double incomeTotal {};
// 碳减排量, 单位:吨
double ccers {};
/////////////////////////////////////////////
/// === 环境 ===
// 光照度
double illuminance {};
// 辐照度
double irradiance {};
// 风速
double windspeed {};
// 温度
double temperature {};
// 湿度
double humidity {};
/////////////////////////////////////////////
/// === 日统计 ===
struct {
// 发电量
double electGen {};
// 入网电量
double electIn {};
// 发电收益金额
double incomeElect {};
// 储能电量
double electStorage {};
// 储能次数
int numStore {};
// 放电电量
double electDischarge {};
// 放电次数
int numDischarge {};
// 用电电量
double electLoad {};
// 充电电量
double electCharge {};
// 充电次数
int numCharge {};
// 充电收益
double incomeCharge {};
// 故障次数
int numFault {};
// 故障次数:光伏设备
int numFaultSolar {};
// 故障次数:储能设备
int numFaultStorage {};
// 故障次数:负荷设备
int numFaultLoad {};
} statDay;
};
class Application
{
public:
@@ -22,7 +98,6 @@ public:
void runThreadMain();
void runThreadDevice();
private:

View File

@@ -205,6 +205,23 @@ int64_t Utils::timeNowMS()
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
//return std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
}
int64_t Utils::timeNowDate()
{
// 获取当前时间
auto now = std::chrono::system_clock::now();
time_t t = std::chrono::system_clock::to_time_t(now);
// 转换为本地时间结构体
struct tm* tmlocal = localtime(&t);
// 设置时分秒为0
tmlocal->tm_hour = 0;
tmlocal->tm_min = 0;
tmlocal->tm_sec = 0;
// 转换回time_t
return mktime(tmlocal);
}
string Utils::timeNowStr(std::string fmt /*= "%Y-%m-%dT%H:%M:%S"*/)
{
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

View File

@@ -41,6 +41,7 @@ public:
static int64_t timeNow();
static int64_t timeNowMS();
static int64_t timeNowDate();
static string timeNowStr(std::string fmt = "%Y-%m-%d %H:%M:%S");
static string timeNowStrMS(std::string fmt = "%Y-%m-%d %H:%M:%S");
static string timeStr(int64_t ts, std::string fmt = "%Y-%m-%d %H:%M:%S");

View File

@@ -438,6 +438,7 @@ int MyWebHandler::updateDevice(const QString& deviceId, QVariantMap params)
JSgetReqParam("model", params, fields);
JSgetReqParam("factory", params, fields);
JSgetReqParam("is_open", params, fields);
JSgetReqParam("attrs", params, fields);
if (fields.size() == 0)
{
return 0;
@@ -783,16 +784,70 @@ QVariantList MyWebHandler::getStatisticDay(const QString& startDate, int nday)
{
QVariantMap row;
row["dt"] = "";
row["elect_gen_solar"] = float(i);
row["elect_in_solar"] = float(i);
row["income_solar"] = float(i);
// 光伏:发电量、入网电量、发电时长、故障次数
row["elect_gen"] = float(i);
row["elect_in"] = float(i);
row["elect_gen_t"] = float(i);
row["income_elect"] = float(i); // 发电收益
row["num_fault_solar"] = float(i);
// 储能:储能电量、放电电量、储能时长、放电时长、故障次数
row["elect_store"] = float(i);
row["elect_discharge"] = float(i);
row["elect_load"] = float(i);
row["elect_charge"] = float(i);
row["num_charge"] = float(i);
row["elect_store_t"] = float(i);
row["elect_discharge_t"] = float(i);
row["num_fault_store"] = float(i);
// 充电:充电电量、充电收益、充电次数、充电时长、故障次数
row["elect_charge"] = float(i);
row["elect_charge_t"] = float(i);
row["income_charge"] = float(i);
row["num_charge"] = float(i);
row["num_fault_charge"] = float(i);
// 负载:
row["elect_load"] = float(i);
row["num_fault_load"] = float(i);
result << row;
}
return result;
}
static QVariantList RandCurveDataDay(int a, int b)
{
QVariantList d;
int64_t t0 = Utils::timeNowDate();
int step = 600;
int N = 86400 / step;
int y = a;
for (int i = 0; i <= N; ++i) {
int t = t0 + i * step * 1000;
y = std::floor((y + Utils::random(0, 20) - 10) * 100) / 100;
QVariantMap item;
item["name"] = t;
item["value"] = QVariantList {t, y};
d << item;
}
return d;
}
// 获取一天的发电功率
QVariantList MyWebHandler::getStatisticPowerDay()
{
static auto tempData = RandCurveDataDay(500, 600);
return tempData;
}
// 获取一天的辐照度
QVariantList MyWebHandler::getStatisticIrradianceDay()
{
static auto tempData = RandCurveDataDay(500, 600);
return tempData;
}
QVariantList MyWebHandler::getCurveDataDay(int a, int b)
{
return RandCurveDataDay(a, b);
}

View File

@@ -129,9 +129,12 @@ public slots:
QVariantMap getStatisticTotal();
// 获取按天统计数据
QVariantList getStatisticDay(const QString& startDate, int nday=7);
// 获取一天的
// 获取一天的发电功率
QVariantList getStatisticPowerDay();
// 获取一天的辐照度
QVariantList getStatisticIrradianceDay();
QVariantList getCurveDataDay(int a, int b);
public:
QString nativeText_;