2025-06-13T15:55:17

This commit is contained in:
yuntang 2025-06-13 15:55:18 +08:00
parent 4f42759df8
commit bc9a3249c3
8 changed files with 94 additions and 176 deletions

View File

@ -128,6 +128,7 @@ void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex
void XlsxHandler::writeExperimentFile(const QString filePath)
{
logde<<"write file...";
#if 0
if(Global::_curveExperimentDataVtr.empty()){
logde<<"_curveExperimentDataVtr empty...";
@ -250,11 +251,13 @@ void XlsxHandler::writeExperimentFile(const QString filePath)
row++;
// phase data.
// logde<<"Global::_curveExperimentDataVtr size:"
// <<Global::_curveExperimentDataVtr.size();
const QVector<Global::ExperimentData>& edVtr =
QVector<Global::ExperimentData> edVtr =
Global::_curveExperimentDataVtr.at(i).dataVtr;
if(Global::_smoothnessFlag){
edVtr = Global::_curveExperimentDataVtr.at(i).smoothDataVtr;
}
// phase data size.
dataSizeRow = row;
xlsx.write(row , 1, ConPhaseDataSize);
@ -289,7 +292,7 @@ void XlsxHandler::writeExperimentFile(const QString filePath)
}
void XlsxHandler:: appendAnalysisOperation(const QString filePath)
void XlsxHandler:: xlsxFileAppendAnalysisOperation(const QString filePath)
{
QXlsx::Document* xlsx = openXlsxFile(_currentFilePath);
if(!xlsx){
@ -594,15 +597,15 @@ void XlsxHandler::writeSmoothnessFile(const QString filePath)
// Write phase data.
logde<<"curve file vtr size:"<<Global::_curveFileDataVtr.size();
QVector<Global::PhaseTotalInfo>& phaseVtr =
Global::_curveFileDataVtr.first().phaseTotalVtr;
QVector<Global::PhaseTotalInfo>& phaseVtr =
Global::_curveFileDataVtr.first().phaseTotalVtr;
int dataSizeRow = 0;
// logde<<"phase vtr size:"<<ei.phaseVtr.size();
// logde<<"phase vtr size:"<<ei.phaseVtr.size();
for(int i = 0; i < phaseVtr.size();i++){
logde<<"phase index:"<<i;
// const Phase& phase = ei.phaseVtr.at(i);
// const Phase& phase = ei.phaseVtr.at(i);
Phase phase = phaseVtr.at(i).phase;
@ -693,34 +696,6 @@ void XlsxHandler::writeSmoothnessFile(const QString filePath)
logde<<"Save xlsx failed.";
return ;
}
#if 0
if(Global::_curveFileDataVtr.empty()){
// Load experiment data.
logde<<"experiment vtr size:"<<Global::_curveExperimentDataVtr.size();
for(Global::CurveExperimentData& ced:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(ced.curve)){
logde<<"load experiment data.";
// PointCalculate::setAnalysisData(ced.dataVtr);
dataVtr = ced.dataVtr;
Global::_smoothnessFileName = ced.fileName;
break;
}
}
}else{
// Load xlsx file data.
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
// PointCalculate::setAnalysisData(pti.dataVtr);
dataVtr = pti.dataVtr;
Global::_smoothnessFileName = cfd.fileName;
break;
}
}
}
}
#endif
}
void XlsxHandler::writeAnalysisiFile(const QString filePath)

View File

@ -25,7 +25,7 @@ namespace XlsxHandler {
void readAnalysisOperation(QXlsx::Worksheet*,int& startLineIndex,Global::CurveFileData&);
void writeExperimentFile(const QString filePath);
void appendAnalysisOperation(const QString filePath);
void xlsxFileAppendAnalysisOperation(const QString filePath);
void writeAnalysisiFile(const QString filePath);
void writeAnalysisOperationDetail(QXlsx::Document*doc,const int row);

View File

@ -33,8 +33,9 @@ const double DefaultParamter = 8.177;
const double OnsetAndEndSetRate = 0.01;
//curve object name
const QString objectNameExperiemnt("experiment");
//const QString objectNameSmoothness("smoothness");
const QString ObjectNameExperiemnt("experiment");
const QString ObjectNameSmooth("smooth");
const QString Separator("___");
//
enum LanguageType{
Chinese,
@ -91,8 +92,9 @@ struct ExperimentInfo{
struct PhaseTotalInfo{
int phaseIndex; // from 1 to 6.
Phase phase;
QVector<ExperimentData> dataVtr;
QCPCurve * curve;
QVector<ExperimentData> dataVtr;
QVector<ExperimentData> smoothDataVtr;
};
struct CurveFileData{
@ -106,6 +108,7 @@ struct CurveExperimentData{
QCPCurve * curve;
QString fileName; // discard
QVector<Global::ExperimentData> dataVtr;
QVector<ExperimentData> smoothDataVtr;
};
// Soft mode.
@ -118,6 +121,7 @@ extern ExperimentInfo _experimentInfo;
extern QVector<CurveExperimentData> _curveExperimentDataVtr;
extern CurveExperimentData* _currentCurveExperimentDataPtr;
extern bool _smoothnessFlag;
#if 0
// Smoothness data
extern QVector<CurveExperimentData> _curveSmoothnessDataVtr;

View File

@ -135,6 +135,7 @@ void MainWindow::connections()
#endif
// mode
// connect(Global::instance(), &Global::sigModeModify,
// _centralWidget, &CentralWidget::slotModeModify);
@ -161,7 +162,7 @@ void MainWindow::connections()
connect(_specificHeatComparisonMethodForm,&SpecificHeatComparisonMethodForm::sigDrawCustomText,
_centralWidget,&CentralWidget::slotDrawCustomText);
//SpecificHeatComparisonMethodForm
// SpecificHeatComparisonMethodForm
connect(_eventHandler,&EventHandler::sigSetCurve,
_specificHeatComparisonMethodForm,
&SpecificHeatComparisonMethodForm::slotSetCurve);
@ -183,9 +184,7 @@ void MainWindow::setActionEnable(const bool flag)
ui->actionStart->setEnabled(true);
ui->actionStop->setEnabled(true);
ui->actionRealTimeWidget->setEnabled(true);
}
else
{
}else{
ui->actionNew->setEnabled(false);
ui->actionStart->setEnabled(false);
ui->actionStop->setEnabled(false);
@ -200,6 +199,7 @@ void MainWindow::setSubWidgetAttribute(QWidget *widget)
widget->setFixedSize(widget->geometry().width(),widget->geometry().height());
}
#if 0
bool MainWindow::saveExperimentFile(const QString fileName)
{
@ -273,25 +273,19 @@ bool MainWindow::saveFile(const QString fileName,const Global::Mode mode)
// Save file.
if(mode == Global::Mode::Analysis){
if(Global::_curveFileDataVtr.empty()){
logde<<"analysis experiemt data...";
// 分析模式下,但是文件数据为空,说明做完实验没有保存数据。
XlsxHandler::writeExperimentFile(filePath);
// XlsxHandler::writeAnalysisOperation(filePath);
}else{
logde<<"analysis xlsx data...";
// 分析模式下,直接保存从文件读取来的数据。
if(Global::_smoothnessFlag){
XlsxHandler::writeSmoothnessFile(filePath);
}else{
XlsxHandler::appendAnalysisOperation(filePath);
// 直接在xlsx文件的基础上添加分析数据。
XlsxHandler::xlsxFileAppendAnalysisOperation(filePath);
}
}
}else if(mode == Global::Mode::Experiment){
logde<<"writeFile...";
XlsxHandler::writeExperimentFile(filePath);
#if 0
// Clear data.
Global::clearExperimentData();
#endif
}
return true;
@ -301,17 +295,18 @@ void MainWindow::smoothness(const int level)
{
Global::_smoothnessFlag = true;
// process data.
QVector<Global::ExperimentData> targetDataVtr;
QVector<Global::ExperimentData> smoothDataVtr;
QString objectName;
QCPCurve ** curvePtrPtr;
if(!Global::_curveExperimentDataVtr.empty()){
for(auto & item:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(item.curve)){
smoothnessDetail(level,item.dataVtr);
smoothDataVtr = smoothnessDetail(level,item.dataVtr);
targetDataVtr = item.dataVtr;
objectName = Global::objectNameExperiemnt;
item.smoothDataVtr = smoothDataVtr;
objectName = Global::ObjectNameExperiemnt;
curvePtrPtr = &item.curve;
}
}
@ -319,20 +314,12 @@ void MainWindow::smoothness(const int level)
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
smoothnessDetail(level,pti.dataVtr);
smoothDataVtr = smoothnessDetail(level,pti.dataVtr);
pti.smoothDataVtr = smoothDataVtr;
targetDataVtr = pti.dataVtr;
objectName = cfd.fileName;
curvePtrPtr = &pti.curve;
//
#if 0
Global::ExperimentData ed;
ed.sampleTemp = 2222;
ed.dsc = 2222;
pti.dataVtr.push_back(ed);
#endif
}
}
}
@ -342,101 +329,23 @@ void MainWindow::smoothness(const int level)
_centralWidget->deleteCurrentCurve();
//
_centralWidget->addSmoothnessCurveData(targetDataVtr,objectName);
QString wholeObjectName = Global::ObjectNameSmooth + Global::Separator + objectName;
_centralWidget->addCurveData(smoothDataVtr,wholeObjectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
#if 0
// Get current data vtr;
QVector<Global::ExperimentData> dataVtr;
if(Global::_curveFileDataVtr.empty()){
// Load experiment data.
logde<<"experiment vtr size:"<<Global::_curveExperimentDataVtr.size();
for(Global::CurveExperimentData& ced:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(ced.curve)){
logde<<"load experiment data.";
// PointCalculate::setAnalysisData(ced.dataVtr);
dataVtr = ced.dataVtr;
Global::_smoothnessFileName = ced.fileName;
break;
}
}
}else{
// Load xlsx file data.
for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
// PointCalculate::setAnalysisData(pti.dataVtr);
dataVtr = pti.dataVtr;
Global::_smoothnessFileName = cfd.fileName;
break;
}
}
}
}
if(dataVtr.empty()){
return;
}
// smoothness.
Lowess::Config config;
config.smoothingFactor = level * 0.1;
config.robustnessIterations = 3;
std::vector<double> x;
std::vector<double> y;
for(Global::ExperimentData& ed:dataVtr) {
if(Global::_axisMode == Global::AxisMode::SingleY){
x.push_back(ed.sampleTemp);
}else{
x.push_back(ed.runTime);
}
y.push_back(ed.dsc);
}
logde<<"smooth start...";
std::vector<double> yest = Lowess::smooth(x, y, config);
logde<<"smooth end...";
// Delete current curve;
_centralWidget->deleteCurrentCurve();
// Add new Curve.
QVector<Global::ExperimentData> newCurveDataVtr;
for(int i = 0; i < x.size();i++){
Global::ExperimentData ed;
if(Global::_axisMode == Global::AxisMode::SingleY){
ed.sampleTemp = x.at(i);
ed.runTime = dataVtr.at(i).runTime;
}else{
ed.runTime = x.at(i);
ed.sampleTemp = dataVtr.at(i).sampleTemp;
}
ed.dsc = yest.at(i);
ed.constantTempTime = dataVtr.at(i).constantTempTime;
newCurveDataVtr.push_back(ed);
}
_centralWidget->addSmoothnessCurveData(newCurveDataVtr);
#endif
}
QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,QVector<Global::ExperimentData>& dataVtr)
QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,const QVector<Global::ExperimentData>&dataVtr)
{
Lowess::Config config;
config.smoothingFactor = level * 0.1;
config.smoothingFactor = level * 0.01;
config.robustnessIterations = 3;
std::vector<double> x;
std::vector<double> y;
for(const Global::ExperimentData& ed:dataVtr) {
for(const Global::ExperimentData& ed:dataVtr){
if(Global::_axisMode == Global::AxisMode::SingleY){
x.push_back(ed.sampleTemp);
}else{
@ -450,8 +359,8 @@ QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,QVe
std::vector<double> yest = Lowess::smooth(x, y, config);
logde<<"smooth end...";
// target data vector.
QVector<Global::ExperimentData> targetVtr;
// result data vector.
QVector<Global::ExperimentData> resultVtr;
for(int i = 0; i < x.size();i++){
Global::ExperimentData ed;
@ -466,13 +375,10 @@ QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,QVe
ed.dsc = yest.at(i);
ed.constantTempTime = dataVtr.at(i).constantTempTime;
targetVtr.push_back(ed);
resultVtr.push_back(ed);
}
dataVtr.clear();
dataVtr = targetVtr;
return targetVtr;
return resultVtr;
}
void MainWindow::smoothnessExperimentData(const int level)
@ -796,3 +702,40 @@ void MainWindow::on_actionSmoothness10_triggered()
smoothness(10);
}
void MainWindow::on_actionOriginalData_triggered()
{
Global::_smoothnessFlag = false;
// process data.
QVector<Global::ExperimentData> targetDataVtr;
QString objectName;
QCPCurve ** curvePtrPtr;
if(!Global::_curveExperimentDataVtr.empty()){
for(auto & item:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(item.curve)){
targetDataVtr = item.dataVtr;
objectName = Global::ObjectNameExperiemnt;
curvePtrPtr = &item.curve;
}
}
}else{
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
targetDataVtr = pti.dataVtr;
objectName = cfd.fileName;
curvePtrPtr = &pti.curve;
}
}
}
}
//
_centralWidget->deleteCurrentCurve();
_centralWidget->addCurveData(targetDataVtr,objectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
}

View File

@ -109,6 +109,8 @@ private slots:
void on_actionSmoothness9_triggered();
void on_actionSmoothness10_triggered();
void on_actionOriginalData_triggered();
private:
void setAnalysisData();
void connections();
@ -118,7 +120,7 @@ private:
bool saveFile(const QString fileName,const Global::Mode);
void smoothness(const int level);
QVector<Global::ExperimentData> smoothnessDetail(const int level,QVector<Global::ExperimentData>&);
QVector<Global::ExperimentData> smoothnessDetail(const int level,const QVector<Global::ExperimentData>&);
void smoothnessExperimentData(const int level);
private:

View File

@ -89,6 +89,7 @@
<addaction name="actionEnthalpyCorrectionEdit"/>
<addaction name="actionEnthalpyCorrectionSelection"/>
<addaction name="menu_9"/>
<addaction name="actionOriginalData"/>
</widget>
<widget class="QMenu" name="menu_6">
<property name="title">
@ -410,6 +411,11 @@
<string>10级</string>
</property>
</action>
<action name="actionOriginalData">
<property name="text">
<string>原始数据</string>
</property>
</action>
</widget>
<resources>
<include location="images.qrc"/>

View File

@ -129,13 +129,12 @@ void CentralWidget::deleteCurrentCurve()
slotDelCurve(_currentCurve);
}
void CentralWidget::addSmoothnessCurveData(
void CentralWidget::addCurveData(
const QVector<ExperimentData> &dataVtr,const QString objectName)
{
PointCalculate::setAnalysisData(dataVtr);
// Load data.
// QVector<Global::ExperimentData> dataVtr;
QVector<double> tVtr,xVtr, yVtr;
int index = 0;
for (const Global::ExperimentData &ed : dataVtr)
@ -174,8 +173,6 @@ void CentralWidget::addSmoothnessCurveData(
minMaxYAxisPair.first,minMaxYAxisPair.second);
_customPlot->yAxis->setRange(newYAxisPair.first ,
newYAxisPair.second);
//
// pti.curve = _currentCurve;
// Add analysis operation data.
#if 0
@ -189,15 +186,6 @@ void CentralWidget::addSmoothnessCurveData(
// Refresh ui.
_customPlot->replot();
#if 0
// Save data.
CurveExperimentData ced;
ced.curve = _currentCurve;
ced.dataVtr = dataVtr;
// Global::_curveSmoothnessDataVtr.push_back(ced);
#endif
}
void CentralWidget::setAnalysisMode(const AnalysisMode mode)
@ -268,7 +256,7 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd)
if(!_currentCurve){
logde<<"_currentCurve is nullptr";
_currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis);
_currentCurve->setObjectName(Global::objectNameExperiemnt);
_currentCurve->setObjectName(Global::ObjectNameExperiemnt);
}
// logde<<"temp:"<<cd.sample_temp<<",dsc:"<<cd.dsc;

View File

@ -42,7 +42,7 @@ public:
bool isCurrentCurve(QCPCurve* curve);
void deleteCurrentCurve();
void addSmoothnessCurveData(const QVector<Global::ExperimentData> &,const QString objectName);
void addCurveData(const QVector<Global::ExperimentData> &,const QString objectName);
QCPCurve * getCurrentCurve(){return _currentCurve;}
signals: