DataEvaluator.cpp 25 KB

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