Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SigerCalculation
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TCS-eConfigTool
SigerCalculation
Commits
ea5b7910
Commit
ea5b7910
authored
Nov 27, 2025
by
lvshi.gong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改随机森林的训练逻辑
parent
b4f5c5a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
29 deletions
+43
-29
RamdomForestCalculate.cpp
SigerCalculation/RadomForestSAC/RamdomForestCalculate.cpp
+42
-29
RamdomForestCalculate.h
SigerCalculation/RadomForestSAC/RamdomForestCalculate.h
+1
-0
No files found.
SigerCalculation/RadomForestSAC/RamdomForestCalculate.cpp
View file @
ea5b7910
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
//发送给流式的消息
//发送给流式的消息
RamdomForestCalculate
::
RamdomForestCalculate
(
QObject
*
parent
)
RamdomForestCalculate
::
RamdomForestCalculate
(
QObject
*
parent
)
{
{
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"Hello RamdomForestCalculate "
);
QString
a
=
"算法模块开始运行"
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"{}"
,
a
.
toStdString
());
qRegisterMetaType
<
Dc_SacData
>
(
"Dc_SacData"
);
qRegisterMetaType
<
Dc_SacData
>
(
"Dc_SacData"
);
...
@@ -22,25 +23,33 @@ RamdomForestCalculate::RamdomForestCalculate(QObject *parent)
...
@@ -22,25 +23,33 @@ RamdomForestCalculate::RamdomForestCalculate(QObject *parent)
QString
dbPath
=
QString
(
"/home/pi/SigerTMS/stream/SAC/%1.db"
).
arg
(
"RamdomForestFeatureValue"
);
QString
dbPath
=
QString
(
"/home/pi/SigerTMS/stream/SAC/%1.db"
).
arg
(
"RamdomForestFeatureValue"
);
QList
<
SACRecord
>
record
=
queryRecordsByLabel
(
dbPath
,
0
);
QList
<
SACRecord
>
record
=
queryRecordsByLabel
(
dbPath
,
0
);
std
::
vector
<
std
::
vector
<
float
>>
FearValues
;
if
(
record
.
size
()
!=
0
)
std
::
vector
<
int
>
TypeValues
;
{
DealRecord
(
record
,
FearValues
,
TypeValues
);
IfHaveModel
=
true
;
Classifier
->
train
(
FearValues
,
TypeValues
,
0.2
f
,
100
);
std
::
vector
<
std
::
vector
<
float
>>
FearValues
;
std
::
vector
<
int
>
TypeValues
;
DealRecord
(
record
,
FearValues
,
TypeValues
);
Classifier
->
train
(
FearValues
,
TypeValues
,
0.2
f
,
100
);
}
//连接信号和槽函数
//连接信号和槽函数
QObject
::
connect
(
m_tcpServerManager
,
&
TcpServerManager
::
getdc_sacdata
,
QObject
::
connect
(
m_tcpServerManager
,
&
TcpServerManager
::
getdc_sacdata
,
[
=
](
const
Dc_SacData
&
sac_data
)
{
[
=
](
const
Dc_SacData
&
sac_data
)
{
qDebug
()
<<
"收到 dc_sacdata 信号"
;
qDebug
()
<<
"Source:"
<<
sac_data
.
source
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"收到 dc_sacdata 信号"
);
qDebug
()
<<
"SacFile:"
<<
sac_data
.
sacFile
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"Source:{}"
,
sac_data
.
source
.
toStdString
());
qDebug
()
<<
"Target:"
<<
sac_data
.
target
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"SacFile:{}"
,
sac_data
.
sacFile
.
toStdString
());
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"Target:{}"
,
sac_data
.
target
.
toStdString
());
Save_SACDATA
(
sac_data
);
// 现在可以识别了
Save_SACDATA
(
sac_data
);
// 现在可以识别了
});
});
//连接TMS信号和槽函数
//连接TMS信号和槽函数
QObject
::
connect
(
m_tcpServerManager
,
&
TcpServerManager
::
TMSTrain
,
QObject
::
connect
(
m_tcpServerManager
,
&
TcpServerManager
::
TMSTrain
,
[
=
]()
{
[
=
]()
{
qDebug
()
<<
"收到 TMS 信号"
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"收到 TMS 信号"
);
IfHaveModel
=
true
;
Retrain
();
Retrain
();
//重新训练
//重新训练
});
});
...
@@ -53,10 +62,10 @@ void RamdomForestCalculate::SendStreamAlarminfo(const StreamInfo &alarmInfo)
...
@@ -53,10 +62,10 @@ void RamdomForestCalculate::SendStreamAlarminfo(const StreamInfo &alarmInfo)
// 统一的清理函数
// 统一的清理函数
auto
cleanup
=
[
client
]()
{
auto
cleanup
=
[
client
]()
{
static
bool
cleaned
=
false
;
// 静态变量确保只清理一次
static
bool
cleaned
=
false
;
// 静态变量确保只清理一次
收到 TMS 信号
if
(
!
cleaned
)
{
if
(
!
cleaned
)
{
cleaned
=
true
;
cleaned
=
true
;
qDebug
()
<<
"清理客户端资源"
;
//
qDebug() << "清理客户端资源";
client
->
disconnectFromServer
();
client
->
disconnectFromServer
();
QTimer
::
singleShot
(
0
,
client
,
&
QObject
::
deleteLater
);
// 延迟删除确保安全
QTimer
::
singleShot
(
0
,
client
,
&
QObject
::
deleteLater
);
// 延迟删除确保安全
}
}
...
@@ -74,7 +83,7 @@ void RamdomForestCalculate::SendStreamAlarminfo(const StreamInfo &alarmInfo)
...
@@ -74,7 +83,7 @@ void RamdomForestCalculate::SendStreamAlarminfo(const StreamInfo &alarmInfo)
message
[
"endIds"
]
=
alarmInfo
.
endIds
;
message
[
"endIds"
]
=
alarmInfo
.
endIds
;
client
->
sendMessage
(
message
);
client
->
sendMessage
(
message
);
qDebug
()
<<
"消息发送完成"
;
SPDLOG_LOGGER_DEBUG
(
spdlog
::
get
(
"logger"
),
"发送给流式告警信息成功"
)
;
// 发送完成后立即开始清理
// 发送完成后立即开始清理
cleanup
();
cleanup
();
...
@@ -173,24 +182,28 @@ int RamdomForestCalculate::Save_SACDATA(const Dc_SacData &sacdata)
...
@@ -173,24 +182,28 @@ int RamdomForestCalculate::Save_SACDATA(const Dc_SacData &sacdata)
//step2: 预测报警
//step2: 预测报警
//std::string data;
//std::string data;
qDebug
()
<<
"x "
<<
x
;
qDebug
()
<<
"x "
<<
x
;
std
::
vector
<
float
>
test_sample
(
10
,
0
);
//用逗号分割
if
(
IfHaveModel
)
QStringList
list
=
x
.
split
(
','
);
{
std
::
vector
<
float
>
test_sample
(
10
,
0
);
//转成 float 并存到 vector
//用逗号分割
for
(
const
QString
&
s
:
list
)
{
QStringList
list
=
x
.
split
(
','
);
bool
ok
=
false
;
float
f
=
s
.
toFloat
(
&
ok
);
//转成 float 并存到 vector
if
(
ok
)
{
for
(
const
QString
&
s
:
list
)
{
test_sample
.
push_back
(
f
);
bool
ok
=
false
;
}
else
{
float
f
=
s
.
toFloat
(
&
ok
);
std
::
cerr
<<
"转换失败: "
<<
s
.
toStdString
()
<<
std
::
endl
;
if
(
ok
)
{
test_sample
.
push_back
(
f
);
}
else
{
std
::
cerr
<<
"转换失败: "
<<
s
.
toStdString
()
<<
std
::
endl
;
}
}
}
}
double
pred
=
Classifier
->
predict
(
test_sample
);
double
pred
=
Classifier
->
predict
(
test_sample
);
cout
<<
"测试样本预测类别: "
<<
pred
<<
endl
;
cout
<<
"测试样本预测类别: "
<<
pred
<<
endl
;
StreamInfo
(
pred
,
sacdata
.
target
,
sacdata
.
startIds
,
sacdata
.
endIds
);
StreamInfo
(
pred
,
sacdata
.
target
,
sacdata
.
startIds
,
sacdata
.
endIds
);
}
//step3: 存入数据库
//step3: 存入数据库
std
::
string
data
=
QString
(
std
::
string
data
=
QString
(
...
...
SigerCalculation/RadomForestSAC/RamdomForestCalculate.h
View file @
ea5b7910
...
@@ -86,6 +86,7 @@ private:
...
@@ -86,6 +86,7 @@ private:
TcpServerManager
*
m_tcpServerManager
;
TcpServerManager
*
m_tcpServerManager
;
RandomForestClassifier
*
Classifier
;
RandomForestClassifier
*
Classifier
;
bool
IfHaveModel
=
false
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment