GreyClusteringSampleTable.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "GreyClusteringItemDelegate.h"
  2. #include "GreyClusteringSampleTable.h"
  3. #include "MultiLevelHeaderView.h"
  4. #include "CMind.h"
  5. #include "dbService/GradeInfoService.h"
  6. #include "dbService/EffectIndexInfoService.h"
  7. #include "dbService/SchemeInfoService.h"
  8. #include "dbService/MindWeightService.h"
  9. #include "dbService/EffectResultService.h"
  10. #include "algorithm/GreyClusterEvaluation.h"
  11. #include "ProjectManager.h"
  12. #include <QHeaderView>
  13. #include <QDebug>
  14. #include <QMessageBox>
  15. #include <QtMath>
  16. /**
  17. * example
  18. * QVector<GreyClusteringItem> gcItems;
  19. gcItems << GreyClusteringItem { "火力", 0, 0, 9, 1, nullptr };
  20. QSharedPointer<GreyClusteringValue> sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  21. sg->units = "m";
  22. sg->weiget = 2;
  23. sg->greyRanges << GreyRange { "较差类", true, 85, true, 100 };
  24. sg->greyRanges << GreyRange { "一般类", true, 100, true, 115 };
  25. sg->greyRanges << GreyRange { "较好类", true, 115, true, 125 };
  26. sg->leftExtension = 70;
  27. sg->rightExtension = 140;
  28. sg->oldValue = 0;
  29. sg->newValue = 0;
  30. gcItems << GreyClusteringItem { "火炮口径", 0, 1, 1, 2, sg };
  31. gcItems << GreyClusteringItem { "初速", 1, 1, 3, 1, nullptr };
  32. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  33. sg->units = "m";
  34. sg->weiget = 4;
  35. sg->greyRanges << GreyRange { "较差类", true, 1600, true, 1300 };
  36. sg->greyRanges << GreyRange { "一般类", true, 1600, true, 1900 };
  37. sg->greyRanges << GreyRange { "较好类", true, 1600, true, 1900 };
  38. sg->leftExtension = 500;
  39. sg->rightExtension = 220;
  40. sg->oldValue = 0;
  41. sg->newValue = 0;
  42. gcItems << GreyClusteringItem { "穿甲弹", 1, 2, 1, 1, sg };
  43. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  44. sg->units = "m";
  45. sg->weiget = 4;
  46. sg->greyRanges << GreyRange { "较差类", true, 1000, true, 1200 };
  47. sg->greyRanges << GreyRange { "一般类", true, 1200, true, 1400 };
  48. sg->greyRanges << GreyRange { "较好类", true, 1200, true, 1400 };
  49. sg->leftExtension = 600;
  50. sg->rightExtension = 1700;
  51. sg->oldValue = 0;
  52. sg->newValue = 0;
  53. gcItems << GreyClusteringItem { "破甲弹", 2, 2, 1, 1, sg };
  54. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  55. sg->units = "m";
  56. sg->weiget = 4;
  57. sg->greyRanges << GreyRange { "较差类", true, 500, false, 650 };
  58. sg->greyRanges << GreyRange { "一般类", true, 650, false, 800 };
  59. sg->greyRanges << GreyRange { "较好类", true, 800, false, 1000 };
  60. sg->leftExtension = 400;
  61. sg->rightExtension = 1100;
  62. sg->oldValue = 0;
  63. sg->newValue = 0;
  64. gcItems << GreyClusteringItem { "榴弹", 3, 2, 1, 1, sg };
  65. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  66. sg->units = "";
  67. sg->weiget = 5;
  68. sg->greyRanges << GreyRange { "较差类", true, 0.5, false, 0.65 };
  69. sg->greyRanges << GreyRange { "一般类", true, 0.65, false, 0.75 };
  70. sg->greyRanges << GreyRange { "较好类", true, 0.75, false, 0.9 };
  71. sg->leftExtension = 0.45;
  72. sg->rightExtension = 0.95;
  73. sg->oldValue = 0;
  74. sg->newValue = 0;
  75. gcItems << GreyClusteringItem { "首发命中", 4, 1, 1, 2, sg };
  76. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  77. sg->units = "m";
  78. sg->weiget = 5;
  79. sg->greyRanges << GreyRange { "较差类", true, 800, false, 1200 };
  80. sg->greyRanges << GreyRange { "一般类", true, 1200, false, 1600 };
  81. sg->greyRanges << GreyRange { "较好类", true, 1600, false, 2200 };
  82. sg->leftExtension = 500;
  83. sg->rightExtension = 2500;
  84. sg->oldValue = 0;
  85. sg->newValue = 0;
  86. gcItems << GreyClusteringItem { "直射距离", 5, 1, 1, 2, sg };
  87. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  88. sg->units = "发";
  89. sg->weiget = 3;
  90. sg->greyRanges << GreyRange { "较差类", true, 30, false, 40 };
  91. sg->greyRanges << GreyRange { "一般类", true, 40, false, 50 };
  92. sg->greyRanges << GreyRange { "较好类", true, 50, false, 65 };
  93. sg->leftExtension = 28;
  94. sg->rightExtension = 70;
  95. sg->oldValue = 0;
  96. sg->newValue = 0;
  97. gcItems << GreyClusteringItem { "弹药基数", 6, 1, 1, 2, sg };
  98. gcItems << GreyClusteringItem { "时间", 7, 1, 2, 1, nullptr };
  99. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  100. sg->units = "s";
  101. sg->weiget = 3;
  102. sg->greyRanges << GreyRange { "较差类", true, 11, false, 10 };
  103. sg->greyRanges << GreyRange { "一般类", true, 10, false, 7 };
  104. sg->greyRanges << GreyRange { "较好类", true, 7, false, 4 };
  105. sg->leftExtension = 12;
  106. sg->rightExtension = 3;
  107. sg->oldValue = 0;
  108. sg->newValue = 0;
  109. gcItems << GreyClusteringItem { "静对静", 7, 2, 1, 1, sg };
  110. sg = QSharedPointer<GreyClusteringValue>(new GreyClusteringValue);
  111. sg->units = "s";
  112. sg->weiget = 3;
  113. sg->greyRanges << GreyRange { "较差类", true, 14, false, 12 };
  114. sg->greyRanges << GreyRange { "一般类", true, 12, false, 10 };
  115. sg->greyRanges << GreyRange { "较好类", true, 10, false, 7 };
  116. sg->leftExtension = 15;
  117. sg->rightExtension = 5;
  118. sg->oldValue = 0;
  119. sg->newValue = 0;
  120. gcItems << GreyClusteringItem { "静对动", 8, 2, 1, 1, sg };
  121. GreyClusteringSampleTable gcst(gcItems, 3, 9);
  122. gcst.resize(1200, 800);
  123. gcst.refreshTableView();
  124. gcst.show();
  125. */
  126. GreyClusteringSampleTable::GreyClusteringSampleTable(CMind *mind, int grayNumber, QWidget *parent)
  127. : QTableView(parent), m_mind(mind), m_nodeDepth(2), m_grayNumber(grayNumber)
  128. {
  129. m_model = new QStandardItemModel();
  130. connect(m_model, &QStandardItemModel::itemChanged, this, &GreyClusteringSampleTable::itemChanged);
  131. this->setModel(m_model);
  132. init();
  133. refreshData();
  134. }
  135. void GreyClusteringSampleTable::refreshData()
  136. {
  137. loadData();
  138. loadSchemeData();
  139. initClusteringItems();
  140. refreshTableView();
  141. }
  142. void GreyClusteringSampleTable::refreshTableView()
  143. {
  144. m_isFillingData = true;
  145. m_model->clear();
  146. if (m_greyClusterings.size() == 0) {
  147. m_isFillingData = false;
  148. return;
  149. }
  150. QStringList greyNames; // 灰数
  151. for (auto &item : m_greyClusterings) {
  152. if (!item.value.isNull()) {
  153. for (const auto &s : item.value->greyRanges) {
  154. greyNames << s.name;
  155. }
  156. break;
  157. }
  158. }
  159. int colCount = m_nodeDepth + 6 + greyNames.size();
  160. // 设置表头
  161. {
  162. if (m_tableHeaderInitialized == false) {
  163. m_tableHeaderInitialized = true;
  164. auto hHeader = new MultiLevelHeaderView(Qt::Horizontal, 2, colCount, this);
  165. hHeader->setSectionResizeMode(QHeaderView::Stretch);
  166. hHeader->setCellSpan(0, 0, 2, m_nodeDepth); // 指标占位
  167. for (int n = 0; n < 2 + greyNames.size(); ++n) { // 单位+权重+灰度级占位
  168. hHeader->setCellSpan(0, m_nodeDepth + n, 2, 1);
  169. }
  170. hHeader->setCellSpan(0, m_nodeDepth + 2 + greyNames.size(), 1, 2); // 延拓值占位
  171. hHeader->setCellSpan(1, m_nodeDepth + 2 + greyNames.size(), 1, 1);
  172. hHeader->setCellSpan(1, m_nodeDepth + 2 + greyNames.size() + 1, 1, 1);
  173. hHeader->setCellSpan(0, m_nodeDepth + 4 + greyNames.size(), 1, 2); // 实现值占位
  174. hHeader->setCellSpan(1, m_nodeDepth + 4 + greyNames.size(), 1, 1);
  175. hHeader->setCellSpan(1, m_nodeDepth + 4 + greyNames.size() + 1, 1, 1);
  176. // 一级
  177. hHeader->setCellText(0, 0, QString("指标"));
  178. hHeader->setCellText(0, m_nodeDepth, QString("单位"));
  179. hHeader->setCellText(0, m_nodeDepth + 1, QString("权重"));
  180. for (int i = 0; i < greyNames.size(); ++i) {
  181. hHeader->setCellText(0, m_nodeDepth + 2 + i, greyNames.at(i));
  182. }
  183. hHeader->setCellText(0, m_nodeDepth + 2 + greyNames.size(), QString("延拓值"));
  184. hHeader->setCellText(0, m_nodeDepth + 4 + greyNames.size(), QString("实现值"));
  185. // 二级
  186. hHeader->setCellText(1, m_nodeDepth + 2 + greyNames.size(), "左");
  187. hHeader->setCellText(1, m_nodeDepth + 3 + greyNames.size(), "右");
  188. hHeader->setCellText(1, m_nodeDepth + 4 + greyNames.size(), "建设前");
  189. hHeader->setCellText(1, m_nodeDepth + 5 + greyNames.size(), "建设后");
  190. this->setHorizontalHeader(hHeader);
  191. }
  192. }
  193. m_model->setColumnCount(colCount);
  194. m_model->setRowCount(m_rowCount);
  195. for (const auto &item : m_greyClusterings) {
  196. // 第一步,设置指标名
  197. auto s = new QStandardItem(item.indexName);
  198. s->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  199. s->setTextAlignment(Qt::AlignCenter);
  200. s->setToolTip(item.indexName);
  201. m_model->setItem(item.row, item.col, s);
  202. if (item.rowSpan > 1 || item.colSpan > 1) {
  203. this->setSpan(item.row, item.col, item.rowSpan, item.colSpan);
  204. }
  205. // 第二步,查看当前指标下是否附带值
  206. if (!item.value.isNull()) {
  207. int offset = item.colSpan;
  208. m_model->setItem(item.row, item.col + offset, new QStandardItem(item.value->units)); // 单位
  209. ++offset;
  210. m_model->setItem(item.row, item.col + offset,
  211. new QStandardItem(QString::number(item.value->weiget))); // 权重
  212. ++offset;
  213. for (auto &range : item.value->greyRanges) { // 灰度级
  214. QString r;
  215. r += range.leftClose ? "[" : "(";
  216. r += QString("%1, %2").arg(range.leftValue).arg(range.rightValue);
  217. r += range.rightClose ? "]" : ")";
  218. m_model->setItem(item.row, item.col + offset, new QStandardItem(r));
  219. ++offset;
  220. }
  221. m_model->setItem(item.row, item.col + offset,
  222. new QStandardItem(QString::number(item.value->leftExtension))); // 延拓值左
  223. ++offset;
  224. m_model->setItem(item.row, item.col + offset,
  225. new QStandardItem(QString::number(item.value->rightExtension))); // 延拓值右
  226. ++offset;
  227. QStandardItem *oldValue = new QStandardItem;
  228. if (m_schemeData.keys().contains("建设前")) {
  229. oldValue->setText(m_schemeData["建设前"][item.indexName]);
  230. }
  231. m_model->setItem(item.row, item.col + offset, oldValue); // 实现值前
  232. ++offset;
  233. QStandardItem *newValue = new QStandardItem;
  234. if (m_schemeData.keys().contains("建设后")) {
  235. newValue->setText(m_schemeData["建设后"][item.indexName]);
  236. }
  237. m_model->setItem(item.row, item.col + offset, newValue); // 实现值后
  238. ++offset;
  239. for (int c = item.colSpan; c < offset - 2; ++c) {
  240. m_model->item(item.row, item.col + c)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  241. m_model->item(item.row, item.col + c)->setTextAlignment(Qt::AlignCenter);
  242. }
  243. for (int c = offset - 2; c < offset; ++c) {
  244. m_model->item(item.row, item.col + c)->setTextAlignment(Qt::AlignCenter);
  245. this->setItemDelegateForColumn(item.col + c, new GreyClusteringItemSpinDelegate(this));
  246. }
  247. }
  248. }
  249. m_isFillingData = false;
  250. }
  251. void GreyClusteringSampleTable::itemChanged(QStandardItem *item)
  252. {
  253. if (m_isFillingData) {
  254. return;
  255. }
  256. if (horizontalHeader()->model()->rowCount() < 2 || horizontalHeader()->model()->columnCount() <= item->column()) {
  257. return;
  258. }
  259. QModelIndex hIndex = horizontalHeader()->model()->index(1, item->column());
  260. QString hTitle = horizontalHeader()->model()->data(hIndex).toString();
  261. QStringList valueStrList;
  262. for (int r = 0; r < m_model->rowCount(); ++r) {
  263. QString vTitle = m_model->item(r, 1)->text();
  264. QString value = m_model->item(r, item->column())->text();
  265. QString valueStr = vTitle + ":" + value;
  266. valueStrList.append(valueStr);
  267. }
  268. QString v = valueStrList.join(";");
  269. SchemaEval scheme;
  270. scheme.engineerId = m_mind->root().projectId;
  271. scheme.name = hTitle;
  272. scheme.valueStr = v;
  273. scheme.type = 2;
  274. bool ret = SchemeInfoService().addUniqueGCEData(scheme);
  275. qDebug() << __FUNCTION__ << __LINE__ << ret << endl;
  276. }
  277. void GreyClusteringSampleTable::compute()
  278. {
  279. GCEMat mat;
  280. GCERangeMat ranges;
  281. QVector<GCEmat> samples;
  282. int colCount = m_nodeDepth + 4 + m_grayNumber;
  283. for (int r = 0; r < m_rowCount; ++r) {
  284. samples << GCEmat { m_model->item(r, colCount)->text().toDouble(),
  285. m_model->item(r, colCount + 1)->text().toDouble() };
  286. }
  287. mat = samples;
  288. // 指标
  289. for (const auto &item : m_greyClusterings) {
  290. if (!item.value.isNull()) {
  291. QVector<GCERange> rg;
  292. QSet<double> fullSet;
  293. fullSet << item.value->leftExtension;
  294. for (const auto &grange : item.value->greyRanges) {
  295. fullSet << grange.leftValue << grange.rightValue;
  296. }
  297. fullSet << item.value->rightExtension;
  298. QList<double> full = fullSet.toList();
  299. std::sort(full.begin(), full.end());
  300. for (int i = 0; i < item.value->greyRanges.size(); ++i) {
  301. double left;
  302. double right;
  303. int lloc = full.indexOf(item.value->greyRanges.at(i).leftValue);
  304. int rloc = full.indexOf(item.value->greyRanges.at(i).rightValue);
  305. if (lloc == 0) {
  306. left = full[0];
  307. } else {
  308. left = full[lloc - 1];
  309. }
  310. if (rloc == full.size() - 1) {
  311. right = full.last();
  312. } else {
  313. right = full[rloc + 1];
  314. }
  315. rg << GCERange { i, left, item.value->greyRanges.at(i).leftValue,
  316. item.value->greyRanges.at(i).rightValue, right };
  317. }
  318. ranges << rg;
  319. }
  320. }
  321. QScopedPointer<GreyClusterEvaluation> gc(new GreyClusterEvaluation(mat, ranges));
  322. MindWeightInfo info;
  323. bool ret = MindWeightService().queryWeightData(&info, m_mind->root().projectId, ProjectManager::EfficiencyIndex);
  324. if (ret == false) {
  325. return;
  326. }
  327. if (info.id < 0) {
  328. qDebug() << __FUNCTION__ << __LINE__ << "未找到指标权重数据" << endl;
  329. return;
  330. }
  331. QMap<QString, double> weightData;
  332. QStringList weightList = info.weight.split(";");
  333. for (QString keyValueStr : weightList) {
  334. QStringList keyValue = keyValueStr.split(":");
  335. if (keyValue.size() == 2) {
  336. weightData[keyValue.first()] = keyValue.last().toDouble();
  337. }
  338. }
  339. QVector<double> weights;
  340. QList<CNodeData> indexList = m_mind->leaves();
  341. for (int i = 0; i < indexList.size(); ++i) {
  342. weights.append(weightData[indexList[i].name]);
  343. }
  344. gc->evaluate(weights);
  345. gc->getBestIndex();
  346. QVector<GCEmat> rangeWeights = gc->getRangeWeights();
  347. QVector<GCEMat> rangeCvt = gc->getRangeCVT();
  348. QList<EffectResult> resultData;
  349. QList<int> schemeIdList = { -2, -1 };
  350. QList<QString> schemeNameList = { "建设前", "建设后" };
  351. for (int scheme = 0; scheme < 2; ++scheme) {
  352. EffectResult overall;
  353. overall.projectId = m_mind->root().projectId;
  354. overall.schemeId = schemeIdList[scheme];
  355. overall.schemeName = schemeNameList[scheme];
  356. overall.algType = 1;
  357. overall.indexName = "综合";
  358. QStringList strList;
  359. for (int v = 0; v < rangeWeights.size(); ++v) {
  360. if (scheme == 0) {
  361. strList.append(QString("%1").arg(rangeWeights[v].front_val));
  362. } else {
  363. strList.append(QString("%1").arg(rangeWeights[v].back_val));
  364. }
  365. }
  366. overall.value = strList.join(",");
  367. resultData.append(overall);
  368. for (int index = 0; index < indexList.size(); ++index) {
  369. EffectResult result;
  370. result.projectId = indexList[index].projectId;
  371. result.schemeId = schemeIdList[scheme];
  372. result.schemeName = schemeNameList[scheme];
  373. result.algType = 1;
  374. result.indexName = indexList[index].name;
  375. QStringList strList;
  376. for (int v = 0; v < rangeWeights.size(); ++v) {
  377. if (scheme == 0) {
  378. strList.append(QString("%1").arg(rangeCvt[index][v].front_val));
  379. } else {
  380. strList.append(QString("%1").arg(rangeCvt[index][v].back_val));
  381. }
  382. }
  383. result.value = strList.join(",");
  384. resultData.append(result);
  385. }
  386. }
  387. bool saveRet = EffectResultService().addDataList(resultData);
  388. qDebug() << __FUNCTION__ << __LINE__ << saveRet << endl;
  389. }
  390. void GreyClusteringSampleTable::init()
  391. {
  392. setAlternatingRowColors(false);
  393. horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
  394. horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  395. verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(244,244,244);color: black;}");
  396. verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
  397. setSelectionMode(QAbstractItemView::SingleSelection);
  398. }
  399. void GreyClusteringSampleTable::loadData()
  400. {
  401. QList<GradeInfo *> gradeInfoList;
  402. QMap<QString, QString> grayLevelMaps;
  403. int projectId = m_mind->root().projectId;
  404. if (!GradeInfoService().QueryGradeByProjectIdAndType(&gradeInfoList, projectId, 1)) {
  405. QMessageBox::warning(this, "警告", "数据库访问失败");
  406. } else {
  407. if (gradeInfoList.size() == 0) {
  408. for (int lvl = 0; lvl < m_grayNumber; ++lvl) {
  409. grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
  410. GradeInfo ginfo;
  411. ginfo.projectId = projectId;
  412. ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
  413. ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
  414. ginfo.type = 1;
  415. if (!GradeInfoService().AddGradeInfo(ginfo)) {
  416. QMessageBox::warning(this, "警告", "数据库访问失败");
  417. }
  418. }
  419. } else {
  420. for (const auto &gi : gradeInfoList) {
  421. grayLevelMaps.insert(gi->gradeName, gi->gradeValue);
  422. if (grayLevelMaps.size() >= m_grayNumber) {
  423. break;
  424. }
  425. }
  426. // 缺少再补
  427. for (int lvl = grayLevelMaps.size(); lvl < m_grayNumber; ++lvl) {
  428. grayLevelMaps.insert(QString("级别 %1:").arg(lvl + 1), QString("E%1").arg(lvl + 1));
  429. GradeInfo ginfo;
  430. ginfo.projectId = projectId;
  431. ginfo.gradeName = QString("级别 %1").arg(lvl + 1);
  432. ginfo.gradeValue = QString("灰类%1级").arg(lvl + 1);
  433. ginfo.type = 1;
  434. if (!GradeInfoService().AddGradeInfo(ginfo)) {
  435. QMessageBox::warning(this, "警告", "数据库访问失败");
  436. }
  437. }
  438. m_grayNames = grayLevelMaps.values();
  439. }
  440. }
  441. qDeleteAll(gradeInfoList);
  442. }
  443. void GreyClusteringSampleTable::loadSchemeData()
  444. {
  445. m_schemeData.clear();
  446. QList<SchemaEval *> schemeList;
  447. bool ret = SchemeInfoService().QuerySchemeInfoByEngineerId(&schemeList, m_mind->root().projectId, 2);
  448. if (ret == false) {
  449. return;
  450. }
  451. for (SchemaEval *scheme : schemeList) {
  452. if (m_schemeData.keys().contains(scheme->name) == false) {
  453. m_schemeData[scheme->name] = QMap<QString, QString>();
  454. }
  455. QStringList valueStrList = scheme->valueStr.split(";");
  456. for (QString valueStr : valueStrList) {
  457. QStringList keyValue = valueStr.split(":");
  458. if (keyValue.size() == 2) {
  459. m_schemeData[scheme->name][keyValue.first()] = keyValue.last();
  460. }
  461. }
  462. }
  463. }
  464. void GreyClusteringSampleTable::initClusteringItems()
  465. {
  466. // 脑图层级 < 2 时无效
  467. if (m_mind->levels() < 2) {
  468. return;
  469. }
  470. m_greyClusterings.clear();
  471. // 使用倒数第二层节点及其子节点
  472. int row = 0;
  473. for (CNodeData n : m_mind->nodesInLevel(m_mind->levels() - 1)) {
  474. GreyClusteringItem parentItem = { n.name, row, 0, 1, 1, nullptr };
  475. QList<CNodeData> subNodes = m_mind->subNodes(n);
  476. parentItem.colSpan = subNodes.size() == 0 ? 2 : 1; // 没有子节点,占两列,否则占一列
  477. parentItem.rowSpan = subNodes.size() == 0 ? 1 : subNodes.size(); // 没有子节点,占一行,否则占子节点数目行
  478. if (subNodes.size() == 0) { // 没有子节点,需要录入值
  479. GreyClusteringValue *sg = new GreyClusteringValue;
  480. sg->units = n.dimension;
  481. sg->weiget = 0;
  482. for (const auto &gname : m_grayNames) {
  483. sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
  484. }
  485. sg->leftExtension = 0;
  486. sg->rightExtension = 0;
  487. sg->oldValue = 0;
  488. sg->newValue = 0;
  489. parentItem.value.reset(sg);
  490. }
  491. m_greyClusterings.append(parentItem);
  492. int subRow = row;
  493. // 子节点
  494. for (const CNodeData &sub : subNodes) {
  495. // 因为已有父节点,所以在第2列
  496. GreyClusteringItem childItem = { sub.name, subRow, 1, 1, 1, nullptr };
  497. GreyClusteringValue *sg = new GreyClusteringValue;
  498. sg->units = sub.dimension;
  499. sg->weiget = 0;
  500. for (const auto &gname : m_grayNames) {
  501. sg->greyRanges << GreyRange { gname, true, 0, true, 0 };
  502. }
  503. sg->leftExtension = 0;
  504. sg->rightExtension = 0;
  505. sg->oldValue = 0;
  506. sg->newValue = 0;
  507. childItem.value.reset(sg);
  508. m_greyClusterings.append(childItem);
  509. subRow++;
  510. }
  511. row += parentItem.rowSpan;
  512. }
  513. m_rowCount = row;
  514. // 更新
  515. QList<EffectIndexInfo *> effectIndexInfoList;
  516. int projectid = m_mind->root().projectId;
  517. if (!EffectIndexInfoService().QueryEffectIndexInfoByProjectId(&effectIndexInfoList, projectid)) {
  518. QMessageBox::warning(this, "警告", "数据库访问失败");
  519. return;
  520. }
  521. if (effectIndexInfoList.size() > 0) {
  522. for (auto &item : m_greyClusterings) {
  523. if (item.value.isNull()) {
  524. continue;
  525. }
  526. for (const auto &effInfo : effectIndexInfoList) {
  527. if (effInfo->effectIndexName == item.indexName) {
  528. if (effInfo->effectIndexUnit.length() > 0) {
  529. // item.value->units = effInfo->effectIndexUnit;
  530. }
  531. item.value->leftExtension = effInfo->extendLeft.toDouble();
  532. item.value->rightExtension = effInfo->extendRight.toDouble();
  533. //[0:0],[0:0],[0:0]
  534. QStringList valueList;
  535. if (effInfo->effectIndexValue.length() > 0) {
  536. valueList = effInfo->effectIndexValue.split(",");
  537. }
  538. int align = qMin(valueList.size(), item.value->greyRanges.size());
  539. for (int str = 0; str < align; str++) {
  540. //[0:0]
  541. QStringList lr = valueList.at(str).mid(1, valueList.at(str).size() - 2).split(":");
  542. item.value->greyRanges[str].leftValue = lr.at(0).toDouble();
  543. item.value->greyRanges[str].rightValue = lr.at(1).toDouble();
  544. }
  545. }
  546. }
  547. }
  548. }
  549. qDeleteAll(effectIndexInfoList);
  550. if (projectid == kDemoProjId1) {
  551. QVector<double> left = { 2, 35, 2, 90, 2.5, 35, 70, 2.5, 35, 30, 2.5, 70, 25, 2, 50, 1, 45, 8, 60, 1 };
  552. QVector<double> right = { 4, 20, 3, 40, 0.5, 55, 90, 1.2, 55, 70, 1.2, 90, 60, 6, 20, 3, 75, 25, 25, 3 };
  553. int sn = 0;
  554. for (auto &item : m_greyClusterings) {
  555. if (item.value.isNull()) {
  556. continue;
  557. }
  558. if (sn < left.size()) {
  559. item.value->oldValue = left.at(sn);
  560. item.value->newValue = right.at(sn);
  561. }
  562. sn++;
  563. }
  564. }
  565. }