调整道址计数处理

This commit is contained in:
徐海 2026-03-04 16:17:04 +08:00
parent c020345b76
commit 91a5e30917
11 changed files with 75 additions and 43 deletions

View File

@ -208,7 +208,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData()
QMap<uint, QMap<uint, uint>> channel_address_counts; // 通道号 -> 地址 -> 计数
// 统计所有通道的粒子计数(不同板卡号通道号相同道址)
QMap<uint, uint> all_channel_address_counts; // 地址 -> 计数
// QMap<uint, uint> all_channel_address_counts; // 地址 -> 计数
std::string board_id_str = QString(QStringLiteral(u"板卡号")).toStdString();
std::string channel_id_str = QString(QStringLiteral(u"通道号")).toStdString();
@ -239,7 +239,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData()
channel_address_counts[channel_num][address]++;
// 统计所有通道的粒子计数
all_channel_address_counts[address]++;
// all_channel_address_counts[address]++;
}
// 写入每个通道的粒子计数数据(优化:使用一次打开文件,批量写入)
@ -274,16 +274,16 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData()
channel_file_streams.clear();
// 写入所有通道的粒子计数数据
all_channel_total_count_filename = all_ch_count_output_dir.filePath("AllChannelParticleTotalCountData.csv");
std::ofstream all_channel_out(QStrToSysPath(all_channel_total_count_filename));
all_channel_out << QString(QStringLiteral(u"道址")).toStdString() << "," << QString(QStringLiteral(u"计数")).toStdString() << std::endl;
// all_channel_total_count_filename = all_ch_count_output_dir.filePath("AllChannelParticleTotalCountData.csv");
// std::ofstream all_channel_out(QStrToSysPath(all_channel_total_count_filename));
// all_channel_out << QString(QStringLiteral(u"道址")).toStdString() << "," << QString(QStringLiteral(u"计数")).toStdString() << std::endl;
for (auto address_it = all_channel_address_counts.begin(); address_it != all_channel_address_counts.end(); ++address_it) {
uint address = address_it.key();
uint count = address_it.value();
all_channel_out << address << "," << count << std::endl;
}
all_channel_out.close();
// for (auto address_it = all_channel_address_counts.begin(); address_it != all_channel_address_counts.end(); ++address_it) {
// uint address = address_it.key();
// uint count = address_it.value();
// all_channel_out << address << "," << count << std::endl;
// }
// all_channel_out.close();
} catch (const std::runtime_error& e) {
QString error = QString(QStringLiteral(u"处理%1发生运行时异常:%2")).arg(all_channel_particle_data_filename).arg(e.what());
@ -309,7 +309,7 @@ bool EveryChannelParticleCountDataTask::processEveryChannelParticleData()
project_model->SetChannelParticleCountDataFilename(it.key(), it.value());
}
// 更新项目模型中的所有通道粒子总计数数据文件名
project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename);
// project_model->SetAllChannelParticleTotalCountDataFilename(all_channel_total_count_filename);
}
return ret_ok;

View File

@ -20,12 +20,12 @@ MeasureAnalysisDataTableView::MeasureAnalysisDataTableView(QWidget* parent)
layout->addWidget(_tableView);
}
void MeasureAnalysisDataTableView::SetAnalyzeDataFilename(const QMap<QString, QString> &data_files_set)
void MeasureAnalysisDataTableView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
{
if (data_files_set.isEmpty()) {
return;
}
auto csv_ddata_source = std::make_shared<CsvDataSource>(data_files_set.first());
auto csv_ddata_source = std::make_shared<CsvDataSource>(data_files_set.first().toString());
if (!csv_ddata_source->isValid()) {
return;
}

View File

@ -16,7 +16,7 @@ class MeasureAnalysisDataTableView : public MeasureAnalysisView
public:
MeasureAnalysisDataTableView(QWidget *parent = nullptr);
virtual void SetAnalyzeDataFilename(const QMap<QString, QString>& data_files_set);
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
private:
// 私有成员变量

View File

@ -12,10 +12,10 @@ MeasureAnalysisParticleCountPlotView::MeasureAnalysisParticleCountPlotView(QWidg
_custom_plot->setGeometry(0, 0, this->width(), this->height());
}
void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QString, QString>& data_files_set)
void MeasureAnalysisParticleCountPlotView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
{
for (auto it = data_files_set.begin(); it != data_files_set.end(); ++it) {
loadDataFromFile(it.value());
loadDataFromFile(it.value().toString());
}
}

View File

@ -13,7 +13,7 @@ class MeasureAnalysisParticleCountPlotView : public MeasureAnalysisView
public:
MeasureAnalysisParticleCountPlotView(QWidget *parent = nullptr);
virtual void SetAnalyzeDataFilename(const QMap<QString, QString>& data_files_set);
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
private:
void setupCustomPlot();

View File

@ -75,10 +75,10 @@ void MeasureAnalysisProjectModel::SetChannelParticleCountDataFilename(uint chann
this->_channel_particle_count_data_filename_list[channel] = filename;
}
void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename)
{
this->_all_channel_particle_total_count_data_filename = filename;
}
// void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename)
// {
// this->_all_channel_particle_total_count_data_filename = filename;
// }
void MeasureAnalysisProjectModel::SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename)
{
@ -170,10 +170,10 @@ const QString& MeasureAnalysisProjectModel::GetChannelParticleCountDataFilename(
return this->_channel_particle_count_data_filename_list[channel];
}
const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const
{
return this->_all_channel_particle_total_count_data_filename;
}
// const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const
// {
// return this->_all_channel_particle_total_count_data_filename;
// }
const QString& MeasureAnalysisProjectModel::GetTimeWinConformParticleDataFilename(uint time_win, uint conform_particle_count) const
{

View File

@ -32,7 +32,7 @@ public:
void SetSortedParticleDataFilename(const QString& filename);
void SetChannelParticleDataFilename(uint channel, const QString& filename);
void SetChannelParticleCountDataFilename(uint channel, const QString& filename);
void SetAllChannelParticleTotalCountDataFilename(const QString& filename);
// void SetAllChannelParticleTotalCountDataFilename(const QString& filename);
void SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename);
const QString& GetProjectDir() const;
@ -52,7 +52,7 @@ public:
const QString& GetChannelParticleDataFilename(uint channel) const;
const QMap<uint, QString>& GetChannelParticleCountDataFilenameList() const;
const QString& GetChannelParticleCountDataFilename(uint channel) const;
const QString& GetAllChannelParticleTotalCountDataFilename() const;
// const QString& GetAllChannelParticleTotalCountDataFilename() const;
const QString& GetTimeWinConformParticleDataFilename(uint time_win, uint conform_particle_count) const;
private:
@ -74,7 +74,7 @@ private:
QString _sorted_particle_data_filename;
QMap<uint, QString> _channel_particle_data_filename_list;
QMap<uint, QString> _channel_particle_count_data_filename_list;
QString _all_channel_particle_total_count_data_filename;
// QString _all_channel_particle_total_count_data_filename;
QMap<uint, ConformParticleData> _time_win_conform_particle_data;
};

View File

@ -118,6 +118,7 @@ void TreeWidget::SetConnectActions(MeasureAnalysisActions* const actions_analyze
});
connect(actions_analyze, &MeasureAnalysisActions::addMeasureAnalysisProject, [this]() {
});
connect(actions_analyze, &MeasureAnalysisActions::rmMeasureAnalysisProject, [this]() {
removeAnalyzeItem();
@ -126,6 +127,7 @@ void TreeWidget::SetConnectActions(MeasureAnalysisActions* const actions_analyze
});
connect(actions_analyze, &MeasureAnalysisActions::addAnalyzeView, [this]() {
});
connect(actions_analyze, &MeasureAnalysisActions::rmAnalyzeView, [this]() {
@ -146,11 +148,14 @@ void TreeWidget::AddProjectModel(MeasureAnalysisProjectModel* model)
TreeItem* tree_item_analyze_data_group = new_item->GetAnalyzeDataGroupItem();
if (tree_item_analyze_data_group) {
const QString& all_ch_particle_data_filename = model->GetAllChannelParticleDataFilename();
QMap<QString, QVariant> data_files_set;
data_files_set[QStringLiteral(u"测量粒子数据")] = all_ch_particle_data_filename;
TreeItem* new_item_particle_data = new TreeItem;
new_item_particle_data->SetName(QStringLiteral(u"测量粒子数据"));
new_item_particle_data->SetType(TreeItemType::ParticleData);
new_item_particle_data->SetDescription(all_ch_particle_data_filename);
new_item_particle_data->setData(0, Qt::UserRole, all_ch_particle_data_filename);
new_item_particle_data->setData(0, Qt::UserRole, data_files_set);
tree_item_analyze_data_group->insertChild(0, new_item_particle_data);
this->expandItem(tree_item_analyze_data_group);
}
@ -215,23 +220,29 @@ void TreeWidget::onFinishedParticleCountData(const QString& project_name)
if (project_model) {
TreeItem* tree_item_analyze_data_group = tree_item_analyze->GetAnalyzeDataGroupItem();
if (tree_item_analyze_data_group) {
const QString& all_ch_count_filename = project_model->GetAllChannelParticleTotalCountDataFilename();
// const QString& all_ch_count_filename = project_model->GetAllChannelParticleTotalCountDataFilename();
// QMap<QString, QVariant> data_files_set;
// data_files_set[QStringLiteral(u"所有通道道址计数数据")] = all_ch_count_filename;
TreeItem* new_item_all_ch_count = new TreeItem;
new_item_all_ch_count->SetName(QStringLiteral(u"粒子计数数据"));
new_item_all_ch_count->SetType(TreeItemType::ParticleData);
new_item_all_ch_count->SetDescription(all_ch_count_filename);
new_item_all_ch_count->setData(0, Qt::UserRole, all_ch_count_filename);
new_item_all_ch_count->SetName(QStringLiteral(u"道址计数数据组"));
new_item_all_ch_count->SetType(TreeItemType::AnalyzeDataGroup);
new_item_all_ch_count->SetDescription(QStringLiteral(u"道址计数数据组,子节点包含所有通道道址的计数数据"));
// new_item_all_ch_count->setData(0, Qt::UserRole, data_files_set);
tree_item_analyze_data_group->addChild(new_item_all_ch_count);
auto ch_particle_count_filename_list = project_model->GetChannelParticleCountDataFilenameList();
for (auto it = ch_particle_count_filename_list.begin(); it != ch_particle_count_filename_list.end(); ++it) {
uint ch_num = it.key();
const QString& ch_count_filename = it.value();
QMap<QString, QVariant> data_files_set;
data_files_set[QStringLiteral(u"通道%1道址计数数据").arg(ch_num)] = ch_count_filename;
TreeItem* new_item_every_ch_count_data = new TreeItem;
new_item_every_ch_count_data->SetName(QStringLiteral(u"通道%1粒子计数数据").arg(ch_num));
new_item_every_ch_count_data->SetName(QStringLiteral(u"通道%1道址计数数据").arg(ch_num));
new_item_every_ch_count_data->SetType(TreeItemType::ParticleData);
new_item_every_ch_count_data->SetDescription(ch_count_filename);
new_item_every_ch_count_data->setData(0, Qt::UserRole, ch_count_filename);
new_item_every_ch_count_data->setData(0, Qt::UserRole, data_files_set);
new_item_all_ch_count->addChild(new_item_every_ch_count_data);
}
this->expandItem(tree_item_analyze_data_group);
@ -268,7 +279,7 @@ void TreeWidget::removeAnalyzeItem()
auto current_item = this->currentItem();
if (current_item) {
const QString& text_title = QStringLiteral(u"删除确认");
const QString& text_msg = QStringLiteral(u"是否确定删除分析项\"%1\"?").arg(current_item->text(0));
const QString& text_msg = QStringLiteral(u"是否确定删除\"%1\"?").arg(current_item->text(0));
if (QMessageBox::Yes == QMessageBox::question(nullptr, text_title, text_msg)) {
TreeItem* tree_item = dynamic_cast<TreeItem*>(this->currentItem());
if (tree_item) {
@ -301,4 +312,22 @@ void TreeWidget::removeTreeItem(QTreeWidgetItem* const item)
delete item;
}
} // namespace MeasureAnalysisTree
}
MeasureAnalysisTree::TreeMeasureAnalysisProjectItem *MeasureAnalysisTree::TreeWidget::getProjectItem(TreeItem *item)
{
if (item) {
TreeItemType item_type = item->GetType();
if (TreeItemType::MeasureAnalysisProject == item_type) {
return dynamic_cast<TreeMeasureAnalysisProjectItem*>(item);
}
} else {
item = dynamic_cast<TreeItem*>(item->parent());
if (item) {
return getProjectItem(item);
}
}
return nullptr;
}
// namespace MeasureAnalysisTree

View File

@ -12,6 +12,7 @@ namespace MeasureAnalysisTree {
class MeasureAnalysisActions;
class TreeAnalyzeItem;
class TreeItem;
class TreeMeasureAnalysisProjectItem;
class TreeWidget : public QTreeWidget {
Q_OBJECT
@ -23,6 +24,10 @@ public:
void SetConnectActions(MeasureAnalysisActions* const actions_analyze);
void AddProjectModel(MeasureAnalysisProjectModel* model);
private:
TreeMeasureAnalysisProjectItem* getProjectItem(TreeItem* item);
private slots:
// void onFinishedSeparateEveryChannelParticleData(const QString& project_name);
void onFinishedParticleSortData(const QString& project_name);

View File

@ -65,9 +65,7 @@ void TreeItem::NewAnalyzeView(const QString &name, const QString &description, c
this->_ptr_analyze_view = MeasureAnalysisView::NewAnalyzeView(view_type_text);
this->_ptr_analyze_view->SetViewName(name);
this->_ptr_analyze_view->SetViewDescription(description);
const QString& data_filename = this->data(0, Qt::UserRole).toString();
QMap<QString, QString> data_files_set;
data_files_set[name] = data_filename;
const QMap<QString, QVariant>& data_files_set = this->data(0, Qt::UserRole).toMap();
this->_ptr_analyze_view->SetAnalyzeDataFilename(data_files_set);
}

View File

@ -38,7 +38,7 @@ public:
void SetViewDescription(const QString& description);
const QString& GetViewName() const;
const QString& GetViewDescription() const;
virtual void SetAnalyzeDataFilename(const QMap<QString, QString>& data_files_set) = 0;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set) = 0;
protected:
void setAnalyzeViewType(ViewType type);