diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp index 518aa29..9d5546e 100644 --- a/src/data/xlsxhandler.cpp +++ b/src/data/xlsxhandler.cpp @@ -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:" - // <& edVtr = + QVector 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:"<& phaseVtr = - Global::_curveFileDataVtr.first().phaseTotalVtr; + QVector& phaseVtr = + Global::_curveFileDataVtr.first().phaseTotalVtr; int dataSizeRow = 0; -// logde<<"phase vtr size:"<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) diff --git a/src/data/xlsxhandler.h b/src/data/xlsxhandler.h index f613f88..ba04262 100644 --- a/src/data/xlsxhandler.h +++ b/src/data/xlsxhandler.h @@ -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); diff --git a/src/global.h b/src/global.h index 9a8e3f7..3c7dd47 100644 --- a/src/global.h +++ b/src/global.h @@ -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 dataVtr; QCPCurve * curve; + QVector dataVtr; + QVector smoothDataVtr; }; struct CurveFileData{ @@ -106,6 +108,7 @@ struct CurveExperimentData{ QCPCurve * curve; QString fileName; // discard QVector dataVtr; + QVector smoothDataVtr; }; // Soft mode. @@ -118,6 +121,7 @@ extern ExperimentInfo _experimentInfo; extern QVector _curveExperimentDataVtr; extern CurveExperimentData* _currentCurveExperimentDataPtr; extern bool _smoothnessFlag; + #if 0 // Smoothness data extern QVector _curveSmoothnessDataVtr; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8b16c9c..0f3e488 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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 targetDataVtr; + QVector 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 dataVtr; - - if(Global::_curveFileDataVtr.empty()){ - // Load experiment data. - logde<<"experiment vtr size:"<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 x; - std::vector 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 yest = Lowess::smooth(x, y, config); - logde<<"smooth end..."; - - // Delete current curve; - _centralWidget->deleteCurrentCurve(); - - // Add new Curve. - QVector 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 MainWindow::smoothnessDetail(const int level,QVector& dataVtr) +QVector MainWindow::smoothnessDetail(const int level,const QVector&dataVtr) { Lowess::Config config; - config.smoothingFactor = level * 0.1; + config.smoothingFactor = level * 0.01; config.robustnessIterations = 3; std::vector x; std::vector 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 MainWindow::smoothnessDetail(const int level,QVe std::vector yest = Lowess::smooth(x, y, config); logde<<"smooth end..."; - // target data vector. - QVector targetVtr; + // result data vector. + QVector resultVtr; for(int i = 0; i < x.size();i++){ Global::ExperimentData ed; @@ -466,13 +375,10 @@ QVector 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 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(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 49e55e1..c6386e6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 smoothnessDetail(const int level,QVector&); + QVector smoothnessDetail(const int level,const QVector&); void smoothnessExperimentData(const int level); private: diff --git a/src/mainwindow.ui b/src/mainwindow.ui index b7bc2bb..530868b 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -89,6 +89,7 @@ + @@ -410,6 +411,11 @@ 10级 + + + 原始数据 + + diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index a7347c8..fee529f 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -129,13 +129,12 @@ void CentralWidget::deleteCurrentCurve() slotDelCurve(_currentCurve); } -void CentralWidget::addSmoothnessCurveData( +void CentralWidget::addCurveData( const QVector &dataVtr,const QString objectName) { PointCalculate::setAnalysisData(dataVtr); // Load data. - // QVector dataVtr; QVector 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:"< &,const QString objectName); + void addCurveData(const QVector &,const QString objectName); QCPCurve * getCurrentCurve(){return _currentCurve;} signals: