Ver Fonte

技术重要度评估;
存储指标得分;

chengxr há 1 ano atrás
pai
commit
914730f431

+ 104 - 17
QFD/common/DataEvaluator.cpp

@@ -14,6 +14,7 @@
 #include <dbService/SchemeProcessService.h>
 #include <dbService/UserConfigService.h>
 #include <dbService/MindWeightService.h>
+#include <dbService/MindScoreService.h>
 
 #include <QMap>
 #include <QDebug>
@@ -50,11 +51,7 @@ bool DataEvaluator::evaluate()
         }
     } else if (m_process.type == SchemePlanManager::ImportEvalData) {
         if (m_process.indexType == ProjectManager::TechIndex) {
-            if (m_process.dSource == SchemePlanManager::FromExpert) {
-                return evaluateTechFromExpert();
-            } else if (m_process.dSource == SchemePlanManager::FromMeasurement) {
-                return evaluateTechFromMeasure();
-            }
+            return evaluateTech();
         } else if (m_process.indexType == ProjectManager::OptimalIndex) {
             return evaluateScheme();
         } else if (m_process.indexType == ProjectManager::EfficiencyIndex) {
@@ -140,7 +137,7 @@ bool DataEvaluator::evaluateWeightFromExpert()
                 for (int j = 0; j < subNodes.size(); j++) {
                     double sum = 0;
                     for (QString expertId : nodeData.keys()) {
-                        sum += mWeights[expertId][subNodes[j].name];
+                        sum += mWeights[expertId][subNodes[j].name] * config[expertId];
                     }
                     indexWeights[subNodes[j].name] = sum / nodeData.keys().size();
                 }
@@ -159,7 +156,7 @@ bool DataEvaluator::evaluateWeightFromExpert()
                 } else {
                     v = nodeValue[0].toDouble() / nodeValue[1].toDouble();
                 }
-                sum += v;
+                sum += v * config[expertId];
             }
             avgNodeValue[key] = sum / nodeData.keys().size();
         }
@@ -203,7 +200,6 @@ bool DataEvaluator::evaluateWeightFromExpert()
     bool ret = MindWeightService().saveUniqueWeightData(m_process.projectId, m_process.indexType, m_process.dSource,
                                                         algorithm, valueStr);
 
-    qDebug() << __FUNCTION__ << __LINE__ << ret << valueStr << endl;
     return ret;
 }
 
@@ -316,19 +312,77 @@ bool DataEvaluator::evaluateWeightFromMeasure()
         }
     }
 
-    qDebug() << __FUNCTION__ << __LINE__ << allWeights << endl;
+    QStringList valueList;
+    for (QString key : allWeights.keys()) {
+        valueList.append(QString("%1:%2").arg(key).arg(allWeights[key]));
+    }
+    QString valueStr = valueList.join(";");
 
-    return true;
-}
+    bool ret = MindWeightService().saveUniqueWeightData(m_process.projectId, m_process.indexType, m_process.dSource,
+                                                        algorithm, valueStr);
 
-bool DataEvaluator::evaluateTechFromExpert()
-{
-    return false;
+    return ret;
 }
 
-bool DataEvaluator::evaluateTechFromMeasure()
+bool DataEvaluator::evaluateTech()
 {
-    return false;
+    QMap<QString, double> weightData;
+    bool weightRet = getWeight(weightData);
+
+    QMap<QString, QMap<QString, NodeMatrixInfo *>> nodeData;
+    bool dataRet = getNodeData(nodeData);
+
+    /// 获取指标体系
+    QList<CNodeData> nodeList;
+    bool mindRet = CNodeDataService().QueryAll(nodeList, m_process.projectId, m_process.indexType);
+    CMind *mind  = new CMind(this);
+    mind->setNodeList(nodeList);
+
+    /// 获取权重配置
+    QMap<QString, double> config;
+    bool cfgRet = false;
+    if (m_process.dSource == SchemePlanManager::FromExpert) {
+        cfgRet = getUserConfig(config);
+    } else {
+        for (QString uuid : nodeData.keys()) {
+            config[uuid] = 1.0 / nodeData.keys().size();
+        }
+        cfgRet = nodeData.size() > 0;
+    }
+
+    if (weightRet == false || dataRet == false || mindRet == false || nodeList.size() <= 0 || cfgRet == false) {
+        qDebug() << __FUNCTION__ << __LINE__ << endl;
+        return false;
+    }
+
+    QMap<QString, double> scoreData;
+    for (int i = 1; i < mind->levels(); i++) {
+        for (CNodeData node : mind->nodesInLevel(i)) {
+            QList<CNodeData> subNodes = mind->subNodes(node);
+            for (int j = 0; j < subNodes.size(); j++) {
+                double score = 0;
+                for (QString uuid : nodeData.keys()) {
+                    for (QString weightKey : weightData.keys()) {
+                        QString key = subNodes[j].name + "-" + weightKey;
+                        if (nodeData[uuid].keys().contains(key)) {
+                            score += nodeData[uuid][key]->nodeValue.toDouble() * weightData[weightKey] * config[uuid];
+                        }
+                    }
+                }
+                scoreData[subNodes[j].name] = score;
+            }
+        }
+    }
+
+    QStringList valueList;
+    for (QString key : scoreData.keys()) {
+        valueList.append(QString("%1:%2").arg(key).arg(scoreData[key]));
+    }
+    QString valueStr = valueList.join(";");
+    bool ret         = MindScoreService().saveUniqueScoreData(m_process.projectId, valueStr);
+    qDebug() << __FUNCTION__ << __LINE__ << valueStr << endl;
+
+    return ret;
 }
 
 bool DataEvaluator::evaluateScheme()
@@ -356,6 +410,12 @@ bool DataEvaluator::getNodeData(QMap<QString, QMap<QString, NodeMatrixInfo *>> &
     if (ret == false) {
         return false;
     }
+
+    if (dataList.size() <= 0) {
+        qDebug() << __FUNCTION__ << __LINE__ << "未录入评估数据" << endl;
+        return false;
+    }
+
     for (NodeMatrixInfo *info : dataList) {
         QString key = info->strUuid;  // 实测数据的 key
         if (m_process.dSource == SchemePlanManager::FromExpert) {
@@ -406,7 +466,34 @@ bool DataEvaluator::getUserConfig(QMap<QString, double> &cfg) const
     }
 
     for (UserConfig *config : userCfgList) {
-        cfg[QString("%1").arg(config->userId)] = config->weight;
+        cfg[QString("%1").arg(config->userId)] = config->weight / 100;
+    }
+    return true;
+}
+
+bool DataEvaluator::getWeight(QMap<QString, double> &weight) const
+{
+    MindWeightInfo info;
+    int indexType = m_process.indexType;
+    if (indexType == ProjectManager::TechIndex) {
+        indexType = ProjectManager::AbilityIndex;
+    }
+    bool ret = MindWeightService().queryWeightData(&info, m_process.projectId, indexType);
+    if (ret == false) {
+        return false;
+    }
+
+    if (info.id < 0) {
+        qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
+        return false;
+    }
+
+    QStringList weightList = info.weight.split(";");
+    for (QString keyValueStr : weightList) {
+        QStringList keyValue = keyValueStr.split(":");
+        if (keyValue.size() == 2) {
+            weight[keyValue.first()] = keyValue.last().toDouble();
+        }
     }
     return true;
 }

+ 4 - 2
QFD/common/DataEvaluator.h

@@ -35,8 +35,7 @@ private:
     bool evaluateWeightFromExpert();   // 权重分析,专家数据
     bool evaluateWeightFromMeasure();  // 权重分析,实测数据
 
-    bool evaluateTechFromExpert();   // 技术重要度评估,专家数据
-    bool evaluateTechFromMeasure();  // 技术重要评估,实测数据
+    bool evaluateTech();  // 技术重要度评估, 指标得分
 
     bool evaluateScheme();  // 方案优选评估
 
@@ -52,6 +51,9 @@ private:
     /// 获取专家配置
     bool getUserConfig(QMap<QString, double> &cfg) const;
 
+    /// 获取指标权重
+    bool getWeight(QMap<QString, double> &weight) const;
+
     /// 使用横坐标和纵坐标构造索引
     QString nodeDataKey(NodeMatrixInfo *data) const;
 

+ 8 - 0
QFD/dbService/ClassSet.h

@@ -446,4 +446,12 @@ public:
     QString weight;  // 指标权重值. 格式 指标名称1:权重;指标名称2:权重;指标名称3:权重
 };
 
+class MindScoreInfo
+{
+public:
+    int id = -1;    // 主键 id
+    int projectId;  // 项目 id
+    QString score;  // 指标得分. 格式 指标名称1:得分;指标名称2:得分;指标名称3:得分
+};
+
 #endif  // CLASSSET_H

+ 77 - 0
QFD/dbService/MindScoreService.cpp

@@ -0,0 +1,77 @@
+#include "MindScoreService.h"
+
+#include "ClassSet.h"
+
+#include "SqlDBHelper.h"
+
+#include <QDebug>
+
+MindScoreService::MindScoreService(QObject *parent) : QObject(parent) { }
+
+bool MindScoreService::saveUniqueScoreData(int projId, const QString &score)
+{
+    MindScoreInfo info;
+    bool qRet = queryScoreData(&info, projId);
+    if (qRet == false) {
+        return false;
+    }
+
+    if (info.id < 0) {
+        info.projectId = projId;
+        info.score     = score;
+        return saveScoreData(&info);
+    } else {
+        return updateScoreData(info.id, score);
+    }
+}
+
+bool MindScoreService::queryScoreData(MindScoreInfo *info, int projId)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        QString selectSql = QString("SELECT id, project_id, score "
+                                    "from t_mind_score WHERE project_id = %1")
+                                    .arg(projId);
+        QueryResult queryResult = t.execQuery(selectSql);
+        if (queryResult.next()) {
+            info->id        = queryResult.value(0).toInt();
+            info->projectId = queryResult.value(1).toInt();
+            info->score     = queryResult.value(2).toString();
+        }
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool MindScoreService::updateScoreData(int id, const QString &score)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        t.update("t_mind_score").set("score", score).where("id = ?", id);
+        t.commit();
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
+bool MindScoreService::saveScoreData(MindScoreInfo *info)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        InsertQuery q         = t.insertInto("t_mind_score (project_id,score)");
+        NonQueryResult result = q.values(info->projectId, info->score).exec();
+        t.commit();
+        info->id = result.lastInsertId().toInt();
+        ret      = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}

+ 42 - 0
QFD/dbService/MindScoreService.h

@@ -0,0 +1,42 @@
+#ifndef MINDSCORESERVICE_H
+#define MINDSCORESERVICE_H
+
+class MindScoreInfo;
+
+#include <QObject>
+
+///
+/// \brief The MindScoreService class
+/// 技术重要度指标得分
+///
+class MindScoreService : public QObject
+{
+    Q_OBJECT
+public:
+    explicit MindScoreService(QObject *parent = nullptr);
+
+    /// 保存数据
+    /// 保存前先查询数据是否已存在, 是则更新数据, 否则新增数据
+    /// 数据的唯一性由项目id,指标体系类型,数据来源,算法共同确定
+    bool saveUniqueScoreData(int projId, const QString &score);
+
+    ///
+    /// \brief queryScoreData 查询权重数据
+    /// \param info 存储权重数据
+    /// \param projId 项目 id
+    /// \return 成功 or 失败
+    bool queryScoreData(MindScoreInfo *info, int projId);
+
+    ///
+    /// \brief updateScoreData 更新权重数据
+    /// \param id 主键
+    /// \param weight 权重
+    /// \return 成功 or 失败
+    bool updateScoreData(int id, const QString &score);
+
+private:
+    /// 保存权重数据
+    bool saveScoreData(MindScoreInfo *info);
+};
+
+#endif  // MINDSCORESERVICE_H

+ 24 - 1
QFD/dbService/MindWeightService.cpp

@@ -12,7 +12,7 @@ bool MindWeightService::saveUniqueWeightData(int projId, int indexType, int data
                                              const QString &weight)
 {
     MindWeightInfo info;
-    bool qRet = queryWeightData(&info, projId, indexType, dataSource, algorithm);
+    bool qRet = queryWeightData(&info, projId, indexType);
     if (qRet == false) {
         return false;
     }
@@ -57,6 +57,29 @@ bool MindWeightService::queryWeightData(MindWeightInfo *info, int projId, int in
     return ret;
 }
 
+bool MindWeightService::queryWeightData(MindWeightInfo *info, int projId, int indexType)
+{
+    bool ret = false;
+    try {
+        Transaction t(SqlDBHelper::getDatabase());
+        QString selectSql = QString("SELECT id, project_id, index_type, weight "
+                                    "from t_mind_weight WHERE project_id = %1 and index_type = %2")
+                                    .arg(projId)
+                                    .arg(indexType);
+        QueryResult queryResult = t.execQuery(selectSql);
+        if (queryResult.next()) {
+            info->id        = queryResult.value(0).toInt();
+            info->projectId = queryResult.value(1).toInt();
+            info->indexType = queryResult.value(2).toInt();
+            info->weight    = queryResult.value(3).toString();
+        }
+        ret = true;
+    } catch (const DBException &ex) {
+        qDebug() << ex.lastError.text();
+    }
+    return ret;
+}
+
 bool MindWeightService::updateWeightData(int id, const QString &weight)
 {
     bool ret = false;

+ 3 - 1
QFD/dbService/MindWeightService.h

@@ -12,7 +12,7 @@ public:
     explicit MindWeightService(QObject *parent = nullptr);
 
     /// 保存权重数据
-    /// 保存前先查询数据是否已存在, 是则更新数据
+    /// 保存前先查询数据是否已存在, 是则更新数据, 否则新增数据
     /// 数据的唯一性由项目id,指标体系类型,数据来源,算法共同确定
     bool saveUniqueWeightData(int projId, int indexType, int dataSource, int algorithm, const QString &weight);
 
@@ -26,6 +26,8 @@ public:
     /// \return 成功 or 失败
     bool queryWeightData(MindWeightInfo *info, int projId, int indexType, int dataSource, int algorithm);
 
+    bool queryWeightData(MindWeightInfo *info, int projId, int indexType);
+
     ///
     /// \brief updateWeightData 更新权重数据
     /// \param id 主键

+ 2 - 0
QFD/dbService/dbService.pri

@@ -9,6 +9,7 @@ HEADERS += \
     $$PWD/EngineerService.h \
     $$PWD/GradeIndexInfoService.h \
     $$PWD/GradeInfoService.h \
+    $$PWD/MindScoreService.h \
     $$PWD/MindWeightService.h \
     $$PWD/NodeMatrixService.h \
     $$PWD/ProjectAlgorithmRelationService.h \
@@ -33,6 +34,7 @@ SOURCES += \
     $$PWD/EngineerService.cpp \
     $$PWD/GradeIndexInfoService.cpp \
     $$PWD/GradeInfoService.cpp \
+    $$PWD/MindScoreService.cpp \
     $$PWD/MindWeightService.cpp \
     $$PWD/NodeMatrixService.cpp \
     $$PWD/ProjectAlgorithmRelationService.cpp \

+ 4 - 0
QFD/widgets/DataCollectionWidget.cpp

@@ -182,6 +182,10 @@ void DataCollectionWidget::slotTabCurrentChanged(int index)
             m_configExpert->setProcess(table->process());
         }
         m_configExpert->setVisible(expert);
+        if (m_configExpert->isVisible()) {
+            m_configExpert->loadData();
+            m_configExpert->selectFirstImported();
+        }
 
         bool scheme = (table->process().indexType != ProjectManager::TechIndex
                        && table->process().type == SchemePlanManager::ImportEvalData);