DataEvaluator.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #include "DataEvaluator.h"
  2. #include <ProjectManager.h>
  3. #include <SchemePlanManager.h>
  4. #include <CMind.h>
  5. #include "algorithm/EntropyWeights.h"
  6. #include "algorithm/PCA.h"
  7. #include "algorithm/HierarchicalAnalysis.h"
  8. #include "algorithm/MatterElementAnalysis.h"
  9. #include <dbService/ClassSet.h>
  10. #include <dbService/NodeMatrixService.h>
  11. #include <dbService/CNodeDataService.h>
  12. #include <dbService/SchemeProcessService.h>
  13. #include <dbService/UserConfigService.h>
  14. #include <dbService/MindWeightService.h>
  15. #include <dbService/MindScoreService.h>
  16. #include <dbService/SchemeInfoService.h>
  17. #include <dbService/GradeIndexInfoService.h>
  18. #include <dbService/EffectResultService.h>
  19. #include <QMap>
  20. #include <QDebug>
  21. DataEvaluator::DataEvaluator(QObject *parent) : QObject(parent) { }
  22. void DataEvaluator::setProcess(SchemePlanManager::SchemeProcessInfo process)
  23. {
  24. m_process = process;
  25. }
  26. SchemePlanManager::SchemeProcessInfo DataEvaluator::process() const
  27. {
  28. return m_process;
  29. }
  30. void DataEvaluator::setGatherType(DataEvaluator::GatherType type)
  31. {
  32. m_gatherType = type;
  33. }
  34. DataEvaluator::GatherType DataEvaluator::gatherType() const
  35. {
  36. return m_gatherType;
  37. }
  38. bool DataEvaluator::evaluate()
  39. {
  40. if (m_process.type == SchemePlanManager::ImportWeightData) {
  41. if (m_process.dSource == SchemePlanManager::FromExpert) {
  42. return evaluateWeightFromExpert();
  43. } else if (m_process.dSource == SchemePlanManager::FromMeasurement) {
  44. return evaluateWeightFromMeasure();
  45. }
  46. } else if (m_process.type == SchemePlanManager::ImportEvalData) {
  47. if (m_process.indexType == ProjectManager::TechIndex) {
  48. return evaluateTech();
  49. } else if (m_process.indexType == ProjectManager::OptimalIndex) {
  50. return evaluateScheme();
  51. } else if (m_process.indexType == ProjectManager::EfficiencyIndex) {
  52. return evaluateEfficiencyMEA();
  53. }
  54. }
  55. return false;
  56. }
  57. bool DataEvaluator::evaluateWeightFromExpert()
  58. {
  59. QMap<QString, QMap<QString, NodeMatrixInfo *>> nodeData;
  60. bool dataRet = getNodeData(nodeData);
  61. /// 权重分析专家导入数据, 使用层次分析法
  62. SchemePlanManager::Algorithm algorithm = SchemePlanManager::AHP;
  63. /// 获取指标体系
  64. QList<CNodeData> nodeList;
  65. bool mindRet = CNodeDataService().QueryAllValid(nodeList, m_process.projectId, m_process.indexType);
  66. CMind *mind = new CMind(this);
  67. mind->setNodeList(nodeList);
  68. /// 获取专家配置
  69. QMap<QString, double> config;
  70. bool cfgRet = getUserConfig(config);
  71. if (!(dataRet && mindRet && cfgRet)) {
  72. return false;
  73. }
  74. QMap<QString, double> indexWeights;
  75. // 结果集结, 先计算各个专家的数据, 再取均值
  76. if (m_gatherType == Result) {
  77. QMap<QString, QMap<QString, double>> mWeights;
  78. for (QString expertId : nodeData.keys()) {
  79. for (int i = 1; i < mind->levels(); i++) {
  80. for (CNodeData node : mind->nodesInLevel(i)) {
  81. QList<CNodeData> subNodes = mind->subNodes(node);
  82. QVector<qreal> nxnValus; // n x n矩阵
  83. for (int j = 0; j < subNodes.size(); j++) {
  84. QString abs = subNodes[j].name;
  85. for (int k = 0; k < subNodes.size(); k++) {
  86. QString ord = subNodes[k].name;
  87. QString key = abs + "-" + ord;
  88. double v;
  89. QStringList nodeValue = nodeData[expertId][key]->nodeValue.split("/");
  90. if (nodeValue.size() == 1) {
  91. // v = nodeValue[0].toDouble();
  92. v = 1.0 / nodeValue[0].toDouble();
  93. } else {
  94. // v = nodeValue[0].toDouble() / nodeValue[1].toDouble();
  95. v = nodeValue[1].toDouble();
  96. }
  97. nxnValus.append(v);
  98. }
  99. }
  100. // 计算权重并存储
  101. QScopedPointer<HierarchicalAnalysis> ha(new HierarchicalAnalysis(subNodes.size(), nxnValus));
  102. QVector<qreal> weights = ha->getWeights();
  103. for (int l = 0; l < weights.size(); ++l) {
  104. if (mWeights.keys().contains(expertId) == false) {
  105. mWeights[expertId] = QMap<QString, double>();
  106. }
  107. CNodeData pNode = mind->node(subNodes[l].pNumber);
  108. if (mWeights[expertId].keys().contains(pNode.name)) {
  109. mWeights[expertId][subNodes[l].name] = mWeights[expertId][pNode.name] * weights[l];
  110. } else {
  111. mWeights[expertId][subNodes[l].name] = weights[l];
  112. }
  113. }
  114. }
  115. }
  116. }
  117. // 求平均权重
  118. for (int i = 1; i < mind->levels(); i++) {
  119. for (CNodeData node : mind->nodesInLevel(i)) {
  120. QList<CNodeData> subNodes = mind->subNodes(node);
  121. for (int j = 0; j < subNodes.size(); j++) {
  122. double sum = 0;
  123. for (QString expertId : nodeData.keys()) {
  124. sum += mWeights[expertId][subNodes[j].name] * config[expertId];
  125. }
  126. indexWeights[subNodes[j].name] = sum;
  127. }
  128. }
  129. }
  130. } else { // 矩阵集结, 先计算各个专家数据的均值, 在求权重
  131. // 求专家数据均值
  132. QMap<QString, double> avgNodeValue;
  133. for (QString key : nodeData.values().first().keys()) {
  134. double sum = 0;
  135. for (QString expertId : nodeData.keys()) {
  136. double v;
  137. QStringList nodeValue = nodeData[expertId][key]->nodeValue.split("/");
  138. if (nodeValue.size() == 1) {
  139. v = nodeValue[0].toDouble();
  140. } else {
  141. v = nodeValue[0].toDouble() / nodeValue[1].toDouble();
  142. }
  143. sum += v * config[expertId];
  144. }
  145. avgNodeValue[key] = sum / nodeData.keys().size();
  146. }
  147. // 求权重
  148. for (int i = 1; i < mind->levels(); i++) {
  149. for (CNodeData node : mind->nodesInLevel(i)) {
  150. QList<CNodeData> subNodes = mind->subNodes(node);
  151. QVector<qreal> nxnValus; // n x n矩阵
  152. for (int j = 0; j < subNodes.size(); j++) {
  153. QString abs = subNodes[j].name;
  154. for (int k = 0; k < subNodes.size(); k++) {
  155. QString ord = subNodes[k].name;
  156. QString key = abs + "-" + ord;
  157. nxnValus.append(avgNodeValue[key]);
  158. }
  159. }
  160. // 计算权重并存储
  161. QScopedPointer<HierarchicalAnalysis> ha(new HierarchicalAnalysis(subNodes.size(), nxnValus));
  162. QVector<qreal> weights = ha->getWeights();
  163. for (int l = 0; l < weights.size(); ++l) {
  164. CNodeData pNode = mind->node(subNodes[l].pNumber);
  165. if (indexWeights.keys().contains(pNode.name)) {
  166. indexWeights[subNodes[l].name] = indexWeights[pNode.name] * weights[l];
  167. } else {
  168. indexWeights[subNodes[l].name] = weights[l];
  169. }
  170. }
  171. }
  172. }
  173. }
  174. QStringList valueList;
  175. for (QString key : indexWeights.keys()) {
  176. valueList.append(QString("%1:%2").arg(key).arg(indexWeights[key]));
  177. }
  178. QString valueStr = valueList.join(";");
  179. bool ret = MindWeightService().saveUniqueWeightData(m_process.projectId, m_process.indexType, m_process.dSource,
  180. algorithm, valueStr);
  181. return ret;
  182. }
  183. bool DataEvaluator::evaluateWeightFromMeasure()
  184. {
  185. QMap<QString, QMap<QString, NodeMatrixInfo *>> nodeData;
  186. bool dataRet = getNodeData(nodeData);
  187. SchemePlanManager::Algorithm algorithm;
  188. bool algRet = getAlgorithm(algorithm);
  189. /// 获取指标体系
  190. QList<CNodeData> nodeList;
  191. bool mindRet = CNodeDataService().QueryAllValid(nodeList, m_process.projectId, m_process.indexType);
  192. CMind *mind = new CMind(this);
  193. mind->setNodeList(nodeList);
  194. if (!(dataRet && algRet && mindRet)) {
  195. return false;
  196. }
  197. /// 各个指标的权重值
  198. /// 外层 QString 是 uuid, 内层 QString 是指标名称, double 是指标权重
  199. QMap<QString, double> allWeights;
  200. if (algorithm == SchemePlanManager::Entropy) { // 熵值法
  201. /// 根据指标体系层级, 构造算法需要的数据, 逐层计算权重值并保存
  202. for (int i = 1; i < mind->levels(); i++) {
  203. for (CNodeData node : mind->nodesInLevel(i)) {
  204. QList<CNodeData> subNodes = mind->subNodes(node);
  205. EntropyMat mat;
  206. for (int j = 0; j < subNodes.size(); j++) {
  207. QVector<double> values;
  208. for (QString uuid : nodeData.keys()) {
  209. NodeMatrixInfo *info = nodeData[uuid][subNodes[j].name];
  210. if (info == nullptr) {
  211. break;
  212. }
  213. double value = nodeData[uuid][subNodes[j].name]->nodeValue.toDouble();
  214. values.append(value);
  215. }
  216. mat.append({ values });
  217. }
  218. if (mat.size() <= 0) {
  219. continue;
  220. }
  221. // 计算权重
  222. QScopedPointer<EntropyWeights> ew(new EntropyWeights(mat));
  223. QVector<double> weights, scores;
  224. ew->compute(weights, scores);
  225. // 结合父节点指标权重计算指标最终权重
  226. for (int k = 0; k < subNodes.size(); k++) {
  227. double w = weights[k];
  228. if (std::_Is_nan(w)) {
  229. w = 1 / subNodes.size();
  230. }
  231. CNodeData pNode = mind->node(subNodes[k].pNumber);
  232. if (allWeights.keys().contains(pNode.name)) {
  233. allWeights[subNodes[k].name] = allWeights[pNode.name] * w;
  234. } else {
  235. allWeights[subNodes[k].name] = w;
  236. }
  237. }
  238. }
  239. }
  240. } else if (algorithm == SchemePlanManager::PrincipalComponents) { // 主成分分析法
  241. for (int i = 1; i < mind->levels(); i++) {
  242. for (CNodeData node : mind->nodesInLevel(i)) {
  243. QList<CNodeData> subNodes = mind->subNodes(node);
  244. QVector<QVector<double>> mat;
  245. for (QString uuid : nodeData.keys()) {
  246. QVector<double> values;
  247. for (int j = 0; j < subNodes.size(); j++) {
  248. NodeMatrixInfo *info = nodeData[uuid][subNodes[j].name];
  249. if (info == nullptr) {
  250. break;
  251. }
  252. double value = nodeData[uuid][subNodes[j].name]->nodeValue.toDouble();
  253. values.append(value);
  254. }
  255. mat.append({ values });
  256. }
  257. if (mat.size() <= 0) {
  258. continue;
  259. }
  260. QScopedPointer<PCA> pca(new PCA(mat));
  261. pca->compute();
  262. // 结合父节点指标权重计算指标最终权重
  263. for (int k = 0; k < subNodes.size(); k++) {
  264. double w = pca->weights()[k];
  265. if (std::_Is_nan(w)) {
  266. w = 1 / subNodes.size();
  267. }
  268. CNodeData pNode = mind->node(subNodes[k].pNumber);
  269. if (allWeights.keys().contains(pNode.name)) {
  270. allWeights[subNodes[k].name] = allWeights[pNode.name] * w;
  271. } else {
  272. allWeights[subNodes[k].name] = w;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. QStringList valueList;
  279. for (QString key : allWeights.keys()) {
  280. valueList.append(QString("%1:%2").arg(key).arg(allWeights[key]));
  281. }
  282. QString valueStr = valueList.join(";");
  283. bool ret = MindWeightService().saveUniqueWeightData(m_process.projectId, m_process.indexType, m_process.dSource,
  284. algorithm, valueStr);
  285. return ret;
  286. }
  287. bool DataEvaluator::evaluateTech()
  288. {
  289. QMap<QString, double> weightData;
  290. bool weightRet = getWeightData(weightData);
  291. QMap<QString, QMap<QString, NodeMatrixInfo *>> nodeData;
  292. bool dataRet = getNodeData(nodeData);
  293. /// 获取指标体系
  294. QList<CNodeData> nodeList;
  295. bool mindRet = CNodeDataService().QueryAllValid(nodeList, m_process.projectId, m_process.indexType);
  296. CMind *mind = new CMind(this);
  297. mind->setNodeList(nodeList);
  298. /// 获取权重配置
  299. QMap<QString, double> config;
  300. bool cfgRet = false;
  301. if (m_process.dSource == SchemePlanManager::FromExpert) {
  302. cfgRet = getUserConfig(config);
  303. } else {
  304. for (QString uuid : nodeData.keys()) {
  305. config[uuid] = 1.0 / nodeData.keys().size();
  306. }
  307. cfgRet = nodeData.size() > 0;
  308. }
  309. if (weightRet == false || dataRet == false || mindRet == false || nodeList.size() <= 0 || cfgRet == false) {
  310. qDebug() << __FUNCTION__ << __LINE__ << endl;
  311. return false;
  312. }
  313. QMap<QString, double> scoreData;
  314. for (int i = 1; i < mind->levels(); i++) {
  315. for (CNodeData node : mind->nodesInLevel(i)) {
  316. QList<CNodeData> subNodes = mind->subNodes(node);
  317. for (int j = 0; j < subNodes.size(); j++) {
  318. double score = 0;
  319. for (QString uuid : nodeData.keys()) {
  320. for (QString weightKey : weightData.keys()) {
  321. QString key = subNodes[j].name + "-" + weightKey;
  322. if (nodeData[uuid].keys().contains(key)) {
  323. score += nodeData[uuid][key]->nodeValue.toDouble() * weightData[weightKey] * config[uuid];
  324. }
  325. }
  326. }
  327. scoreData[subNodes[j].name] = score;
  328. }
  329. }
  330. }
  331. QStringList valueList;
  332. for (QString key : scoreData.keys()) {
  333. valueList.append(QString("%1:%2").arg(key).arg(scoreData[key]));
  334. }
  335. QString valueStr = valueList.join(";");
  336. bool ret = MindScoreService().saveUniqueScoreData(m_process.projectId, valueStr);
  337. return ret;
  338. }
  339. bool DataEvaluator::evaluateScheme()
  340. {
  341. QMap<QString, double> weightData;
  342. bool weightRet = getWeightData(weightData);
  343. QMap<int, QMap<QString, double>> schemeData;
  344. QMap<int, QString> schemeNames;
  345. bool schemeRet = getSchemeData(schemeData, schemeNames);
  346. if (weightRet == false || schemeRet == false) {
  347. return false;
  348. }
  349. for (int schemeId : schemeData.keys()) {
  350. double score = 0;
  351. for (QString key : schemeData[schemeId].keys()) {
  352. score += schemeData[schemeId][key] * weightData[key];
  353. }
  354. SchemeInfoService().updateSchemeScore(schemeId, score);
  355. }
  356. return true;
  357. }
  358. bool DataEvaluator::evaluateEfficiencyMEA()
  359. {
  360. /// 获取指标体系
  361. QList<CNodeData> nodeList;
  362. bool mindRet = CNodeDataService().QueryAllValid(nodeList, m_process.projectId, m_process.indexType);
  363. CMind *mind = new CMind(this);
  364. mind->setNodeList(nodeList);
  365. /// 获取物元配置效能分级
  366. QList<SchemePlanManager::SchemeProcessInfo> processList;
  367. bool processRet = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_process.projectId,
  368. m_process.indexType);
  369. int domainLevel = m_process.efficiencyGrades;
  370. for (auto process : processList) {
  371. if (process.type == SchemePlanManager::RunEvaluate) {
  372. domainLevel = process.efficiencyGrades;
  373. break;
  374. }
  375. }
  376. /// 获取物元配置数据
  377. QList<GradeIndexInfo *> rangeList;
  378. bool gradeRet = GradeIndexInfoService().QueryGradeIndexInfoByProjectId(&rangeList, m_process.projectId);
  379. /// 整理物元配置数据, int:层级 QString:指标名称 QPair:区间左右值
  380. QMap<QString, QMap<int, QPair<double, double>>> rangeData;
  381. for (GradeIndexInfo *info : rangeList) {
  382. if (rangeData.keys().contains(info->gradeIndexName) == false) {
  383. rangeData[info->gradeIndexName] = QMap<int, QPair<double, double>>();
  384. }
  385. QString v = info->gradeIndexValue;
  386. if (v.length() > 2 && v.contains(", ")) {
  387. QStringList l = v.mid(1, v.length() - 2).split(", ");
  388. QPair<double, double> range(l.first().toDouble(), l.last().toDouble());
  389. rangeData[info->gradeIndexName][info->gradeLevel] = range;
  390. }
  391. }
  392. /// 获取样本数据
  393. QMap<int, QMap<QString, double>> schemeData;
  394. QMap<int, QString> schemeNames;
  395. bool schemeRet = getSchemeData(schemeData, schemeNames);
  396. QMap<QString, double> weightData;
  397. bool weightRet = getWeightData(weightData);
  398. /// 获取权重数据
  399. if (mindRet == false || processRet == false || gradeRet == false || schemeRet == false || weightRet == false) {
  400. return false;
  401. }
  402. /// 物元分析
  403. MEAMat mat; // 样本数据
  404. MEARangeMat ranges; // 等级数据
  405. QVector<double> weights; // 权重数据
  406. QList<CNodeData> indexList = mind->leaves(); // 最后一级指标
  407. for (int key : schemeData.keys()) {
  408. QVector<double> m;
  409. for (int i = 0; i < indexList.size(); ++i) {
  410. m.append(schemeData[key][indexList[i].name]);
  411. }
  412. mat.append(m);
  413. }
  414. QVector<MEARange> jointRanges;
  415. for (int level = 1; level < domainLevel + 1; ++level) {
  416. QVector<MEARange> levelRanges;
  417. for (int i = 0; i < indexList.size(); ++i) {
  418. QPair<double, double> p = rangeData[indexList[i].name][level];
  419. MEARange levRange = MEARange { i, p.first, p.second };
  420. levelRanges.append(levRange);
  421. if (level == 1) {
  422. MEARange jointRange = MEARange { i, p.first };
  423. jointRanges.append(jointRange);
  424. } else if (level == domainLevel) {
  425. jointRanges[i].max_value = p.second;
  426. }
  427. }
  428. ranges.append(levelRanges);
  429. }
  430. ranges.append(jointRanges);
  431. for (int i = 0; i < indexList.size(); ++i) {
  432. weights.append(weightData[indexList[i].name]);
  433. }
  434. MatterElementAnalysis me(mat, ranges);
  435. me.evaluate(weights);
  436. QVector<MEAMat> rangeCvt = me.getRangeCVT();
  437. MEAMat rangeWeights = me.getRangeWeights();
  438. if (schemeData.keys().size() != rangeCvt.size() || schemeData.keys().size() != rangeWeights.size()) {
  439. return false;
  440. }
  441. QList<EffectResult> resultData;
  442. for (int scheme = 0; scheme < schemeData.keys().size(); ++scheme) {
  443. EffectResult overall;
  444. overall.projectId = m_process.projectId;
  445. overall.schemeId = schemeData.keys()[scheme];
  446. overall.schemeName = schemeNames[schemeData.keys()[scheme]];
  447. overall.algType = 0;
  448. overall.indexName = "综合";
  449. QVector<double> values = rangeWeights[scheme];
  450. QStringList strList;
  451. for (int v = 0; v < values.size(); ++v) {
  452. strList.append(QString("%1").arg(values[v]));
  453. }
  454. overall.value = strList.join(",");
  455. resultData.append(overall);
  456. for (int index = 0; index < indexList.size(); ++index) {
  457. EffectResult result;
  458. result.projectId = m_process.projectId;
  459. result.schemeId = schemeData.keys()[scheme];
  460. result.schemeName = schemeNames[schemeData.keys()[scheme]];
  461. result.algType = 0;
  462. result.indexName = indexList[index].name;
  463. QVector<double> values = rangeCvt[scheme][index];
  464. QStringList strList;
  465. for (int v = 0; v < values.size(); ++v) {
  466. strList.append(QString("%1").arg(values[v]));
  467. }
  468. result.value = strList.join(",");
  469. resultData.append(result);
  470. }
  471. }
  472. bool saveRet = EffectResultService().addDataList(resultData);
  473. return saveRet;
  474. }
  475. bool DataEvaluator::evaluateEfficiencyGCE()
  476. {
  477. return false;
  478. }
  479. bool DataEvaluator::getNodeData(QMap<QString, QMap<QString, NodeMatrixInfo *>> &nodeData) const
  480. {
  481. /// 整理数据, 使用 uuid 将数据分组, 使用指标名称索引
  482. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
  483. QList<NodeMatrixInfo *> dataList;
  484. bool ret = NodeMatrixService().QueryDataByProjectAndIndex(&dataList, indexName, m_process.projectId,
  485. m_process.dSource);
  486. if (ret == false) {
  487. return false;
  488. }
  489. if (dataList.size() <= 0) {
  490. qDebug() << __FUNCTION__ << __LINE__ << "未录入评估数据" << endl;
  491. return false;
  492. }
  493. for (NodeMatrixInfo *info : dataList) {
  494. QString key = info->strUuid; // 实测数据的 key
  495. if (m_process.dSource == SchemePlanManager::FromExpert) {
  496. key = info->expertId; // 专家数据的 key
  497. }
  498. if (nodeData.keys().contains(key) == false) {
  499. nodeData[key] = QMap<QString, NodeMatrixInfo *>();
  500. }
  501. nodeData[key][nodeDataKey(info)] = info;
  502. }
  503. return true;
  504. }
  505. bool DataEvaluator::getAlgorithm(SchemePlanManager::Algorithm &algorithm) const
  506. {
  507. QList<SchemePlanManager::SchemeProcessInfo> processList;
  508. bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_process.projectId,
  509. m_process.indexType);
  510. if (ret == false) {
  511. return false;
  512. }
  513. for (auto process : processList) {
  514. if (process.type == SchemePlanManager::CalculateWeight) {
  515. algorithm = process.algorithm;
  516. break;
  517. }
  518. }
  519. if (m_process.type == SchemePlanManager::ImportWeightData) {
  520. if (m_process.dSource == SchemePlanManager::FromMeasurement && algorithm == SchemePlanManager::AHP) {
  521. algorithm == SchemePlanManager::Entropy;
  522. }
  523. if (m_process.dSource == SchemePlanManager::FromExpert) {
  524. algorithm == SchemePlanManager::AHP;
  525. }
  526. }
  527. return true;
  528. }
  529. bool DataEvaluator::getUserConfig(QMap<QString, double> &cfg) const
  530. {
  531. QList<UserConfig *> userCfgList;
  532. bool ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&userCfgList, m_process.projectId);
  533. if (ret == false) {
  534. return false;
  535. }
  536. for (UserConfig *config : userCfgList) {
  537. cfg[QString("%1").arg(config->userId)] = config->weight / 100;
  538. }
  539. return true;
  540. }
  541. bool DataEvaluator::getWeightData(QMap<QString, double> &weightData) const
  542. {
  543. MindWeightInfo info;
  544. int indexType = m_process.indexType;
  545. if (indexType == ProjectManager::TechIndex) {
  546. indexType = ProjectManager::AbilityIndex;
  547. }
  548. bool ret = MindWeightService().queryWeightData(&info, m_process.projectId, indexType);
  549. if (ret == false) {
  550. return false;
  551. }
  552. if (info.id < 0) {
  553. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  554. return false;
  555. }
  556. QStringList weightList = info.weight.split(";");
  557. for (QString keyValueStr : weightList) {
  558. QStringList keyValue = keyValueStr.split(":");
  559. if (keyValue.size() == 2) {
  560. weightData[keyValue.first()] = keyValue.last().toDouble();
  561. }
  562. }
  563. return true;
  564. }
  565. bool DataEvaluator::getSchemeData(QMap<int, QMap<QString, double>> &schemeData, QMap<int, QString> &schemeNames) const
  566. {
  567. QList<SchemaEval *> schemeList;
  568. int type = m_process.indexType == ProjectManager::OptimalIndex ? 0 : 1;
  569. bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_process.projectId, type);
  570. if (ret == false) {
  571. return false;
  572. }
  573. if (schemeList.size() <= 0) {
  574. qDebug() << __FUNCTION__ << __LINE__ << "未创建方案" << endl;
  575. return false;
  576. }
  577. for (SchemaEval *scheme : schemeList) {
  578. if (schemeData.keys().contains(scheme->id) == false) {
  579. schemeData[scheme->id] = QMap<QString, double>();
  580. }
  581. QStringList keyValueStringList = scheme->valueStr.split(";");
  582. for (QString keyValueStr : keyValueStringList) {
  583. QStringList keyValue = keyValueStr.split(":");
  584. if (keyValue.size() == 2) {
  585. schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
  586. }
  587. }
  588. schemeNames[scheme->id] = scheme->name;
  589. }
  590. return true;
  591. }
  592. QString DataEvaluator::nodeDataKey(NodeMatrixInfo *data) const
  593. {
  594. QString key = data->abscissa;
  595. if (data->ordinate.length() > 0) {
  596. key += ("-" + data->ordinate);
  597. }
  598. return key;
  599. }