Переглянути джерело

修正权重计算;
显示评估结果;
修改和显示饼图;

chengxr 1 рік тому
батько
коміт
2c6e8541eb

+ 2 - 1
QFD/common/DataEvaluator.cpp

@@ -140,10 +140,11 @@ bool DataEvaluator::evaluateWeightFromExpert()
                     for (QString expertId : nodeData.keys()) {
                         sum += mWeights[expertId][subNodes[j].name] * config[expertId];
                     }
-                    indexWeights[subNodes[j].name] = sum / nodeData.keys().size();
+                    indexWeights[subNodes[j].name] = sum;
                 }
             }
         }
+
     } else {  // 矩阵集结, 先计算各个专家数据的均值, 在求权重
         // 求专家数据均值
         QMap<QString, double> avgNodeValue;

+ 12 - 5
QFD/widgets/CustomPieChart.cpp

@@ -1,5 +1,7 @@
 #include "CustomPieChart.h"
 
+#include <QDebug>
+
 CustomPieChart::CustomPieChart(QWidget *parent) : QWidget(parent)
 {
     title = "默认标题";  // 标题名字
@@ -20,8 +22,8 @@ CustomPieChart::CustomPieChart(const QString &title, const QString &tag, const i
     initPieChartWidget();
 }
 
-CustomPieChart::CustomPieChart(const QString &title, QStringList tagList, QList<int> dataList, QList<QColor> colorList,
-                               QWidget *parent)
+CustomPieChart::CustomPieChart(const QString &title, QStringList tagList, QList<double> dataList,
+                               QList<QColor> colorList, QWidget *parent)
     : QWidget(parent)
 {
     this->title = title;  // 标题名字
@@ -120,14 +122,19 @@ void CustomPieChart::drawPieChart()
                 QRectF(-(radius * 2.1), -(radius / 2.1 + fontSize / 3) + count * (fontSize * 1.3), radius, radius),
                 tagList[count]);
         /* 绘制标签折线 */
-        tagFont.setPointSizeF(!isSetTagFont ? radius / 5 : tagFont.pointSizeF());
+        tagFont.setPointSizeF(!isSetTagFont ? radius / 8 : tagFont.pointSizeF());
         painter.setFont(tagFont);
         fontSize      = tagFont.pointSize();
         QPointF point = QPointF(midPoint + radius * cos(radian * M_PI / 180),
                                 midPoint - radius * sin(radian * M_PI / 180));  // 弧度在坐标轴的象限点
         QPolygonF polygon;                                                      // 多段线
         polygon << point;
-        QString tagText  = QString::number(dataList[count] / sum * 100, 'f', 0) + "%";
+
+        QString tagText = QString("%1").arg(dataList[count] * 100) + "%";
+        if (sum - 0.01 > 1 || sum + 0.01 < 1) {
+            tagText = QString("%1").arg(dataList[count]);
+        }
+
         double textWidth = tagText.size() / 2 * fontSize;
         if (dataList[count] != 0) {            // 数据不为零才可以绘制折线和标签
             if (radian > 0 && radian <= 90) {  // 第一象限
@@ -203,7 +210,7 @@ void CustomPieChart::addSlice(const QString &tag, const int &data, const QColor
 }
 
 /* 设置系列 */
-void CustomPieChart::setSeries(QStringList tagList, QList<int> dataList, QList<QColor> colorList)
+void CustomPieChart::setSeries(QStringList tagList, QList<double> dataList, QList<QColor> colorList)
 {
     total           = dataList.size();  // 数据表长度
     sum             = 0;                // 数据总量

+ 8 - 8
QFD/widgets/CustomPieChart.h

@@ -16,15 +16,15 @@ public:
     explicit CustomPieChart(QWidget *parent = nullptr);
     explicit CustomPieChart(const QString &title, const QString &tag, const int &data, const QColor &color,
                             QWidget *parent = nullptr);
-    explicit CustomPieChart(const QString &title, QStringList tagList, QList<int> dataList, QList<QColor> colorList,
+    explicit CustomPieChart(const QString &title, QStringList tagList, QList<double> dataList, QList<QColor> colorList,
                             QWidget *parent = nullptr);
     ~CustomPieChart();
-    void addSlice(const QString &tag, const int &data, const QColor &color);         // 增加切片的函数
-    void setSeries(QStringList tagList, QList<int> value, QList<QColor> colorList);  // 设置系列的函数
-    void setTitleFont(const QFont &font);                                            // 设置标题字体的函数
-    void setTagFont(const QFont &font);                                              // 设置标签字体的函数
-    void setLegendFont(const QFont &font);                                           // 设置说明字体的函数
-    void setSumFont(const QFont &font);                                              // 设置总数字体的函数
+    void addSlice(const QString &tag, const int &data, const QColor &color);            // 增加切片的函数
+    void setSeries(QStringList tagList, QList<double> value, QList<QColor> colorList);  // 设置系列的函数
+    void setTitleFont(const QFont &font);                                               // 设置标题字体的函数
+    void setTagFont(const QFont &font);                                                 // 设置标签字体的函数
+    void setLegendFont(const QFont &font);                                              // 设置说明字体的函数
+    void setSumFont(const QFont &font);                                                 // 设置总数字体的函数
     void setSumTextFont(const QFont &font);    // 设置"总数"文本字体的函数
     void setGlobalFont(const QFont &font);     // 设置全局字体的函数
     void setRingSize(const double &ringSize);  // 设置圆环大小的函数
@@ -49,7 +49,7 @@ private:
     QWidget *pieChartWidget;                           // 绘制饼图的部件
     QString title;                                     // 标题名字
     QStringList tagList;                               // 标签列表
-    QList<int> dataList;                               // 数据列表
+    QList<double> dataList;                            // 数据列表
     QList<QColor> colorList;                           // 颜色列表
     bool eventFilter(QObject *widget, QEvent *event);  // 过滤绘图事件的函数
     void drawPieChart();                               // 绘制饼图的函数

+ 156 - 49
QFD/widgets/EvalReportWidget.cpp

@@ -10,6 +10,8 @@
 #include <dbService/ClassSet.h>
 #include <dbService/SchemeInfoService.h>
 #include <dbService/SchemeProcessService.h>
+#include <dbService/MindWeightService.h>
+#include <dbService/MindScoreService.h>
 
 #include <QLabel>
 #include <QBoxLayout>
@@ -91,7 +93,7 @@ void EvalReportWidget::initWidgets()
     m_indexCombo->setCurrentIndex(2);
     connect(m_indexCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSelectIndexPlotType(int)));
 
-    plots       = QStringList { "竖向柱状图" };
+    //    plots       = QStringList { "竖向柱状图" };
     m_techCombo = new QComboBox(this);
     m_techCombo->setFixedSize(QSize(150, 35));
     m_techCombo->addItems(plots);
@@ -206,19 +208,28 @@ void EvalReportWidget::showIndexWeight()
         return;
     }
 
-    /// 项目演示-方案优选-层级分析法
-    QMap<int, QList<double>> optiCC;
-    optiCC[2] = { 0.0399746, 0.08573655, 0.1867215, 0.517877, 0.1696905 };
-    optiCC[3] = { 0.03164655, 0.00832805, 0.06787475, 0.0178618,  0.15171122,
-                  0.03501028, 0.43156399, 0.08631301, 0.04242262, 0.12726788 };
+    MindWeightInfo info;
+    int indexType = m_indexType;
+    if (indexType == ProjectManager::TechIndex) {
+        indexType = ProjectManager::AbilityIndex;
+    }
+    bool ret = MindWeightService().queryWeightData(&info, m_proj->id, indexType);
+    if (ret == false) {
+        return;
+    }
 
-    /// 项目演示-效能评估
-    QMap<int, QList<double>> effi;
-    effi[2] = { 0.280833, 0.584156, 0.13501 };
-    effi[3] = { 0.07020825, 0.21062475, 0.48679647, 0.09735953, 0.10688289, 0.02812711 };
-    effi[4] = { 0.05558152, 0.01462673, 0.12860136, 0.0567758,  0.02524748, 0.05098171, 0.31008254,
-                0.12573223, 0.01327194, 0.01461917, 0.01931854, 0.05014989, 0.06026197, 0.01258931,
-                0.0281506,  0.00588096, 0.01585843, 0.00331298, 0.00740806, 0.00154762 };
+    if (info.id < 0) {
+        qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
+        return;
+    }
+    QMap<QString, double> weightData;
+    QStringList weightList = info.weight.split(";");
+    for (QString keyValueStr : weightList) {
+        QStringList keyValue = keyValueStr.split(":");
+        if (keyValue.size() == 2) {
+            weightData[keyValue.first()] = keyValue.last().toDouble();
+        }
+    }
 
     for (int i = 2; i <= levels; i++) {
         QTableView *t = new QTableView();
@@ -240,14 +251,9 @@ void EvalReportWidget::showIndexWeight()
             QStandardItem *vHeader = new QStandardItem(node.name);
             model->setVerticalHeaderItem(j, vHeader);
 
-            QStandardItem *item = new QStandardItem("0.5");
-            if (m_proj->id == kDemoProjId1) {
-                if (m_indexType == ProjectManager::OptimalIndex) {
-                    item->setText(QString("%1").arg(optiCC[i][j]));
-                } else if (m_indexType == ProjectManager::EfficiencyIndex) {
-                    item->setText(QString("%1").arg(effi[i][j]));
-                }
-            }
+            QStandardItem *item = new QStandardItem();
+            item->setText(QString("%1").arg(weightData[node.name]));
+
             item->setEditable(false);
             model->setItem(j, 0, item);
         }
@@ -295,18 +301,12 @@ void EvalReportWidget::showIndexWeightPlot()
     } else {
 
         QStringList tagList;
-        QList<int> dataList;
+        QList<double> dataList;
         QList<QColor> colorList;
 
-        int sum = 0;
         for (int i = 0; i < values.size(); i++) {
             tagList.append("");
-            int t = values[i].value * 100;
-            if (i < values.size() - 1) {
-                sum += t;
-            } else {
-                t = 100 - sum;
-            }
+            double t = values[i].value;
             dataList.append(t);
             QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
             colorList.append(color);
@@ -329,6 +329,21 @@ void EvalReportWidget::showTechScore()
         return;
     }
 
+    MindScoreInfo info;
+    bool ret = MindScoreService().queryScoreData(&info, m_proj->id);
+    if (ret == false || info.id < 0) {
+        return;
+    }
+
+    QMap<QString, QString> scoreData;
+    QStringList keyValueStringList = info.score.split(";");
+    for (QString keyValueString : keyValueStringList) {
+        QStringList keyValue = keyValueString.split(":");
+        if (keyValue.size() == 2) {
+            scoreData[keyValue.first()] = keyValue.last();
+        }
+    }
+
     QStandardItem *hHeader = new QStandardItem("得分");
     model->setHorizontalHeaderItem(0, hHeader);
 
@@ -340,7 +355,8 @@ void EvalReportWidget::showTechScore()
         QStandardItem *vHeader = new QStandardItem(node.name);
         model->setVerticalHeaderItem(j, vHeader);
 
-        QStandardItem *item = new QStandardItem("0.5");
+        QStandardItem *item = new QStandardItem();
+        item->setText(scoreData[node.name]);
 
         item->setEditable(false);
         model->setItem(j, 0, item);
@@ -352,6 +368,58 @@ void EvalReportWidget::showTechScore()
     m_techPlot->updateData(values);
 }
 
+void EvalReportWidget::showTechScorePlot()
+{
+    DataTableItemModel *model = (DataTableItemModel *)m_techTable->model();
+    if (model == nullptr) {
+        return;
+    }
+
+    QVector<PlotView::Data> values;
+    for (int i = 0; i < model->rowCount(); i++) {
+        QStandardItem *header = model->verticalHeaderItem(i);
+        QStandardItem *item   = model->item(i, 0);
+        PlotView::Data data { header->text(), item->text().toDouble() };
+        values.append(data);
+    }
+
+    if (m_techPlot != nullptr) {
+        m_gridLayout->removeWidget(m_techPlot);
+        m_techPlot->deleteLater();
+        m_techPlot = nullptr;
+    }
+    if (m_techPie != nullptr) {
+        m_gridLayout->removeWidget(m_techPie);
+        m_techPie->deleteLater();
+        m_techPie = nullptr;
+    }
+
+    if (m_techCombo->currentIndex() < 5) {
+        PlotView::PlotType type = (PlotView::PlotType)m_techCombo->currentIndex();
+        m_techPlot              = new PlotView(type, values, "", this);
+        m_techPlot->setFixedSize(600, 600);
+        m_techPlot->plot();
+        m_gridLayout->addWidget(m_techPlot, 1, 1);
+    } else {
+
+        QStringList tagList;
+        QList<double> dataList;
+        QList<QColor> colorList;
+
+        for (int i = 0; i < values.size(); i++) {
+            tagList.append("");
+            double t = values[i].value;
+            dataList.append(t);
+            QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
+            colorList.append(color);
+        }
+
+        m_techPie = new CustomPieChart("", tagList, dataList, colorList);
+        m_techPie->setFixedSize(600, 600);
+        m_gridLayout->addWidget(m_techPie, 1, 1);
+    }
+}
+
 void EvalReportWidget::showSchemeScore()
 {
     int levels = m_mind->levels();
@@ -376,13 +444,6 @@ void EvalReportWidget::showSchemeScore()
         QStandardItem *hHeader = new QStandardItem("得分");
         model->setHorizontalHeaderItem(0, hHeader);
 
-        /// 项目演示-方案优选-层次加权法得分
-        QList<double> scoreList = { 10.136319544500001, 11.961457030999998, 17.516247966, 11.692445301 };
-        /// 项目演示-方案优选-集对分析法得分
-        if (m_evalAlg == SchemePlanManager::SPA) {
-            scoreList = { 0.889003, 0.662887, 0.951992, 0.565267 };
-        }
-
         for (int i = 0; i < schemeList.size(); i++) {
             SchemaEval *scheme     = schemeList[i];
             QStandardItem *vHeader = new QStandardItem(scheme->name);
@@ -392,11 +453,6 @@ void EvalReportWidget::showSchemeScore()
             item->setEditable(false);
             PlotView::Data data { vHeader->text(), scheme->score };
 
-            if (m_proj->id == kDemoProjId1 && m_indexType == ProjectManager::OptimalIndex) {
-                item->setText(QString("%1").arg(scoreList[i]));
-                data.value = scoreList[i];
-            }
-
             model->setItem(i, 0, item);
             values.append(data);
         }
@@ -406,9 +462,60 @@ void EvalReportWidget::showSchemeScore()
     m_schemePlot->updateData(values);
 }
 
-void EvalReportWidget::showEffiResult()
+void EvalReportWidget::showSchemeScorePlot()
 {
+    DataTableItemModel *model = (DataTableItemModel *)m_schemeTable->model();
+    if (model == nullptr) {
+        return;
+    }
 
+    QVector<PlotView::Data> values;
+    for (int i = 0; i < model->rowCount(); i++) {
+        QStandardItem *header = model->verticalHeaderItem(i);
+        QStandardItem *item   = model->item(i, 0);
+        PlotView::Data data { header->text(), item->text().toDouble() };
+        values.append(data);
+    }
+
+    if (m_schemePlot != nullptr) {
+        m_gridLayout->removeWidget(m_schemePlot);
+        m_schemePlot->deleteLater();
+        m_schemePlot = nullptr;
+    }
+    if (m_schemePie != nullptr) {
+        m_gridLayout->removeWidget(m_schemePie);
+        m_schemePie->deleteLater();
+        m_schemePie = nullptr;
+    }
+
+    if (m_schemeCombo->currentIndex() < 5) {
+        PlotView::PlotType type = (PlotView::PlotType)m_schemeCombo->currentIndex();
+        m_schemePlot            = new PlotView(type, values, "", this);
+        m_schemePlot->setFixedSize(600, 600);
+        m_schemePlot->plot();
+        m_gridLayout->addWidget(m_schemePlot, 3, 1);
+    } else {
+
+        QStringList tagList;
+        QList<double> dataList;
+        QList<QColor> colorList;
+
+        for (int i = 0; i < values.size(); i++) {
+            tagList.append("");
+            double t = values[i].value;
+            dataList.append(t);
+            QColor color(20 + 200 / values.size() * i, 70 * (1.6 - i / values.size()), 150, 255);
+            colorList.append(color);
+        }
+
+        m_schemePie = new CustomPieChart("", tagList, dataList, colorList);
+        m_schemePie->setFixedSize(600, 600);
+        m_gridLayout->addWidget(m_schemePie, 3, 1);
+    }
+}
+
+void EvalReportWidget::showEffiResult()
+{
     m_EffiTab->clear();
 
     QList<QString> tabList = { "建设前", "建设后" };
@@ -492,16 +599,16 @@ void EvalReportWidget::slotSelectIndexPlotType(int)
     showIndexWeightPlot();
 }
 
-void EvalReportWidget::slotSelectTechPlotType(int type)
+void EvalReportWidget::slotSelectTechPlotType(int)
 {
-    makePlotClear(m_techPlot);
-    m_techPlot->updateType(PlotView::PlotType(type));
+    showTechScorePlot();
 }
 
-void EvalReportWidget::slotSelectSchemePlotType(int type)
+void EvalReportWidget::slotSelectSchemePlotType(int)
 {
-    makePlotClear(m_schemePlot);
-    m_schemePlot->updateType(PlotView::PlotType(type));
+    showSchemeScorePlot();
+    //    makePlotClear(m_schemePlot);
+    //    m_schemePlot->updateType(PlotView::PlotType(type));
 }
 
 void EvalReportWidget::slotIndexTabIndexChanged(int)

+ 2 - 0
QFD/widgets/EvalReportWidget.h

@@ -38,12 +38,14 @@ private:
     void showIndexWeightPlot();
 
     void showTechScore();
+    void showTechScorePlot();
 
     /// 项目演示-方案优选-层次加权法得分
     /// [10.136319544500001, 11.961457030999998, 17.516247966, 11.692445301]
     /// 及对分析发得分
     /// (0.889003, 0.662887,  0.951992, 0.565267)
     void showSchemeScore();
+    void showSchemeScorePlot();
 
     void showEffiResult();