testReport.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <el-dialog custom-class="cDialog" top="50px" v-model="dialogVisible" width="80%" @opened="report()">
  3. <el-button style="position: absolute; right: 24px; top: 60px; z-index: 5000" type="primary" @click="exportPDF">
  4. 导出为PDF</el-button>
  5. <div class="pdfDom">
  6. <div class="title">故障检测报告</div>
  7. <div class="info">
  8. <div class="infoContent">
  9. <div class="contents">
  10. <div class="contentsTitle">风机编号:</div>
  11. <div>{{reportData.windturbineId}}</div>
  12. </div>
  13. <div class="contents">
  14. <div class="contentsTitle">风机型号:</div>
  15. <div>{{reportData.model}}</div>
  16. </div>
  17. <div class="contents">
  18. <div class="contentsTitle">故障发生时间:</div>
  19. <div>{{reportData.faultTime}}</div>
  20. </div>
  21. </div>
  22. <div class="infoContent">
  23. <div class="contents">
  24. <div class="contentsTitle">使用模型:</div>
  25. <div>{{modelName}}</div>
  26. </div>
  27. <div class="contents">
  28. <div class="contentsTitle">训练次数:</div>
  29. <div>{{reportData.trainingTimes}}次</div>
  30. </div>
  31. <div class="contents"></div>
  32. </div>
  33. <div class="result">
  34. <div class="moduleTitle">诊断结果:</div>
  35. <div class="resultContent">
  36. 诊断故障最大可能为<text style="color: #dc143c">{{faultResult}}</text>下表为各故障可能发生的实际概率:
  37. </div>
  38. <div class="resultTable">
  39. <el-table empty-text="暂无数据" :data="faultList"
  40. :header-cell-style="{ background: 'rgb(153,204,255)', color: '#000', 'font-size': '20px', }"
  41. :cell-style="{ 'font-size': '20px', color: '#696969', }" border stripe
  42. style="width: 100%; margin: 10px 0">
  43. <el-table-column prop="name" label="故障名称" align="center"></el-table-column>
  44. <el-table-column prop="percent" label="发生概率" align="center"></el-table-column>
  45. </el-table>
  46. </div>
  47. </div>
  48. <div class="result">
  49. <div class="moduleTitle">诊断依据:</div>
  50. <div class="resultContent">
  51. 根据风场情况,训练故障权重图、训练和测试准确率、训练模型误差率如下:
  52. </div>
  53. <div class="charts">
  54. <LineChart width="33.33%" v-if="lossList" id="reporLoss" :reportFlag="true" :dataList="lossList"></LineChart>
  55. <LineChart width="33.33%" v-if="accuracyList" id="reporAccuracy" :reportFlag="true" :dataList="accuracyList"> </LineChart>
  56. <BarChart width="33.33%" v-if="barList.length > 0" id="reportBar" :baseLine='BaseLine' :barList="barList"> </BarChart>
  57. </div>
  58. <div class="resultContent">
  59. 该模型训练和测试的准确率分别为<text style="color: #dc143c">{{result[0]}} 和 {{result[1]}}</text>;
  60. 误差率分别为<text style="color: #dc143c">{{result2[0]}} 和 {{result2[1]}}</text>;<br>
  61. 该模型训练所倚重的测点比重分别为:<text style="color: #dc143c" v-for="(item,index) in proportionList" :key="index">{{item.name+item.percent+(index != (proportionList.length-1)?'、':'')}}</text>。<br>
  62. 模型训练过程所有测点倚重占比如下表所示:
  63. </div>
  64. <div class="resultTable">
  65. <el-table empty-text="暂无数据" :data="proportionList" :header-cell-style="{ background: 'rgb(153,204,255)', color: '#000', 'font-size': '20px', }" :cell-style="{ 'font-size': '20px', color: '#696969', }" border stripe style="width: 100%; margin: 10px 0">
  66. <el-table-column prop="name" label="故障名称" align="center"></el-table-column>
  67. <el-table-column prop="percent" label="发生概率" align="center"></el-table-column>
  68. </el-table>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </el-dialog>
  74. </template>
  75. <script>
  76. import Get_PDF from "@tools/htmlToPdf";
  77. import LineChart from "./lineChart.vue";
  78. import BarChart from "./barChart.vue";
  79. export default {
  80. components: {
  81. LineChart,
  82. BarChart,
  83. },
  84. props: {
  85. faultid: '',
  86. },
  87. created() {
  88. },
  89. data() {
  90. return {
  91. result:[],
  92. result2:[],
  93. modelName:'',
  94. lossList: {},
  95. accuracyList: {},
  96. BaseLine: '',
  97. barList: [],
  98. faultResult:'',
  99. reportData: {},
  100. faultList: [{
  101. name: "齿轮箱故障",
  102. percent: "80%",
  103. },
  104. {
  105. name: "变频器故障",
  106. percent: "17%",
  107. },
  108. ],
  109. proportionList: [{
  110. name: "偏航位置",
  111. percent: "7.2%",
  112. },
  113. {
  114. name: "发电机转速",
  115. percent: "4.4%",
  116. }
  117. ],
  118. };
  119. },
  120. methods: {
  121. jzxF(arr){
  122. let jzx = [],
  123. jzxData = [],
  124. baselineAdd = 0;
  125. arr.forEach(ele => {
  126. if (parseFloat(ele.value) >= this.BaseLine) {
  127. baselineAdd += parseFloat(ele.value);
  128. jzx.push(ele)
  129. }
  130. })
  131. let jzxNum = [];
  132. let jzxNum2 = []; //初始顺序
  133. jzx.forEach(ele => {
  134. jzxNum.push(parseFloat(ele.value));
  135. jzxNum2.push(parseFloat(ele.value));
  136. })
  137. let jzxNumData = jzxNum.sort().reverse().slice(0, 5);
  138. jzxNumData.forEach(ele => {
  139. let idx = jzxNum2.indexOf(ele);
  140. jzxData.push({
  141. name: jzx[idx].name,
  142. percent: ((ele/baselineAdd)*100).toFixed(3) + "%",
  143. })
  144. })
  145. this.proportionList = jzxData;
  146. },
  147. history(name) {
  148. let that = this;
  149. that.API.requestData({
  150. method: "GET",
  151. baseURL: "http://10.155.32.14:9090/",
  152. subUrl: "api/supervised/history",
  153. success(res) {
  154. if (res) {
  155. let data = res.find(ele=>{
  156. return ele.name === name
  157. });
  158. data.coordinate = JSON.parse(data?.coordinate);
  159. data.coordinate.bar = JSON.parse(data?.coordinate.bar);
  160. that.lossList.loss = data?.coordinate.loss;
  161. that.lossList.val_loss = data?.coordinate.val_loss;
  162. that.BaseLine = parseFloat(data?.coordinate.BaseLine);
  163. that.accuracyList.accuracy = data?.coordinate.accuracy;
  164. that.accuracyList.val_accuracy = data?.coordinate.val_accuracy;
  165. data?.coordinate.bar?.sort(that.Compare("value"));
  166. that.barList = data?.coordinate.bar?.slice(0, 5);
  167. let accuracy = that.accuracyList.accuracy.sort()[that.accuracyList.accuracy.length-1];
  168. let val_accuracy = that.accuracyList.val_accuracy.sort()[that.accuracyList.val_accuracy.length-1];
  169. let loss = that.lossList.loss.sort()[that.lossList.loss.length-1];
  170. let val_loss = that.lossList.val_loss.sort()[that.lossList.val_loss.length-1];
  171. that.endResult(accuracy,val_accuracy,loss,val_loss);
  172. that.jzxF(data?.coordinate.bar);
  173. }
  174. },
  175. });
  176. },
  177. endResult(accuracy,val_accuracy,loss,val_loss){//取数组最后一位
  178. let result = [accuracy,val_accuracy];
  179. result.forEach((ele,index)=>{
  180. result[index] = (ele*100).toFixed(3)+'%'
  181. })
  182. let result2 = [loss,val_loss];
  183. result2.forEach((ele,index)=>{
  184. result2[index] = ele.toFixed(2)
  185. })
  186. this.result = result;
  187. this.result2 = result2;
  188. },
  189. Compare(property) {
  190. return function (a, b) {
  191. var value1 = a[property];
  192. var value2 = b[property];
  193. return value2 - value1;
  194. };
  195. },
  196. exportPDF(name) {// 导出PDF
  197. this.BASE.showMsg({
  198. type: "success",
  199. msg: "正在导出...请稍后...",
  200. });
  201. Get_PDF.downloadPDF(document.querySelector(".pdfDom"), "故障检测报告");
  202. },
  203. report() {
  204. let that = this;
  205. that.API.requestData({
  206. method: "GET",
  207. subUrl: "http://10.155.32.14:9090/api/autofault/report",
  208. success(res) {
  209. if (res) {
  210. res.forEach(ele => {
  211. if (ele.id === that.faultid) {
  212. that.history(ele.modelName)
  213. that.reportData = ele;
  214. that.modelName=ele.modelName.split('-')[2];
  215. let faultList = [],
  216. faultResult = '';
  217. ele.result.split(' ').forEach(ele => {
  218. let data = ele.split(':');
  219. if(data.length > 1){
  220. faultList.push({
  221. name: data[0],
  222. percent: data[1] * 100 + '%'
  223. })
  224. faultResult += data[0] + ':' + data[1] * 100 + '%,'
  225. }
  226. })
  227. that.faultResult = faultResult;
  228. that.faultList = faultList;
  229. }
  230. })
  231. }
  232. },
  233. });
  234. }
  235. },
  236. };
  237. </script>
  238. <style lang="less" scoped>
  239. .cDialog {
  240. position: relative;
  241. .pdfDom {
  242. padding: 30px 50px;
  243. }
  244. .title {
  245. text-align: center;
  246. font-size: 32px;
  247. font-weight: 700;
  248. }
  249. .info {
  250. display: flex;
  251. flex-direction: column;
  252. width: 100%;
  253. .infoContent {
  254. width: 100%;
  255. display: flex;
  256. flex-direction: row;
  257. align-items: center;
  258. justify-content: center;
  259. margin-bottom: 20px;
  260. font-size: 22px;
  261. .contents {
  262. display: flex;
  263. flex-direction: row;
  264. align-items: center;
  265. width: 33%;
  266. .contentsTitle {
  267. font-weight: bold;
  268. }
  269. }
  270. }
  271. .result {
  272. font-size: 22px;
  273. .resultTable {
  274. display: flex;
  275. width: 40%;
  276. margin-left: 30%;
  277. }
  278. .charts {
  279. display: flex;
  280. justify-content: left;
  281. }
  282. }
  283. }
  284. }
  285. </style>