123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #include "DataEvaluator.h"
- #include <ProjectManager.h>
- #include <SchemePlanManager.h>
- #include <CMind.h>
- #include "algorithm/EntropyWeights.h"
- #include <dbService/ClassSet.h>
- #include <dbService/NodeMatrixService.h>
- #include <dbService/CNodeDataService.h>
- #include <dbService/SchemeProcessService.h>
- #include <QMap>
- #include <QDebug>
- DataEvaluator::DataEvaluator(QObject *parent) : QObject(parent) { }
- void DataEvaluator::setProcess(SchemePlanManager::SchemeProcessInfo process)
- {
- m_process = process;
- }
- SchemePlanManager::SchemeProcessInfo DataEvaluator::process() const
- {
- return m_process;
- }
- void DataEvaluator::setGatherType(DataEvaluator::GatherType type)
- {
- m_gatherType = type;
- }
- DataEvaluator::GatherType DataEvaluator::gatherType() const
- {
- return m_gatherType;
- }
- bool DataEvaluator::evaluate()
- {
- if (m_process.type == SchemePlanManager::ImportWeightData) {
- if (m_process.dSource == SchemePlanManager::FromExpert) {
- return evaluateWeightFromExpert();
- } else if (m_process.dSource == SchemePlanManager::FromMeasurement) {
- return evaluateWeightFromMeasure();
- }
- } 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();
- }
- } else if (m_process.indexType == ProjectManager::OptimalIndex) {
- return evaluateScheme();
- } else if (m_process.indexType == ProjectManager::EfficiencyIndex) {
- return evaluateEfficiencyMEA();
- }
- }
- return false;
- }
- bool DataEvaluator::evaluateWeightFromExpert()
- {
- return false;
- }
- bool DataEvaluator::evaluateWeightFromMeasure()
- {
- /// 获取权重分析数据
- /// 整理数据, 使用 uuid 将数据分组, 使用指标名称索引
- QMap<QString, QMap<QString, NodeMatrixInfo *>> nodeData;
- bool dataRet = getNodeData(nodeData);
- SchemePlanManager::Algorithm algorithm;
- bool algRet = getAlgorithm(algorithm);
- /// 获取指标体系
- QList<CNodeData> nodeList;
- bool mindRet = CNodeDataService().QueryAll(nodeList, m_process.projectId, m_process.indexType);
- CMind *mind = new CMind(this);
- mind->setNodeList(nodeList);
- if (!(dataRet && algRet && mindRet)) {
- return false;
- }
- /// 各个指标的权重值
- /// 外层 QString 是 uuid, 内层 QString 是指标名称, double 是指标权重
- QMap<QString, double> allWeights;
- /// 根据指标体系层级, 构造算法需要的数据
- for (int i = 1; i < mind->levels(); i++) {
- for (CNodeData node : mind->nodesInLevel(i)) {
- QList<CNodeData> subNodes = mind->subNodes(node);
- EntropyMat mat;
- for (int j = 0; j < subNodes.size(); j++) {
- QVector<double> values;
- for (QString uuid : nodeData.keys()) {
- NodeMatrixInfo *info = nodeData[uuid][subNodes[j].name];
- if (info == nullptr) {
- break;
- }
- double value = nodeData[uuid][subNodes[j].name]->nodeValue.toDouble();
- values.append(value);
- }
- mat.append({ values });
- }
- // pdata = { { 4.1 }, { 0.04 }, { 0.19 }, { 0.01 }, { 0.05 } };
- // pdata = {
- // { 4.1, 3.9 }, { 0.04, 0.08 }, { 0.19, 0.38 }, { 0.01, 0.18 }, { 0.36, 0.19 }, {
- // 0.05, 0.04 }
- // };
- if (mat.size() <= 0) {
- break;
- }
- QScopedPointer<EntropyWeights> ew(new EntropyWeights(mat));
- QVector<double> weights, scores;
- ew->compute(weights, scores);
- qDebug() << __FUNCTION__ << __LINE__ << weights << endl;
- for (int j = 0; j < subNodes.size(); j++) {
- double w = weights[j];
- if (std::_Is_nan(w)) {
- w = 0;
- }
- CNodeData pNode = mind->node(subNodes[j].pNumber);
- if (allWeights.keys().contains(pNode.name)) {
- allWeights[subNodes[j].name] = allWeights[pNode.name] * w;
- } else {
- allWeights[subNodes[j].name] = w;
- }
- }
- }
- }
- qDebug() << __FUNCTION__ << __LINE__ << allWeights << endl;
- return false;
- }
- bool DataEvaluator::evaluateTechFromExpert()
- {
- return false;
- }
- bool DataEvaluator::evaluateTechFromMeasure()
- {
- return false;
- }
- bool DataEvaluator::evaluateScheme()
- {
- return false;
- }
- bool DataEvaluator::evaluateEfficiencyMEA()
- {
- return false;
- }
- bool DataEvaluator::evaluateEfficiencyGCE()
- {
- return false;
- }
- bool DataEvaluator::getNodeData(QMap<QString, QMap<QString, NodeMatrixInfo *>> &nodeData) const
- {
- /// 整理数据, 使用 uuid 将数据分组, 使用指标名称索引
- QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
- QList<NodeMatrixInfo *> dataList;
- bool ret = NodeMatrixService().QueryDataByProjectAndIndex(&dataList, indexName, m_process.projectId,
- m_process.dSource);
- if (ret == false) {
- return false;
- }
- for (NodeMatrixInfo *info : dataList) {
- if (nodeData.keys().contains(info->strUuid) == false) {
- nodeData[info->strUuid] = QMap<QString, NodeMatrixInfo *>();
- }
- nodeData[info->strUuid][nodeDataKey(info)] = info;
- }
- return true;
- }
- bool DataEvaluator::getAlgorithm(SchemePlanManager::Algorithm &algorithm) const
- {
- QList<SchemePlanManager::SchemeProcessInfo> processList;
- bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_process.projectId,
- m_process.indexType);
- if (ret == false) {
- return false;
- }
- for (auto process : processList) {
- if (process.type == SchemePlanManager::CalculateWeight) {
- if (process.algorithm == SchemePlanManager::Entropy) {
- algorithm = process.algorithm;
- }
- break;
- }
- }
- return true;
- }
- QString DataEvaluator::nodeDataKey(NodeMatrixInfo *data) const
- {
- QString key = data->abscissa;
- if (data->ordinate.length() > 0) {
- key += ("-" + data->ordinate);
- }
- return key;
- }
|