DataEvaluator.cpp 25 KB

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