优化数据处理任务

This commit is contained in:
徐海 2026-03-20 15:45:18 +08:00
parent c558e12697
commit 1ba84d36ee
13 changed files with 275 additions and 124 deletions

View File

@ -62,16 +62,24 @@ void DataProcessTask::run()
if (!IsValidSetWorkParameters()) { if (!IsValidSetWorkParameters()) {
return; return;
} }
bool task_ok = processTask();
if (!processTask()) {
return;
}
if ((GetFinishedNotifier() != nullptr) && (GetFinishedNotifierProcess() != nullptr)) { if ((GetFinishedNotifier() != nullptr) && (GetFinishedNotifierProcess() != nullptr)) {
QMetaObject::invokeMethod(_finished_notifier, _finished_notifier_process, Qt::QueuedConnection, Q_ARG(QString, _project_name)); QMetaObject::invokeMethod(
_finished_notifier,
_finished_notifier_process,
Qt::QueuedConnection,
Q_ARG(bool, task_ok),
Q_ARG(QString, _project_name),
Q_ARG(QVariant, _task_result_data)
);
} }
} }
void DataProcessTask::updateTaskResultData(const QVariant &task_result_data)
{
this->_task_result_data = task_result_data;
}
void ParticleDataTask::SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename) void ParticleDataTask::SetAllChannelParticleDataFilename(const QString& all_channel_particle_data_filename)
{ {
this->_all_channel_particle_data_filename = all_channel_particle_data_filename; this->_all_channel_particle_data_filename = all_channel_particle_data_filename;
@ -336,7 +344,8 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData()
// 更新项目模型中的所有通道粒子总计数数据文件名 // 更新项目模型中的所有通道粒子总计数数据文件名
// project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename); // project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename);
} }
const QString& info = QStringLiteral(u"所有通道粒子计数处理完成.");
LOG_INFO(info);
return ret_ok; return ret_ok;
} }
@ -389,17 +398,16 @@ std::vector<std::string> splitFile(const std::string& input_file, size_t chunk_s
> reader(input_file); > reader(input_file);
reader.read_header(io::ignore_extra_column, board_id_str, channel_id_str, address_str, time_str); reader.read_header(io::ignore_extra_column, board_id_str, channel_id_str, address_str, time_str);
int chunkIndex = 0; int chunk_index = 0;
while (true) { while (true) {
std::vector<CsvRow> rows; std::vector<CsvRow> rows;
size_t currentSize = 0; size_t current_size = 0;
uint board_id; uint board_id;
uint channel_id; uint channel_id;
uint address; uint address;
unsigned long long time; unsigned long long time;
while (reader.read_row(board_id, channel_id, address, time)) { while (reader.read_row(board_id, channel_id, address, time)) {
CsvRow row; CsvRow row;
row.board_id = board_id; row.board_id = board_id;
@ -408,63 +416,56 @@ std::vector<std::string> splitFile(const std::string& input_file, size_t chunk_s
row.time = time; row.time = time;
// Estimate row size // Estimate row size
currentSize += std::to_string(board_id).size() + std::to_string(channel_id).size() + std::to_string(address).size() + std::to_string(time).size() + 4; // +4 for commas current_size += std::to_string(board_id).size() + std::to_string(channel_id).size() + std::to_string(address).size() + std::to_string(time).size() + 4;
if (current_size > chunk_size && !rows.empty()) {
if (currentSize > chunk_size && !rows.empty()) {
break; break;
} }
rows.push_back(row); rows.push_back(row);
} }
if (rows.empty()) if (rows.empty())
break; break;
std::sort(rows.begin(), rows.end(), [](const CsvRow& a, const CsvRow& b) { std::sort(rows.begin(), rows.end(), [](const CsvRow& a, const CsvRow& b) {
return a.time < b.time; return a.time < b.time;
}); });
std::string chunk_file = input_file + ".chunk" + std::to_string(chunk_index);
std::string chunkFile = input_file + ".chunk" + std::to_string(chunkIndex); std::ofstream outFile(chunk_file);
std::ofstream outFile(chunkFile);
for (const auto& row : rows) { for (const auto& row : rows) {
outFile << row.board_id << "," << row.channel_id << "," << row.address << "," << row.time << "\n"; outFile << row.board_id << "," << row.channel_id << "," << row.address << "," << row.time << "\n";
} }
outFile.close(); outFile.close();
chunks.push_back(chunk_file);
chunks.push_back(chunkFile); chunk_index++;
chunkIndex++;
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
throw(e); throw(e);
} }
return chunks; return chunks;
} }
void mergeChunks(const std::vector<std::string>& chunks, const std::string& output_file) void mergeChunks(const std::vector<std::string>& chunks, const std::string& output_file)
{ {
std::vector<std::unique_ptr<io::CSVReader<4>>> chunkReaders; std::vector<std::unique_ptr<io::CSVReader<4>>> chunk_readers;
std::priority_queue<CsvRow> minHeap; std::priority_queue<CsvRow> min_heap;
for (const auto& chunk : chunks) { for (const auto& chunk : chunks) {
auto reader = std::make_unique<io::CSVReader<4>>(chunk); auto reader = std::make_unique<io::CSVReader<4>>(chunk);
chunkReaders.push_back(std::move(reader)); chunk_readers.push_back(std::move(reader));
} }
for (size_t i = 0; i < chunkReaders.size(); i++) { for (size_t i = 0; i < chunk_readers.size(); i++) {
uint board_id; uint board_id;
uint channel_id; uint channel_id;
uint address; uint address;
unsigned long long time; unsigned long long time;
if (chunkReaders[i]->read_row(board_id, channel_id, address, time)) { if (chunk_readers[i]->read_row(board_id, channel_id, address, time)) {
CsvRow row; CsvRow row;
row.board_id = board_id; row.board_id = board_id;
row.channel_id = channel_id; row.channel_id = channel_id;
row.address = address; row.address = address;
row.time = time; row.time = time;
row.chunk_index = i; row.chunk_index = i;
minHeap.push(row); min_heap.push(row);
} }
} }
@ -475,35 +476,33 @@ void mergeChunks(const std::vector<std::string>& chunks, const std::string& outp
std::ofstream outFile(output_file); std::ofstream outFile(output_file);
outFile << board_id_str << "," << channel_id_str << "," << address_str << "," << time_str << "\n"; outFile << board_id_str << "," << channel_id_str << "," << address_str << "," << time_str << "\n";
while (!minHeap.empty()) { while (!min_heap.empty()) {
CsvRow current = minHeap.top(); CsvRow current = min_heap.top();
minHeap.pop(); min_heap.pop();
outFile << current.board_id << "," << current.channel_id << "," << current.address << "," << current.time << "\n"; outFile << current.board_id << "," << current.channel_id << "," << current.address << "," << current.time << "\n";
size_t chunk_index = current.chunk_index; size_t chunk_index = current.chunk_index;
if (chunkReaders[chunk_index]) { if (chunk_readers[chunk_index]) {
uint board_id; uint board_id;
uint channel_id; uint channel_id;
uint address; uint address;
unsigned long long time; unsigned long long time;
if (chunkReaders[chunk_index]->read_row(board_id, channel_id, address, time)) { if (chunk_readers[chunk_index]->read_row(board_id, channel_id, address, time)) {
CsvRow row; CsvRow row;
row.board_id = board_id; row.board_id = board_id;
row.channel_id = channel_id; row.channel_id = channel_id;
row.address = address; row.address = address;
row.time = time; row.time = time;
row.chunk_index = chunk_index; row.chunk_index = chunk_index;
minHeap.push(row); min_heap.push(row);
} else { } else {
chunkReaders[chunk_index].reset(); chunk_readers[chunk_index].reset();
} }
} }
} }
outFile.close(); outFile.close();
for (const auto& chunk : chunks) { for (const auto& chunk : chunks) {
std::remove(chunk.c_str()); std::remove(chunk.c_str());
} }
@ -517,7 +516,7 @@ bool ParticleDataSortTask::processEveryChannelParticleData()
sorted_result_output_dir.mkpath(sorted_result_dir); sorted_result_output_dir.mkpath(sorted_result_dir);
const QString& all_channel_particle_data_filename = GetAllChannelParticleDataFilename(); const QString& all_channel_particle_data_filename = GetAllChannelParticleDataFilename();
QString sorted_output_filename = sorted_result_output_dir.filePath(QStringLiteral(u"粒子数据[已排序].csv")); QString sorted_output_filename = sorted_result_output_dir.filePath(QStringLiteral(u"粒子数据.csv"));
try { try {
const size_t CHUNK_SIZE = 100 * 1024 * 1024; // 100MB chunks const size_t CHUNK_SIZE = 100 * 1024 * 1024; // 100MB chunks
@ -538,7 +537,7 @@ bool ParticleDataSortTask::processEveryChannelParticleData()
} catch (const std::exception& e) { } catch (const std::exception& e) {
const QString& e_what = QString::fromLatin1(e.what()); const QString& e_what = QString::fromLatin1(e.what());
QString error = QString(QStringLiteral(u"处理%1异常:%2")).arg(all_channel_particle_data_filename).arg(QString::fromStdString(e.what())); QString error = QString(QStringLiteral(u"处理%1异常:%2")).arg(all_channel_particle_data_filename).arg(e_what);
LOG_ERROR(error) LOG_ERROR(error)
ret_ok = false; ret_ok = false;
} catch (...) { } catch (...) {
@ -546,15 +545,7 @@ bool ParticleDataSortTask::processEveryChannelParticleData()
LOG_ERROR(error) LOG_ERROR(error)
ret_ok = false; ret_ok = false;
} }
this->updateTaskResultData(QVariant(sorted_output_filename));
const QString& project_name = GetProjectName();
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetProjectModel(project_name);
if (project_model == nullptr) {
ret_ok = false;
} else {
project_model->SetSortedParticleDataFilename(sorted_output_filename);
}
return ret_ok; return ret_ok;
} }
@ -639,7 +630,7 @@ bool AutoFindPeaksTask::processTask()
const QString& error = QStringLiteral(u"%1自动寻峰异常!").arg(ch_count_data_name); const QString& error = QStringLiteral(u"%1自动寻峰异常!").arg(ch_count_data_name);
LOG_WARN(error); LOG_WARN(error);
} }
const QString& info = QStringLiteral(u"%1自动寻峰完成").arg(ch_count_data_name); const QString& info = QStringLiteral(u"%1自动寻峰完成.").arg(ch_count_data_name);
LOG_INFO(info); LOG_INFO(info);
} }
} }
@ -651,7 +642,7 @@ bool AutoFindPeaksTask::processTask()
} else { } else {
project_model->SetAnalysisCustomData(this->_analysis_type, QString("AutoFindPeaksResult"), result_filename); project_model->SetAnalysisCustomData(this->_analysis_type, QString("AutoFindPeaksResult"), result_filename);
} }
const QString& info = QStringLiteral(u"自动寻峰完成"); const QString& info = QStringLiteral(u"自动寻峰完成.");
LOG_INFO(info); LOG_INFO(info);
return true; return true;
} }
@ -742,3 +733,18 @@ bool ChannelEnergyScaleFittingTask::processTask()
LOG_INFO(info); LOG_INFO(info);
return true; return true;
} }
bool ApplyEnergyScaleTask::processTask()
{
bool ok = true;
const QString& project_name = GetProjectName();
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetProjectModel(project_name);
if (project_model == nullptr) {
return false;
}
const QString& info = QStringLiteral(u"应用能量刻度完成.");
LOG_INFO(info);
return ok;
}

View File

@ -23,6 +23,9 @@ namespace DataProcessWorkPool
virtual void run() override final; virtual void run() override final;
protected:
void updateTaskResultData(const QVariant& task_result_data);
private: private:
virtual bool processTask() = 0; virtual bool processTask() = 0;
@ -30,6 +33,7 @@ namespace DataProcessWorkPool
QObject* _finished_notifier { nullptr }; QObject* _finished_notifier { nullptr };
const char* _finished_notifier_process { nullptr }; const char* _finished_notifier_process { nullptr };
QString _project_name; QString _project_name;
QVariant _task_result_data;
}; };
class ParticleDataTask : public DataProcessTask class ParticleDataTask : public DataProcessTask
@ -120,6 +124,14 @@ namespace DataProcessWorkPool
FitDataMap _channel_energy_scale_fit_data_map; FitDataMap _channel_energy_scale_fit_data_map;
QMap<QString, int> _fit_degree_map; QMap<QString, int> _fit_degree_map;
}; };
class ApplyEnergyScaleTask : public DataProcessTask
{
private:
virtual bool processTask() override;
private:
QString _project_name;
};
} }
#endif // DATAPROCESSWORKPOOL_H #endif // DATAPROCESSWORKPOOL_H

View File

@ -151,32 +151,18 @@ void MainWindow::initAction()
{ {
auto new_measurement_analysis_handler = [this]() { auto new_measurement_analysis_handler = [this]() {
NewMeasureAnalysisDlg new_measure_analysis_dlg; NewMeasureAnalysisDlg new_measure_analysis_dlg;
// new_measure_analysis_dlg.exec();
if (QDialog::Accepted == new_measure_analysis_dlg.exec()) { if (QDialog::Accepted == new_measure_analysis_dlg.exec()) {
ProjectList* project_list_model = ProjectList::Instance(); ProjectList* project_list_model = ProjectList::Instance();
auto project_model = project_list_model->GetCurrentProjectModel(); auto project_model = project_list_model->GetCurrentProjectModel();
if (project_model->GetIsMeasureComplete()) { const QString& all_channel_particle_data_filename = project_model->GetAllChannelParticleDataFilename();
const QString& project_name = project_model->GetProjectName(); if (!all_channel_particle_data_filename.isEmpty()) {
// const QString& result_data_dir = QDir(project_model->GetProjectDir()).filePath("EveryChannelParticleData");
// auto separate_task = new DataProcessWorkPool::EveryChannelParticleDataSeparateTask;
// separate_task->SetAllChannelParticleDataFilename(project_model->GetAllChannelParticleDataFilename());
// separate_task->SetResultDataDir(result_data_dir);
// separate_task->SetFinishedNotifier(this->_tree_measure_analysis, "onFinishedSeparateEveryChannelParticleData", project_name);
// separate_task->StartTask();
// auto separate_task = new DataProcessWorkPool::ParticleDataSortTask;
// separate_task->SetAllChannelParticleDataFilename(project_model->GetAllChannelParticleDataFilename());
// separate_task->SetSortedResultDir(project_model->GetProjectDir());
// separate_task->StartTask();
const QString& all_ch_count_dir = project_model->GetProjectDir(); const QString& all_ch_count_dir = project_model->GetProjectDir();
const QString& every_ch_count_dir = QDir(project_model->GetProjectDir()).filePath(QStringLiteral(u"通道道址计数")); const QString& every_ch_count_dir = QDir(project_model->GetProjectDir()).filePath(QStringLiteral(u"通道道址计数"));
auto count_task = new DataProcessWorkPool::EveryChannelParticleCountDataTask; auto count_task = new DataProcessWorkPool::EveryChannelParticleCountDataTask;
count_task->SetAllChannelParticleDataFilename(project_model->GetAllChannelParticleDataFilename()); count_task->SetAllChannelParticleDataFilename(all_channel_particle_data_filename);
count_task->SetAllChannelCountResultDir(all_ch_count_dir); count_task->SetAllChannelCountResultDir(all_ch_count_dir);
count_task->SetEveryChannelCountResultDir(every_ch_count_dir); count_task->SetEveryChannelCountResultDir(every_ch_count_dir);
count_task->SetFinishedNotifier(project_list_model, "onChannelAddressCountProcessFinished", project_name); count_task->SetFinishedNotifier(project_list_model, "onChannelAddressCountProcessFinished", project_model->GetProjectName());
count_task->StartTask(); count_task->StartTask();
} }
} }

View File

@ -318,9 +318,13 @@ void BatchEnergyScaleDialog::onFitBtnClickedProcess()
} }
} }
void BatchEnergyScaleDialog::onEnergyScaleFitFinished(const QString &project_name) void BatchEnergyScaleDialog::onEnergyScaleFitFinished(bool ok, const QString &project_name, const QVariant& data)
{ {
Q_UNUSED(project_name); Q_UNUSED(project_name);
Q_UNUSED(data);
if ( !ok )
return;
QDir result_dir(this->_workspace); QDir result_dir(this->_workspace);
const QString& result_filename = result_dir.filePath(QStringLiteral(u"多通道能量刻度拟合结果.json")); const QString& result_filename = result_dir.filePath(QStringLiteral(u"多通道能量刻度拟合结果.json"));
EnergyScaleDataModel result_model(result_filename); EnergyScaleDataModel result_model(result_filename);
@ -346,6 +350,7 @@ void BatchEnergyScaleDialog::applyEnergyScaleFitResultData()
const QString& energy_scale_result_filename = this->_energy_scale_data_model->GetDataFilename(); const QString& energy_scale_result_filename = this->_energy_scale_data_model->GetDataFilename();
if (QFile::copy(energy_scale_result_filename, energy_scale_data_filename)) { if (QFile::copy(energy_scale_result_filename, energy_scale_data_filename)) {
project_model->SetEnergyScaleFilename(energy_scale_data_filename); project_model->SetEnergyScaleFilename(energy_scale_data_filename);
ProjectList::Instance()->ApplyEnergyScale(this->_project_name);
} }
} else { } else {
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"不能应用非完整的能量刻度!")); QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"不能应用非完整的能量刻度!"));

View File

@ -28,7 +28,7 @@ public slots:
void onSelectedScaleRange(double min, double max); void onSelectedScaleRange(double min, double max);
void onFitBtnClickedProcess(); void onFitBtnClickedProcess();
private slots: private slots:
void onEnergyScaleFitFinished(const QString& project_name); void onEnergyScaleFitFinished(bool ok, const QString& project_name, const QVariant &data);
private: private:
void insertSetEnergyValueToFilter(double energy); void insertSetEnergyValueToFilter(double energy);
@ -37,7 +37,7 @@ private:
void energyScaleDataChanged(const QStringList& channel_name_list); void energyScaleDataChanged(const QStringList& channel_name_list);
signals: signals:
void applyEnergyScale(); void applyEnergyScale(const QString& project_name);
void close(); void close();
protected: protected:

View File

@ -280,9 +280,13 @@ void MeasureAnalysisParticleCountPlotView::updatePlotPeakInfo(const QVariantMap
this->_plot->replot(); this->_plot->replot();
} }
void MeasureAnalysisParticleCountPlotView::onAutoFindPeaksFinished(const QString& project_name) void MeasureAnalysisParticleCountPlotView::onAutoFindPeaksFinished(bool ok, const QString &project_name, const QVariant& data)
{ {
Q_UNUSED(project_name); Q_UNUSED(project_name);
Q_UNUSED(data);
if ( !ok )
return;
this->_plot->CleanMarkers(); this->_plot->CleanMarkers();
this->_plot->replot(); this->_plot->replot();
if (this->_find_peaks_result_dlg) { if (this->_find_peaks_result_dlg) {

View File

@ -35,7 +35,7 @@ private:
void updatePlotPeakInfo(const QVariantMap& peak_infos); void updatePlotPeakInfo(const QVariantMap& peak_infos);
private slots: private slots:
void onAutoFindPeaksFinished(const QString& project_name); void onAutoFindPeaksFinished(bool ok, const QString &project_name, const QVariant& data);
private slots: private slots:
void onActionCurveShowSetting(); void onActionCurveShowSetting();
void onActionFindPeaksResult(); void onActionFindPeaksResult();
@ -44,6 +44,9 @@ private slots:
void onActionEnergyScale(); void onActionEnergyScale();
void onActionPlotConfigure(); void onActionPlotConfigure();
signals:
void applyEnergyScale();
private: private:
QString _workspace; QString _workspace;
CustomQwtPlot* _plot = nullptr; CustomQwtPlot* _plot = nullptr;

View File

@ -5,6 +5,7 @@
#include <QDir> #include <QDir>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include "DataProcessWorkPool.h"
MeasureAnalysisProjectModel::~MeasureAnalysisProjectModel() MeasureAnalysisProjectModel::~MeasureAnalysisProjectModel()
@ -430,15 +431,17 @@ MeasureAnalysisProjectModelList::~MeasureAnalysisProjectModelList()
} }
} }
bool MeasureAnalysisProjectModelList::AddProjectModel(MeasureAnalysisProjectModel* model) bool MeasureAnalysisProjectModelList::AddProjectModel(MeasureAnalysisProjectModel* model, bool save)
{ {
bool ok = true; bool ok = true;
const QString& project_name = model->GetProjectName(); const QString& project_name = model->GetProjectName();
if (!_project_models.contains(project_name)) { if (!_project_models.contains(project_name)) {
_project_models[project_name] = model; _project_models[project_name] = model;
intiProjectNodeStruce(model); intiProjectNodeStruce(model);
SetCurrentProjectModel(project_name); if (save) {
model->SaveProjectModel(); this->SetCurrentProjectModel(project_name);
model->SaveProjectModel();
}
} else { } else {
delete model; delete model;
ok &= false; ok &= false;
@ -610,8 +613,34 @@ QString MeasureAnalysisProjectModelList::GetNodeStatus(QStandardItem* item) cons
return status_item ? status_item->text() : QString(); return status_item ? status_item->text() : QString();
} }
void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(const QString& project_name) void MeasureAnalysisProjectModelList::ApplyEnergyScale(const QString &project_name)
{ {
if (this->_project_models.contains(project_name)) {
auto pro_model = this->_project_models[project_name];
const QString& energy_scale_filename = pro_model->GetEnergyScaleFilename();
QString status = QStringLiteral(u"未配置");
if (energy_scale_filename.isEmpty()) {
status = QStringLiteral(u"已配置");
auto& node_map = this->_project_node_items[project_name];
const QString& energy_scale_item_name = QStringLiteral(u"能量刻度");
if (node_map.contains(energy_scale_item_name)) {
auto energy_scale_item = node_map[energy_scale_item_name];
this->SetNodeStatus(energy_scale_item, status);
}
pro_model->SaveProjectModel();
auto apply_erergy_scale_fit_task = new DataProcessWorkPool::ApplyEnergyScaleTask;
apply_erergy_scale_fit_task->SetFinishedNotifier(this, "onApplyEnergyScaleProcessFinished", project_name);
apply_erergy_scale_fit_task->StartTask();
}
}
}
void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(bool ok, const QString& project_name, const QVariant &data)
{
Q_UNUSED(data);
if ( !ok )
return;
if (this->_project_models.contains(project_name)) { if (this->_project_models.contains(project_name)) {
auto pro_model = this->_project_models[project_name]; auto pro_model = this->_project_models[project_name];
const QMap<uint, QString>& filename_list = pro_model->GetChannelAddressCountDataFilenameList(); const QMap<uint, QString>& filename_list = pro_model->GetChannelAddressCountDataFilenameList();
@ -648,6 +677,44 @@ void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(const
} }
} }
void MeasureAnalysisProjectModelList::onApplyEnergyScaleProcessFinished(bool ok, const QString& project_name, const QVariant &data)
{
Q_UNUSED(data);
if ( !ok )
return;
if (this->_project_models.contains(project_name)) {
auto pro_model = this->_project_models[project_name];
auto& node_map = this->_project_node_items[project_name];
QString status = QStringLiteral(u"无效");
const QString& energy_total_count_filename = pro_model->GetAllChannelEnergyTotalCountDataFilename();
if (!energy_total_count_filename.isEmpty()) {
status = QStringLiteral(u"有效");
const QString& energy_total_count_item_name = QStringLiteral(u"能量计数");
if (node_map.contains(energy_total_count_item_name)) {
auto energy_total_count_item = node_map[energy_total_count_item_name];
this->SetNodeStatus(energy_total_count_item, status);
const QMap<uint, QString>& channel_energy_count_filename_list = pro_model->GetChannelEnergyCountDataFilenameList();
for (auto it = channel_energy_count_filename_list.constBegin(); it != channel_energy_count_filename_list.constEnd(); ++it) {
uint ch_num = it.key();
QString item_name = QStringLiteral(u"通道%1能量计数").arg(ch_num);
const QVariant& analys_type = QVariant::fromValue(AnalysisType::EnergyCountData);
QStandardItem* node_item = AddChildNode(energy_total_count_item, item_name, status, analys_type, true);
node_item->setData(project_name, ProjectName);
node_item->setData(ch_num, ChannelNum);
node_map[item_name] = node_item;
}
const QString& adrr_count_spec_item_name = QStringLiteral(u"能量计数谱");
if (node_map.contains(adrr_count_spec_item_name)) {
auto adrr_count_spec_item = node_map[adrr_count_spec_item_name];
this->SetNodeStatus(adrr_count_spec_item, status);
}
}
}
pro_model->SaveProjectModel();
}
}
void MeasureAnalysisProjectModelList::intiProjectNodeStruce(MeasureAnalysisProjectModel* pro_model) void MeasureAnalysisProjectModelList::intiProjectNodeStruce(MeasureAnalysisProjectModel* pro_model)
{ {
if (!pro_model) { if (!pro_model) {

View File

@ -131,7 +131,7 @@ public:
static MeasureAnalysisProjectModelList* Instance(); static MeasureAnalysisProjectModelList* Instance();
virtual ~MeasureAnalysisProjectModelList(); virtual ~MeasureAnalysisProjectModelList();
bool AddProjectModel(MeasureAnalysisProjectModel* model); bool AddProjectModel(MeasureAnalysisProjectModel* model, bool save = true);
bool RmProjectModel(const QString& project_name); bool RmProjectModel(const QString& project_name);
MeasureAnalysisProjectModel* GetProjectModel(const QString& project_name); MeasureAnalysisProjectModel* GetProjectModel(const QString& project_name);
@ -152,8 +152,11 @@ public:
void SetNodeStatus(QStandardItem* item, const QString& status); void SetNodeStatus(QStandardItem* item, const QString& status);
QString GetNodeStatus(QStandardItem* item) const; QString GetNodeStatus(QStandardItem* item) const;
void ApplyEnergyScale(const QString& project_name);
private slots: private slots:
void onChannelAddressCountProcessFinished(const QString& project_name); void onChannelAddressCountProcessFinished(bool ok, const QString& project_name, const QVariant& data);
void onApplyEnergyScaleProcessFinished(bool ok, const QString& project_name, const QVariant &data);
private: private:
void intiProjectNodeStruce(MeasureAnalysisProjectModel *pro_model); void intiProjectNodeStruce(MeasureAnalysisProjectModel *pro_model);

View File

@ -126,6 +126,7 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index)
view->SetViewDescription(view_name); view->SetViewDescription(view_name);
view->InitViewWorkspace(project_name); view->InitViewWorkspace(project_name);
view->SetAnalyzeDataFilename(data_files_set); view->SetAnalyzeDataFilename(data_files_set);
} }
if ( view ) { if ( view ) {
_item_views[item] = view; _item_views[item] = view;

View File

@ -5,6 +5,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include "DataProcessWorkPool.h"
NewMeasureAnalysisDlg::NewMeasureAnalysisDlg(QWidget *parent) NewMeasureAnalysisDlg::NewMeasureAnalysisDlg(QWidget *parent)
: QDialog(parent) : QDialog(parent)
@ -21,6 +22,8 @@ NewMeasureAnalysisDlg::~NewMeasureAnalysisDlg()
void NewMeasureAnalysisDlg::initialization() void NewMeasureAnalysisDlg::initialization()
{ {
ui->progressBar->setVisible(false);
QRegExp rx(R"(^[^\\/:*?"<>|]+$)"); QRegExp rx(R"(^[^\\/:*?"<>|]+$)");
QValidator *validator = new QRegExpValidator(rx, this); QValidator *validator = new QRegExpValidator(rx, this);
ui->lineEdit_name->setValidator(validator); ui->lineEdit_name->setValidator(validator);
@ -102,6 +105,63 @@ void NewMeasureAnalysisDlg::initialization()
connect(ui->btn_cancel, &QPushButton::clicked, this, &NewMeasureAnalysisDlg::reject); connect(ui->btn_cancel, &QPushButton::clicked, this, &NewMeasureAnalysisDlg::reject);
} }
void NewMeasureAnalysisDlg::newProject(const QString& particle_data_filename)
{
const QString& project_name = ui->lineEdit_name->text();
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
QDir projects_dir(projects_dir_path);
QString project_dir_path = projects_dir.filePath(project_name);
bool is_std_source = ui->checkBox_is_std_source->isChecked();
ulong measure_preset_time = ui->spinBox_measure_preset_time->value();
uint conform_time_win = ui->spinBox_conform_time->value();
QString description_info = ui->plainTextEdit_description->toPlainText();
MeasureAnalysisProjectModel::SpectrumType spec_type = MeasureAnalysisProjectModel::SpectrumType::None;
if (ui->rbtn_sample_spec->isChecked()) {
spec_type = MeasureAnalysisProjectModel::SpectrumType::Sample;
} else if (ui->rbtn_background_spec->isChecked()) {
spec_type = MeasureAnalysisProjectModel::SpectrumType::Background;
}
bool is_measure_complete = true;
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel;
model->SetProjectDir(project_dir_path);
model->SetProjectName(project_name);
model->SetSpectrumType(spec_type);
model->SetIsStdSource(is_std_source);
model->SetMeasurePresetTime(measure_preset_time);
model->SetConformTimeWin(conform_time_win);
model->SetDescriptionInfo(description_info);
model->SetAllChannelParticleDataFilename(particle_data_filename);
model->SetIsMeasureComplete(is_measure_complete);
ProjectList::Instance()->AddProjectModel(model);
NewMeasureAnalysisDlg::accept();
}
void NewMeasureAnalysisDlg::onNewProjectFromFileFinished(bool ok, const QString& project_name, const QVariant &data)
{
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
QDir projects_dir(projects_dir_path);
QString project_dir_path = projects_dir.filePath(project_name);
QDir project_dir(project_dir_path);
if (ok) {
QString all_channel_particle_data_filename = data.toString();
QFileInfo data_file_info(all_channel_particle_data_filename);
if ( data_file_info.exists(all_channel_particle_data_filename) ) {
this->newProject(all_channel_particle_data_filename);
}
} else {
project_dir.removeRecursively();
ui->stackedWidget->setEnabled(false);
ui->btn_previous_step->setEnabled(false);
ui->btn_next_step->setEnabled(false);
ui->btn_ok->setEnabled(false);
const QString& data_file_path = ui->lineEdit_filename->property("data_file_path").toString();
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"粒子数据%1异常,创建测量分析项目失败!").arg(data_file_path));
}
}
void NewMeasureAnalysisDlg::on_btn_ok_clicked() void NewMeasureAnalysisDlg::on_btn_ok_clicked()
{ {
const QString& project_name = ui->lineEdit_name->text(); const QString& project_name = ui->lineEdit_name->text();
@ -112,56 +172,36 @@ void NewMeasureAnalysisDlg::on_btn_ok_clicked()
QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects"); QString projects_dir_path = QDir(qApp->applicationDirPath()).filePath("Projects");
QDir projects_dir(projects_dir_path); QDir projects_dir(projects_dir_path);
QString project_dir_path = projects_dir.filePath(project_name); QString project_dir_path = projects_dir.filePath(project_name);
QDir project_dir(project_dir_path); QDir project_dir(project_dir_path);
if (project_dir.exists()) { if (project_dir.exists()) {
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"测量分析名称已存在,请重新输入!")); QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"测量分析名称已存在,请重新输入!"));
return; return;
} }
MeasureAnalysisProjectModel::SpectrumType spec_type = MeasureAnalysisProjectModel::SpectrumType::None; project_dir.mkpath(project_dir_path);
if (ui->rbtn_sample_spec->isChecked()) { if ( ui->checkBox_file_data->isChecked() ) {
spec_type = MeasureAnalysisProjectModel::SpectrumType::Sample; const QString& data_file_path = ui->lineEdit_filename->property("data_file_path").toString();
} else if (ui->rbtn_background_spec->isChecked()) {
spec_type = MeasureAnalysisProjectModel::SpectrumType::Background;
}
bool is_std_source = ui->checkBox_is_std_source->isChecked();
ulong measure_preset_time = ui->spinBox_measure_preset_time->value();
uint conform_time_win = ui->spinBox_conform_time->value();
QString description_info = ui->plainTextEdit_description->toPlainText();
bool is_measure_complete = false;
QString data_file_path;
if (ui->checkBox_file_data->isChecked()) {
data_file_path = ui->lineEdit_filename->property("data_file_path").toString();
if (data_file_path.isEmpty()) { if (data_file_path.isEmpty()) {
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"请选择粒子数据文件!")); QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"请选择粒子数据文件!"));
return; return;
} }
} auto separate_task = new DataProcessWorkPool::ParticleDataSortTask;
separate_task->SetAllChannelParticleDataFilename(data_file_path);
project_dir.mkpath(project_dir_path); separate_task->SetSortedResultDir(project_dir_path);
// 拷贝粒子数据文件到项目目录 separate_task->SetFinishedNotifier(this, "onNewProjectFromFileFinished", project_name);
QFileInfo data_file_info(data_file_path); separate_task->StartTask();
QString all_channel_particle_data_filename = project_dir.filePath(data_file_info.fileName()); ui->progressBar->setVisible(true);
if (!QFile::copy(data_file_path, all_channel_particle_data_filename)) {
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"载入粒子数据文件到项目目录失败!"));
project_dir.removeRecursively();
return;
} else { } else {
is_measure_complete = true; this->newProject();
} }
ui->stackedWidget->setEnabled(false);
ui->btn_previous_step->setEnabled(false);
ui->btn_next_step->setEnabled(false);
ui->btn_ok->setEnabled(false);
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel; // const QString& result_data_dir = QDir(project_model->GetProjectDir()).filePath("EveryChannelParticleData");
model->SetProjectDir(project_dir_path); // auto separate_task = new DataProcessWorkPool::EveryChannelParticleDataSeparateTask;
model->SetProjectName(project_name); // separate_task->SetAllChannelParticleDataFilename(project_model->GetAllChannelParticleDataFilename());
model->SetSpectrumType(spec_type); // separate_task->SetResultDataDir(result_data_dir);
model->SetIsStdSource(is_std_source); // separate_task->SetFinishedNotifier(this->_tree_measure_analysis, "onFinishedSeparateEveryChannelParticleData", project_name);
model->SetMeasurePresetTime(measure_preset_time); // separate_task->StartTask();
model->SetConformTimeWin(conform_time_win);
model->SetDescriptionInfo(description_info);
model->SetAllChannelParticleDataFilename(all_channel_particle_data_filename);
model->SetIsMeasureComplete(is_measure_complete);
ProjectList::Instance()->AddProjectModel(model);
NewMeasureAnalysisDlg::accept();
} }

View File

@ -17,8 +17,10 @@ public:
private: private:
void initialization(); void initialization();
void newProject(const QString &particle_data_filename = QString());
private slots: private slots:
void onNewProjectFromFileFinished(bool ok, const QString& project_name, const QVariant &data);
void on_btn_ok_clicked(); void on_btn_ok_clicked();
private: private:

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>534</width> <width>550</width>
<height>279</height> <height>278</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -542,14 +542,36 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QProgressBar" name="progressBar">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>1</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>