2025-06-23T10:42:13

This commit is contained in:
yuntang 2025-06-23 10:42:15 +08:00
parent 0a359b4645
commit 2b879ef928
46 changed files with 71 additions and 19 deletions

Binary file not shown.

View File

@ -0,0 +1,4 @@
[2025-06-23 08:57:37,833] main...
[2025-06-23 08:57:37,835] config file existed.
[2025-06-23 08:57:37,872] version:1.0.5.0
[2025-06-23 08:57:37,898] setEventHandlerEnable...0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,7 +9,7 @@ CONFIG+=precompile_header
PRECOMPILED_HEADER=stable.h PRECOMPILED_HEADER=stable.h
# #
VERSION = 1.0.5 VERSION = 1.0.6
# 设置目标文件名,包含版本号 # 设置目标文件名,包含版本号
TARGET = DSCAnalysisTool_$${VERSION} TARGET = DSCAnalysisTool_$${VERSION}

View File

@ -60,7 +60,8 @@ void OITAutoAnalysis::analysis()
if((ed.runTime > Global::_OITAutoAnalysisCoefficient) if((ed.runTime > Global::_OITAutoAnalysisCoefficient)
&& (ed.dsc - phase2FirstData.dsc > Global::_OITAutoAnalysisThreshold)){ && (ed.dsc - phase2FirstData.dsc > Global::_OITAutoAnalysisThreshold)){
// //
double x1 = phase2FirstData.runTime; // double x1 = phase2FirstData.runTime;
double x1 = ConDefaultXValue;
double x2 = ed.runTime; double x2 = ed.runTime;
emit sigExperimentStop(x1,x2); emit sigExperimentStop(x1,x2);

View File

@ -7,6 +7,8 @@ class OITAutoAnalysis : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
const double ConDefaultXValue = -1.0;
explicit OITAutoAnalysis(QObject *parent = nullptr); explicit OITAutoAnalysis(QObject *parent = nullptr);
static OITAutoAnalysis* getInstance() static OITAutoAnalysis* getInstance()

View File

@ -4,6 +4,7 @@
#include "logger.h" #include "logger.h"
#include "global.h" #include "global.h"
#include "confighandler.h" #include "confighandler.h"
#include "oitautoanalysis.h"
QVector<Global::ExperimentData>PointCalculate:: _dataVtr; QVector<Global::ExperimentData>PointCalculate:: _dataVtr;
QPointF PointCalculate::_peakPoint; QPointF PointCalculate::_peakPoint;
@ -933,6 +934,7 @@ Global::ExperimentData PointCalculate::findOnSetDataByTime(const double x1, cons
Global::ExperimentData PointCalculate::getOITStartData(const double x1,const double x2) Global::ExperimentData PointCalculate::getOITStartData(const double x1,const double x2)
{ {
Global::ExperimentData startEd = _dataVtr.first(); Global::ExperimentData startEd = _dataVtr.first();
logde<<"startEd phase index:"<<startEd.phaseIndex; logde<<"startEd phase index:"<<startEd.phaseIndex;
@ -1008,14 +1010,15 @@ PointCalculate::calculateOITStartAndEndDataByTime(const double x1, const double
{ {
// 获取起点数据。 // 获取起点数据。
Global::ExperimentData startData = getOITStartData(x1,x2); Global::ExperimentData startData = getOITStartData(x1,x2);
//
// 计算OIT结束数据需根据实际逻辑实现 ExperimentData selectedData = getClosestDataByTime(x1);
Global::ExperimentData endData; if(Global::isEqual(OITAutoAnalysis::getInstance()->ConDefaultXValue,x1)){
selectedData = calculateMedianOIT().second;
}
QPair<Global::ExperimentData,Global::ExperimentData> maxDiffDataPair = QPair<Global::ExperimentData,Global::ExperimentData> maxDiffDataPair =
calculateMaxDiffDataByTime(x1,x2); calculateMaxDiffDataByTime(x1,x2);
Global::ExperimentData endData;
ExperimentData selectedData = getClosestDataByTime(x1);
// calculate intersection point. // calculate intersection point.
QPointF selectedPoint1(selectedData.runTime,selectedData.dsc); QPointF selectedPoint1(selectedData.runTime,selectedData.dsc);
@ -1100,3 +1103,30 @@ PointCalculate::calculateMaxDiffDataByTime(
return qMakePair(currentPoint,lastPoint); return qMakePair(currentPoint,lastPoint);
#endif #endif
} }
// 返回值: first=true表示计算成功second是中位数
std::pair<bool, Global::ExperimentData> PointCalculate::calculateMedianOIT(){
ExperimentData ed;
if (_dataVtr.empty()) return std::make_pair(false, ed);
// 创建数据副本用于排序
std::vector<ExperimentData> sortedData(_dataVtr.begin(),_dataVtr.end());
// 定义排序比较函数使用value成员进行比较
auto compare = [](const ExperimentData& a, const ExperimentData& b) {
return a.dsc < b.dsc;
};
// 对数据进行排序
std::sort(sortedData.begin(), sortedData.end(), compare);
// 计算中位数
size_t n = sortedData.size();
if (n % 2 == 0) {
// 数据个数为偶数,中位数是中间两个数的平均值
return std::make_pair(true, sortedData[n/2 - 1]);
} else {
// 数据个数为奇数,中位数是中间的数
return std::make_pair(true, sortedData[n/2]);
}
}

View File

@ -52,7 +52,7 @@ ExperimentData findOnSetDataByTime(const double x1,const double x2);
ExperimentData findEndSetDataByTime(const double x1,const double x2); ExperimentData findEndSetDataByTime(const double x1,const double x2);
ExperimentData getOITStartData(const double x1,const double x2); ExperimentData getOITStartData(const double x1,const double x2);
std::pair<bool, ExperimentData> calculateMedianOIT();
// text format // text format
QString textFormatPeakPoint(const float enthalpyValue, QString textFormatPeakPoint(const float enthalpyValue,
const float peakValue, const float peakValue,

View File

@ -149,6 +149,11 @@ bool isZero(double value, double epsilon) {
return std::abs(value) < epsilon; return std::abs(value) < epsilon;
} }
bool isEqual(const double a, const double b) {
const double tolerance = 1e-5; // 容差值,可以根据需要调整
return std::fabs(a - b) < tolerance;
}
QString getFileName(const QString filePath) QString getFileName(const QString filePath)
{ {
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);

View File

@ -180,7 +180,9 @@ QString converDoubleToStr(const double);
void quadraticLeastSquaresFit(double x[], double y[], int n, double coeff[]); void quadraticLeastSquaresFit(double x[], double y[], int n, double coeff[]);
double findNegativeStartPoint(double m, double b, double start, double end); double findNegativeStartPoint(double m, double b, double start, double end);
bool isZero(double value, double epsilon = 1e-9); bool isZero(double value, double epsilon = 1e-9);
bool isEqual(const double a,const double b);
QString getFileName(const QString filePath); QString getFileName(const QString filePath);
}; };
#endif // GLOBAL_H #endif // GLOBAL_H

View File

@ -258,6 +258,8 @@ bool MainWindow::saveAnalysisFile(const QString fileName)
bool MainWindow::saveFile(const QString fileName,const Global::Mode mode, bool MainWindow::saveFile(const QString fileName,const Global::Mode mode,
QString& finalFileName,const bool autoSaveFlag) QString& finalFileName,const bool autoSaveFlag)
{ {
logde<<"save file...";
QString localFileName = fileName; QString localFileName = fileName;
if(fileName.isEmpty()){ if(fileName.isEmpty()){
localFileName = "new"; localFileName = "new";
@ -460,11 +462,15 @@ void MainWindow::on_actionStop_triggered()
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop); QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop);
SerialPort::instance()->slotSendData(ba); SerialPort::instance()->slotSendData(ba);
#if 1 // Set software mode to analysis.
_manuallyStopTheExperimentFlag = true;
logde<<"_manuallyStopTheExperimentFlag:"<<_manuallyStopTheExperimentFlag;
Global::_mode = Global::Mode::Analysis;
// Save data. // Save data.
// if(saveExperimentFile(Global::_experimentInfo.sampleName)){ #if 1
// _leftWidget->reloadFileName(); logde<<"on_actionStop_triggered saveFile ...";
// }
QString finalFileName; QString finalFileName;
if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){ if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){
@ -475,10 +481,6 @@ void MainWindow::on_actionStop_triggered()
} }
#endif #endif
// Set software mode to analysis.
Global::_mode = Global::Mode::Analysis;
_manuallyStopTheExperimentFlag = true;
} }
} }
@ -520,12 +522,15 @@ void MainWindow::on_actionRealTimeWidget_triggered()
void MainWindow::slotSaveExperimentalDataMsgBox() void MainWindow::slotSaveExperimentalDataMsgBox()
{ {
logde<<"_manuallyStopTheExperimentFlag:"<<_manuallyStopTheExperimentFlag;
if(_manuallyStopTheExperimentFlag){ if(_manuallyStopTheExperimentFlag){
logde<<"_manuallyStopTheExperimentFlag..."; logde<<"_manuallyStopTheExperimentFlag...";
return; return;
} }
// auto save file. // auto save file.
logde<<"slotSaveExperimentalDataMsgBox saveFile ...";
QString finalFileName; QString finalFileName;
if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){ if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){
_leftWidget->reloadFileName(); _leftWidget->reloadFileName();

View File

@ -209,20 +209,23 @@ void SerialPort::updateStatus(const CommonData &cd)
emit sigUpdateStatusbarMsg(msg); emit sigUpdateStatusbarMsg(msg);
#if 1
// If save experiment data. // If save experiment data.
static Global::Mode preMode = Global::Mode::Analysis; static Global::Mode preMode = Global::Mode::Analysis;
bool sendSignalFlag = false; bool sendSaveSignalFlag = false;
if(Global::_mode != preMode){ if(Global::_mode != preMode){
if(preMode == Global::Mode::Experiment if(preMode == Global::Mode::Experiment
&& Global::_mode == Global::Mode::Analysis){ && Global::_mode == Global::Mode::Analysis){
sendSignalFlag = true; sendSaveSignalFlag = true;
} }
preMode = Global::_mode; preMode = Global::_mode;
} }
if(sendSignalFlag && !Global::_OITAutoAnalysisModeFlag){
if(sendSaveSignalFlag && !Global::_OITAutoAnalysisModeFlag){
emit sigSaveExperimentalDataMsgBox(); emit sigSaveExperimentalDataMsgBox();
} }
#endif
} }
void SerialPort::commonDataParser(const int dataLength, const u16 addr, void SerialPort::commonDataParser(const int dataLength, const u16 addr,