records.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <el-dialog
  3. width="70%"
  4. top="10vh"
  5. custom-class="modal"
  6. :close-on-click-modal="false"
  7. title="训练记录"
  8. v-model="dialogTableVisible"
  9. @opened="opened()"
  10. @closed="closed()"
  11. >
  12. <el-row :type="'flex'" class="content">
  13. <el-col :span="12" class="pd-l-8">
  14. <div style="font-size: 20px">历史记录</div>
  15. <div style="height: 60vh; overflow-y: auto; margin-top: 30px">
  16. <div v-if="supervisedFlag">
  17. <div
  18. class="body"
  19. v-for="(item, index) in recordList"
  20. :key="index"
  21. @click="chooses(index)"
  22. >
  23. <div class="left">
  24. <div :class="index === current ? 'round_on' : 'round'"></div>
  25. <div class="line"></div>
  26. </div>
  27. <div class="right">
  28. <div>{{ item.showTime }}</div>
  29. <div class="content">
  30. <div class="names">
  31. {{ item.showName || item.ducumentName }}
  32. </div>
  33. <button class="btn" @click="deleteDate(item.name)">
  34. 删除
  35. </button>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div v-else>
  41. <div
  42. class="body"
  43. v-for="(item, index) in showResultList"
  44. :key="index"
  45. @click="choose(index)"
  46. >
  47. <div class="left">
  48. <div :class="index === current ? 'round_on' : 'round'"></div>
  49. <div class="line"></div>
  50. </div>
  51. <div class="right">
  52. <div>{{ item.showTime }}</div>
  53. <div class="content">
  54. <div class="names">
  55. {{ item.showName || item.ducumentName }}
  56. </div>
  57. <button class="btn" @click="deleteDate(item.name)">
  58. 删除
  59. </button>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </el-col>
  66. <el-col :span="12" class="pd-l-8">
  67. <div style="margin-left: 30px; font-size: 20px">训练结果</div>
  68. <div v-if="supervisedFlag">
  69. <LineChart id="accuracyCharts" :dataList="accuracyList"></LineChart>
  70. <BarChart
  71. id="barCharts"
  72. @click="showDetials"
  73. height="350px"
  74. :barList="barList"
  75. :baseLine="recordList[current]?.coordinate?.BaseLine"
  76. ></BarChart>
  77. </div>
  78. <div v-else>
  79. <div
  80. class="scatterEchart"
  81. id="scatterEcharts"
  82. @click="showResults()"
  83. ></div>
  84. </div>
  85. </el-col>
  86. </el-row>
  87. <ChartDetails
  88. v-model="detialsDisplay"
  89. :barList="recordList[current]?.coordinate?.bar"
  90. :baseLine="recordList[current]?.coordinate?.BaseLine"
  91. ></ChartDetails>
  92. </el-dialog>
  93. </template>
  94. <script>
  95. import BarChart from ".//barChart.vue";
  96. import LineChart from "./lineChart.vue";
  97. import ChartDetails from "./chartDetails.vue";
  98. import * as echarts from "echarts";
  99. export default {
  100. components: {
  101. BarChart,
  102. LineChart,
  103. ChartDetails,
  104. },
  105. props: {
  106. supervisedFlag: {
  107. type: Boolean,
  108. default: false,
  109. },
  110. },
  111. data() {
  112. return {
  113. current: 0,
  114. accuracyList:{},
  115. barList: [],
  116. resultList: [],
  117. showResultList: [
  118. {
  119. showTime: '2021-12-08 12:02:00',
  120. showName: '牛首山UP82型风机DBSCAN模型',
  121. },
  122. {
  123. showTime: '2021-12-08 11:22:23',
  124. showName: '麻黄山UP77型风机DBSCAN模型',
  125. },
  126. ],
  127. recordList: [],
  128. detialsDisplay: false,
  129. colors: [
  130. "#FFFFFF",
  131. "#FF0000",
  132. "#820041",
  133. "#FF00FF",
  134. "#8600FF",
  135. "#0000C6",
  136. "#00FFFF",
  137. "#00DB00",
  138. "#F9F900",
  139. "#FF5809",
  140. "#984B4B",
  141. "#AFAF61",
  142. "#5151A2",
  143. "#FFAF60",
  144. "#B766AD",
  145. "#006030",
  146. "#2894FF",
  147. "#796400",
  148. ],
  149. series: [
  150. {
  151. name: "",
  152. symbolSize: 10,
  153. encode: { tooltip: [0, 1] },
  154. itemStyle: {
  155. color: "#ffffff",
  156. },
  157. data: [
  158. [11.0, 8.04],
  159. [8.07, 6.95],
  160. [13.0, 7.58],
  161. [9.05, 8.81],
  162. [11.0, 8.33],
  163. [14.0, 7.66],
  164. [13.4, 6.81],
  165. [10.0, 6.33],
  166. [14.0, 8.96],
  167. [12.5, 6.82],
  168. [9.15, 7.2],
  169. [11.5, 7.2],
  170. [3.03, 4.23],
  171. [12.2, 7.83],
  172. [2.02, 4.47],
  173. [1.05, 3.33],
  174. [4.05, 4.96],
  175. [6.03, 7.24],
  176. [12.0, 6.26],
  177. [12.0, 8.84],
  178. [7.08, 5.82],
  179. [5.02, 5.68],
  180. ],
  181. type: "scatter",
  182. },
  183. {
  184. name: "",
  185. encode: { tooltip: [0, 1] },
  186. symbolSize: 10,
  187. itemStyle: {
  188. color: "#FF0000",
  189. },
  190. data: [
  191. [1.0, 8.04],
  192. [18.07, 6.95],
  193. [3.0, 7.58],
  194. [19.05, 8.81],
  195. [1.0, 8.33],
  196. [4.0, 7.66],
  197. [3.4, 6.81],
  198. [20.0, 6.33],
  199. [4.0, 8.96],
  200. [2.5, 6.82],
  201. [19.15, 7.2],
  202. [11.5, 7.2],
  203. [3.03, 4.23],
  204. [12.2, 7.83],
  205. [2.02, 4.47],
  206. [1.05, 3.33],
  207. [4.05, 4.96],
  208. [6.03, 7.24],
  209. [12.0, 6.26],
  210. [12.0, 8.84],
  211. [7.08, 5.82],
  212. [5.02, 5.68],
  213. ],
  214. type: "scatter",
  215. },
  216. ],
  217. };
  218. },
  219. methods: {
  220. opened() {
  221. if (!this.supervisedFlag) {
  222. this.getRecords();
  223. this.getScatter();
  224. } else {
  225. this.getSupervisedRecord();
  226. }
  227. },
  228. showDetials() {
  229. this.detialsDisplay = true;
  230. },
  231. choose(index) {
  232. this.current = index;
  233. },
  234. chooses(index) {
  235. this.current = index;
  236. this.accuracyList.accuracy =
  237. this.recordList[this.current]?.coordinate.accuracy;
  238. this.accuracyList.val_accuracy =
  239. this.recordList[this.current]?.coordinate.val_accuracy;
  240. this.recordList[this.current]?.coordinate.bar?.sort(
  241. this.Compare("value")
  242. );
  243. this.barList = this.recordList[this.current]?.coordinate.bar?.slice(0, 5);
  244. },
  245. getRecords() {
  246. let that = this;
  247. this.API.requestData({
  248. method: "GET",
  249. baseURL: "http://10.155.32.14:9090/",
  250. subUrl: "api/coordinate/history",
  251. success(res) {
  252. if (res.length > 0) {
  253. res.forEach((item) => {
  254. let arr = item.name.split("-");
  255. item.coordinate = JSON.parse(item.coordinate);
  256. item.showName = arr[0];
  257. item.showTime = new Date(Number(arr[1])).formatDate(
  258. "yyyy-MM-dd hh:mm:ss"
  259. );
  260. });
  261. that.showResultList = res;
  262. that.dataDeal();
  263. }
  264. },
  265. });
  266. },
  267. getSupervisedRecord() {
  268. let that = this;
  269. this.API.requestData({
  270. method: "GET",
  271. baseURL: "http://192.168.10.18:8080/",
  272. subUrl: "api/supervised/history",
  273. success(res) {
  274. if (res) {
  275. res.forEach((item) => {
  276. let arr = item.name.split("-");
  277. item.coordinate = JSON.parse(item.coordinate);
  278. item.showName = arr[2];
  279. item.showTime = new Date(Number(arr[3])).formatDate(
  280. "yyyy-MM-dd hh:mm:ss"
  281. );
  282. item.coordinate.bar = JSON.parse(item.coordinate.bar);
  283. });
  284. that.accuracyList.accuracy = res[that.current]?.coordinate.accuracy;
  285. that.accuracyList.val_accuracy =
  286. res[that.current]?.coordinate.val_accuracy;
  287. res[that.current]?.coordinate.bar?.sort(that.Compare("value"));
  288. that.barList = res[that.current]?.coordinate.bar?.slice(0, 5);
  289. that.recordList = res;
  290. }
  291. },
  292. });
  293. },
  294. Compare(property) {
  295. return function (a, b) {
  296. var value1 = a[property];
  297. var value2 = b[property];
  298. return value2 - value1;
  299. };
  300. },
  301. dataDeal() {
  302. let that = this;
  303. that.resultList = [];
  304. let data = that.showResultList[that.current];
  305. let dataList = [];
  306. data?.coordinate.forEach((item, index) => {
  307. let idList = [];
  308. item.value.forEach((val) => {
  309. let datas = {};
  310. let arr = val[2].split("-");
  311. let dataArr = [];
  312. datas.name =
  313. arr[0] +
  314. "-" +
  315. new Date(Number(arr[1])).formatDate("yyyy-MM-dd hh:mm:ss");
  316. dataArr.push([Number(val[0]), Number(val[1])]);
  317. idList.push(arr[2]);
  318. datas.symbolSize = 10;
  319. datas.encode = { tooltip: [0, 1] };
  320. datas.data = dataArr;
  321. datas.type = "scatter";
  322. datas.itemStyle = { color: that.colors[index] };
  323. dataList.push(datas);
  324. });
  325. that.resultList.push(idList);
  326. });
  327. that.series = dataList;
  328. that.getScatter();
  329. },
  330. getScatter() {
  331. let chartDom = document.getElementById("scatterEcharts");
  332. let myChart = echarts.init(chartDom);
  333. let option;
  334. option = {
  335. legend: {
  336. show: true,
  337. data: ["测试", "测试1"],
  338. right: 56,
  339. icon: "circle",
  340. itemWidth: 6,
  341. inactiveColor: "#606769",
  342. textStyle: {
  343. color: "#B3BDC0",
  344. fontSize: 12,
  345. },
  346. },
  347. xAxis: {
  348. splitLine: { show: false },
  349. },
  350. yAxis: {
  351. splitLine: { show: false },
  352. },
  353. tooltip: {
  354. position: "top",
  355. },
  356. series: this.series,
  357. };
  358. option && myChart.setOption(option);
  359. },
  360. showResults() {
  361. this.showList = [];
  362. this.getFaultList(0);
  363. },
  364. deleteDate(val) {
  365. let that = this;
  366. this.API.requestData({
  367. method: "GET",
  368. baseURL: "http://192.168.10.18:8080/",
  369. subUrl: "api/coordinate/history/remove/",
  370. data: {
  371. names: val,
  372. },
  373. success(res) {
  374. if (res) {
  375. that.showResultList = [];
  376. that.barList = [];
  377. that.recordList = [];
  378. that.current = 0
  379. if (!that.supervisedFlag) {
  380. that.getRecords();
  381. that.getScatter();
  382. } else {
  383. that.getSupervisedRecord();
  384. }
  385. }
  386. },
  387. });
  388. },
  389. getFaultList(index) {
  390. let result = this.resultList[index];
  391. let that = this;
  392. this.API.requestData({
  393. method: "GET",
  394. baseURL: "http://192.168.11.18:8075/",
  395. subUrl: "fault/history/",
  396. data: {
  397. ids: result.join(","),
  398. },
  399. success(res) {
  400. if (res) {
  401. res.forEach((item) => {
  402. item.colors = that.colors[index];
  403. });
  404. that.showList =
  405. that.showList.length > 0 ? [that.showList, ...res] : res;
  406. index++;
  407. if (index < that.resultList.length) {
  408. that.getFaultList(index);
  409. } else {
  410. that.$emit("results", that.showList);
  411. }
  412. }
  413. },
  414. });
  415. },
  416. closed() {
  417. this.$emit("records-closed");
  418. },
  419. },
  420. };
  421. </script>
  422. <style lang="less" scoped>
  423. .body {
  424. display: flex;
  425. flex-direction: row;
  426. height: 75px;
  427. width: 100%;
  428. .left {
  429. display: flex;
  430. flex-direction: column;
  431. justify-content: center;
  432. align-items: center;
  433. width: 30px;
  434. margin-left: 30px;
  435. .round_on {
  436. width: 20px;
  437. height: 27px;
  438. border-radius: 50%;
  439. background-color: rgb(30, 209, 45);
  440. }
  441. .round {
  442. width: 20px;
  443. height: 27px;
  444. border-radius: 50%;
  445. background-color: crimson;
  446. }
  447. .line {
  448. width: 2px;
  449. height: 100%;
  450. background-color: #ffffff;
  451. }
  452. }
  453. .right {
  454. width: 100%;
  455. margin-left: 20px;
  456. .content {
  457. display: flex;
  458. flex-direction: row;
  459. justify-content: space-between;
  460. align-items: center;
  461. margin-top: 10px;
  462. .btn {
  463. margin-right: 20px;
  464. }
  465. }
  466. }
  467. }
  468. .scatterEchart {
  469. width: 600px;
  470. height: 500px;
  471. margin-top: -20px;
  472. }
  473. </style>