DataEvaluator.cpp 23 KB

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