DataEvaluator.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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, MEARange>> rangeData;
  388. for (GradeIndexInfo *info : rangeList) {
  389. if (rangeData.keys().contains(info->gradeIndexName) == false) {
  390. rangeData[info->gradeIndexName] = QMap<int, MEARange>();
  391. }
  392. QString v = info->gradeIndexValue;
  393. if (v.length() > 2 && v.contains(", ")) {
  394. QStringList l = v.mid(1, v.length() - 2).split(", ");
  395. double left = l.first().toDouble();
  396. double right = l.last().toDouble();
  397. bool leftClosed = v[0] == "[";
  398. bool rightClosed = v.right(1) == "]";
  399. int tempIndex = -1;
  400. MEARange range = MEARange { tempIndex, leftClosed, rightClosed, left, right };
  401. rangeData[info->gradeIndexName][info->gradeLevel] = range;
  402. }
  403. }
  404. /// 获取样本数据
  405. QMap<int, QMap<QString, double>> schemeData;
  406. QMap<int, QString> schemeNames;
  407. bool schemeRet = getSchemeData(schemeData, schemeNames);
  408. QMap<QString, double> weightData;
  409. bool weightRet = getWeightData(weightData);
  410. /// 获取权重数据
  411. if (mindRet == false || processRet == false || gradeRet == false || schemeRet == false || weightRet == false) {
  412. return false;
  413. }
  414. /// 物元分析
  415. MEAMat mat; // 样本数据
  416. MEARangeMat ranges; // 等级数据
  417. QVector<double> weights; // 权重数据
  418. QList<CNodeData> indexList = mind->leaves(); // 最后一级指标
  419. for (int key : schemeData.keys()) {
  420. QVector<double> m;
  421. for (int i = 0; i < indexList.size(); ++i) {
  422. m.append(schemeData[key][indexList[i].name]);
  423. }
  424. mat.append(m);
  425. }
  426. QVector<MEARange> jointRanges;
  427. for (int level = 1; level < domainLevel + 1; ++level) {
  428. QVector<MEARange> levelRanges;
  429. for (int i = 0; i < indexList.size(); ++i) {
  430. MEARange levRange = rangeData[indexList[i].name][level];
  431. levRange.index = i;
  432. levelRanges.append(levRange);
  433. if (level == 1) {
  434. jointRanges.append(levRange);
  435. } else if (level == domainLevel) {
  436. MEARange jointRange = jointRanges[i];
  437. if (levRange.min_value < jointRange.min_value) {
  438. jointRange.min_value = levRange.min_value;
  439. jointRange.left_close = levRange.left_close;
  440. }
  441. if (levRange.max_value > jointRange.max_value) {
  442. jointRange.max_value = levRange.max_value;
  443. jointRange.right_close = levRange.right_close;
  444. }
  445. jointRanges[i] = jointRange;
  446. }
  447. }
  448. ranges.append(levelRanges);
  449. }
  450. ranges.append(jointRanges);
  451. for (int i = 0; i < indexList.size(); ++i) {
  452. weights.append(weightData[indexList[i].name]);
  453. }
  454. MatterElementAnalysis me(mat, ranges);
  455. me.evaluate(weights);
  456. QVector<MEAMat> rangeCvt = me.getRangeCVT();
  457. MEAMat rangeWeights = me.getRangeWeights();
  458. if (schemeData.keys().size() != rangeCvt.size() || schemeData.keys().size() != rangeWeights.size()) {
  459. return false;
  460. }
  461. QList<EffectResult> resultData;
  462. for (int scheme = 0; scheme < schemeData.keys().size(); ++scheme) {
  463. EffectResult overall;
  464. overall.projectId = m_process.projectId;
  465. overall.schemeId = schemeData.keys()[scheme];
  466. overall.schemeName = schemeNames[schemeData.keys()[scheme]];
  467. overall.algType = 0;
  468. overall.indexName = "综合";
  469. QVector<double> values = rangeWeights[scheme];
  470. QStringList strList;
  471. for (int v = 0; v < values.size(); ++v) {
  472. strList.append(QString("%1").arg(values[v]));
  473. }
  474. overall.value = strList.join(",");
  475. resultData.append(overall);
  476. for (int index = 0; index < indexList.size(); ++index) {
  477. EffectResult result;
  478. result.projectId = m_process.projectId;
  479. result.schemeId = schemeData.keys()[scheme];
  480. result.schemeName = schemeNames[schemeData.keys()[scheme]];
  481. result.algType = 0;
  482. result.indexName = indexList[index].name;
  483. QVector<double> values = rangeCvt[scheme][index];
  484. QStringList strList;
  485. for (int v = 0; v < values.size(); ++v) {
  486. strList.append(QString("%1").arg(values[v]));
  487. }
  488. result.value = strList.join(",");
  489. resultData.append(result);
  490. }
  491. }
  492. bool saveRet = EffectResultService().addDataList(resultData);
  493. return saveRet;
  494. }
  495. bool DataEvaluator::evaluateEfficiencyGCE()
  496. {
  497. return false;
  498. }
  499. bool DataEvaluator::getNodeData(QMap<QString, QMap<QString, NodeMatrixInfo *>> &nodeData) const
  500. {
  501. /// 整理数据, 使用 uuid 将数据分组, 使用指标名称索引
  502. QString indexName = ProjectManager::nameOfIndexType((ProjectManager::IndexType)m_process.indexType);
  503. QList<NodeMatrixInfo *> dataList;
  504. bool ret = NodeMatrixService().QueryDataByProjectAndIndex(&dataList, indexName, m_process.projectId,
  505. m_process.dSource);
  506. if (ret == false) {
  507. return false;
  508. }
  509. if (dataList.size() <= 0) {
  510. qDebug() << __FUNCTION__ << __LINE__ << "未录入评估数据" << endl;
  511. return false;
  512. }
  513. for (NodeMatrixInfo *info : dataList) {
  514. QString key = info->strUuid; // 实测数据的 key
  515. if (m_process.dSource == SchemePlanManager::FromExpert) {
  516. key = info->expertId; // 专家数据的 key
  517. }
  518. if (nodeData.keys().contains(key) == false) {
  519. nodeData[key] = QMap<QString, NodeMatrixInfo *>();
  520. }
  521. nodeData[key][nodeDataKey(info)] = info;
  522. }
  523. return true;
  524. }
  525. bool DataEvaluator::getAlgorithm(SchemePlanManager::Algorithm &algorithm) const
  526. {
  527. QList<SchemePlanManager::SchemeProcessInfo> processList;
  528. bool ret = SchemeProcessService().QueryAllByProjectIdAndIndexType(processList, m_process.projectId,
  529. m_process.indexType);
  530. if (ret == false) {
  531. return false;
  532. }
  533. for (auto process : processList) {
  534. if (process.type == SchemePlanManager::CalculateWeight) {
  535. algorithm = process.algorithm;
  536. break;
  537. }
  538. }
  539. if (m_process.type == SchemePlanManager::ImportWeightData) {
  540. if (m_process.dSource == SchemePlanManager::FromMeasurement && algorithm == SchemePlanManager::AHP) {
  541. algorithm == SchemePlanManager::Entropy;
  542. }
  543. if (m_process.dSource == SchemePlanManager::FromExpert) {
  544. algorithm == SchemePlanManager::AHP;
  545. }
  546. }
  547. return true;
  548. }
  549. bool DataEvaluator::getUserConfig(QMap<QString, double> &cfg) const
  550. {
  551. QList<UserConfig *> userCfgList;
  552. bool ret = UserConfigService().QueryUserConfigListInfoByEngineerId(&userCfgList, m_process.projectId);
  553. if (ret == false) {
  554. return false;
  555. }
  556. for (UserConfig *config : userCfgList) {
  557. cfg[QString("%1").arg(config->userId)] = config->weight / 100;
  558. }
  559. return true;
  560. }
  561. bool DataEvaluator::getWeightData(QMap<QString, double> &weightData) const
  562. {
  563. MindWeightInfo info;
  564. int indexType = m_process.indexType;
  565. if (indexType == ProjectManager::TechIndex) {
  566. indexType = ProjectManager::AbilityIndex;
  567. }
  568. bool ret = MindWeightService().queryWeightData(&info, m_process.projectId, indexType);
  569. if (ret == false) {
  570. return false;
  571. }
  572. if (info.id < 0) {
  573. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  574. return false;
  575. }
  576. QStringList weightList = info.weight.split(";");
  577. for (QString keyValueStr : weightList) {
  578. QStringList keyValue = keyValueStr.split(":");
  579. if (keyValue.size() == 2) {
  580. weightData[keyValue.first()] = keyValue.last().toDouble();
  581. }
  582. }
  583. return true;
  584. }
  585. bool DataEvaluator::getSchemeData(QMap<int, QMap<QString, double>> &schemeData, QMap<int, QString> &schemeNames) const
  586. {
  587. QList<SchemaEval *> schemeList;
  588. int type = m_process.indexType == ProjectManager::OptimalIndex ? 0 : 1;
  589. bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_process.projectId, type);
  590. if (ret == false) {
  591. return false;
  592. }
  593. if (schemeList.size() <= 0) {
  594. qDebug() << __FUNCTION__ << __LINE__ << "未创建方案" << endl;
  595. return false;
  596. }
  597. for (SchemaEval *scheme : schemeList) {
  598. if (schemeData.keys().contains(scheme->id) == false) {
  599. schemeData[scheme->id] = QMap<QString, double>();
  600. }
  601. QStringList keyValueStringList = scheme->valueStr.split(";");
  602. for (QString keyValueStr : keyValueStringList) {
  603. QStringList keyValue = keyValueStr.split(":");
  604. if (keyValue.size() == 2) {
  605. schemeData[scheme->id][keyValue.first()] = keyValue.last().toDouble();
  606. }
  607. }
  608. schemeNames[scheme->id] = scheme->name;
  609. }
  610. return true;
  611. }
  612. QString DataEvaluator::nodeDataKey(NodeMatrixInfo *data) const
  613. {
  614. QString key = data->abscissa;
  615. if (data->ordinate.length() > 0) {
  616. key += ("-" + data->ordinate);
  617. }
  618. return key;
  619. }