tower.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. var xhr = new XMLHttpRequest();
  2. var url = "tower/org";
  3. obj = "";
  4. xhr.open("GET", url);
  5. xhr.onload = function () {
  6. obj = JSON.parse(xhr.responseText);
  7. //insertHTML();
  8. start();
  9. onChangeColumn1();
  10. onChangeColumn2();
  11. onChangeColumn3();
  12. click_button();
  13. };
  14. xhr.send();
  15. function insertHTML(data) {
  16. var tower_select = document.getElementById('tower');
  17. //aria.innerHTML=data[0].tower_name;
  18. var inner = '';
  19. for (var i = 0; i < data.length; i++) {
  20. if (i >= 3) {
  21. inner = inner + '<button type="button" class="btn btn-primary m-1" onclick="tower_info(\'' + data[0].tower_name + '\');">' + data[i].tower_name + '</button>';
  22. }
  23. else {
  24. inner = inner + '<button type="button" class="btn btn-primary m-1" onclick="tower_info(\'' + data[i].tower_name + '\');">' + data[i].tower_name + '</button>';
  25. }
  26. console.log(inner);
  27. }
  28. tower_select.innerHTML = inner;
  29. }
  30. obj2 = "";
  31. function click_button() {
  32. //alert("click");
  33. companySelect = document.getElementById("company-list");
  34. factorySelect = document.getElementById("factory-list");
  35. departmentSelect = document.getElementById("department-list");
  36. towerGroupSelect = document.getElementById("towerGroup-list");
  37. if (companySelect.value != 0 && factorySelect.value != 0 && departmentSelect.value != 0 && towerGroupSelect.value != 0) {
  38. var url2 = "tower/?company=" + companySelect.value + "&factory=" + factorySelect.value + "&department=" + departmentSelect.value + "&towerGroup=" + towerGroupSelect.value;
  39. var xhr2 = new XMLHttpRequest();
  40. xhr2.open("GET", url2);
  41. xhr2.onload = function () {
  42. obj2 = JSON.parse(xhr2.responseText);
  43. insertHTML(obj2);
  44. tower_info(obj2[0].tower_name);
  45. };
  46. xhr2.send();
  47. }
  48. }
  49. function tower_info(tower_str) {
  50. tower = tower_str;
  51. console.log(tower);
  52. inner = "";
  53. for (var i = 0; i < obj2.length; i++) {
  54. if (obj2[i].tower_name == tower) {
  55. // inner = '<p> DCS </P> '+
  56. // '<p> 入水溫度 = '+ obj2[i].tower_data.DCS.hotTemp + ' </P> ' +
  57. // '<p> 出水溫度 = '+ obj2[i].tower_data.DCS.coldTemp + ' </P> ' +
  58. // '<p> 水流量 = '+ obj2[i].tower_data.DCS.waterFlow + ' </P> ' +
  59. // '<p> 風扇馬達電流 = '+ obj2[i].tower_data.DCS.fanMotorCur + ' </P> ' +
  60. // '<p> 風扇馬達轉速頻率 = '+ obj2[i].tower_data.DCS.fanMotorSpeedFreq + ' </P><br> ' +
  61. // '<p> 風扇震動 </P> '+
  62. // '<p> 馬達震動 = '+ obj2[i].tower_data.Moter.ch01.Vrms + ' </P> ' +
  63. // '<p> 減速機震動 = '+ obj2[i].tower_data.Fan.reducer + ' </P> ' +
  64. // '<p> 靜壓機 = '+ obj2[i].tower_data.Fan.staticPressure + ' </P> ' +
  65. // '<p> 水流量 = '+ obj2[i].tower_data.Fan.waterFlow + ' </P> ' +
  66. // '<p> 濕求溫度 = '+ obj2[i].tower_data.Fan.wetTemp + ' </P> ' +
  67. // '<p> 水冷槽溫度1 = '+ obj2[i].tower_data.Fan.coldTempData1 + ' </P> ' +
  68. // '<p> 水冷槽溫度2 = '+ obj2[i].tower_data.Fan.coldTempData2 + ' </P><br> ' +
  69. // '<p> 馬達震動 </P> '+
  70. // '<p> ch001,通道1'+ obj2[i].tower_data.Moter.ch01.Vrms + ',' + obj2[i].tower_data.Moter.ch01.CV+' </P> ' +
  71. // '<p> ch002,通道2'+ obj2[i].tower_data.Moter.ch02.Vrms + ',' + obj2[i].tower_data.Moter.ch02.CV+' </P> '
  72. // ;
  73. inner = ' <h1 class="ms-3"><i style="color:#0174c7;" class="fas fa-file-signature me-1"></i>中控室DSC訊號</h1>\
  74. <div class="row px-0 mx-0">\
  75. <div class="card col-lg-2">\
  76. <p class="data-title fw-bold">入水溫度</p>\
  77. <div>\
  78. <h2 class="text-center">'+ obj2[i].tower_data.DCS.hotTemp + '</h2>\
  79. <P class="unit text-end">°C</P>\
  80. </div>\
  81. </div>\
  82. <div class="card col-lg-2">\
  83. <p class="data-title fw-bold">出水溫度</p>\
  84. <div>\
  85. <h2 class="text-center">'+ obj2[i].tower_data.DCS.coldTemp + '</h2>\
  86. <P class="unit text-end">°C</P>\
  87. </div>\
  88. </div>\
  89. <div class="card col-lg-2">\
  90. <p class="data-title fw-bold ">水流量</p>\
  91. <div>\
  92. <h2 class="text-center">'+ obj2[i].tower_data.DCS.waterFlow + '</h2>\
  93. <P class="unit text-end">M³/H</P>\
  94. </div>\
  95. </div>\
  96. <div class="card col-lg-2">\
  97. <p class="data-title fw-bold">風扇馬達電流</p>\
  98. <div>\
  99. <h2 class="text-center">'+ obj2[i].tower_data.DCS.fanMotorCur + '</h2>\
  100. <P class="unit text-end">A</P>\
  101. </div>\
  102. </div>\
  103. <div class="card col-lg-2">\
  104. <p class="data-title fw-bold ">風扇馬達轉速頻率</p>\
  105. <div>\
  106. <h2 class="text-center">'+ obj2[i].tower_data.DCS.fanMotorSpeedFreq + '&ensp;</h2>\
  107. <P class="unit text-end">Hz</P>\
  108. </div>\
  109. </div>\
  110. </div>\
  111. <div class="card mt-5">\
  112. <div class="row">\
  113. <div class="col-lg-6">\
  114. <h1><i style="color:#0174c7;" class="fas fa-tachometer-alt me-2"></i>風扇震動</h1>\
  115. </div>\
  116. <div class="col-lg-6">\
  117. <h1><i style=" color:#0174c7;" class="fas fa-cogs me-2"></i>馬達震動</h1>\
  118. </div>\
  119. </div>\
  120. <div>\
  121. <div class="row px-0 mx-0">\
  122. <div class="col-lg-6">\
  123. <table style="font-size:16px;" class="table">\
  124. <thead>\
  125. <tr>\
  126. <th scope="col">數據名稱</th>\
  127. <th scope="col">值</th>\
  128. <th scope="col">單位</th>\
  129. </tr>\
  130. </thead>\
  131. <tbody>\
  132. <tr>\
  133. <td>馬達震動</td>\
  134. <td>'+ obj2[i].tower_data.Moter[0].Vrms + '</td>\
  135. <td>mm/s</td>\
  136. </tr>\
  137. <tr>\
  138. <td>減速機震動</td>\
  139. <td>'+ obj2[i].tower_data.Fan.reducer + '</td>\
  140. <td>mm/s</td>\
  141. </tr>\
  142. <tr>\
  143. <td>靜壓機</td>\
  144. <td>'+ obj2[i].tower_data.Fan.staticPressure + '</td>\
  145. <td>pa</td>\
  146. </tr>\
  147. <tr>\
  148. <td>水流量</td>\
  149. <td>'+ obj2[i].tower_data.Fan.waterFlow + '</td>\
  150. <td>M³/H</td>\
  151. </tr>\
  152. <tr>\
  153. <td>濕求溫度</td>\
  154. <td>'+ obj2[i].tower_data.Fan.wetTemp + '</td>\
  155. <td>°C</td>\
  156. </tr>\
  157. <tr>\
  158. <td>水冷槽溫度1</td>\
  159. <td>'+ obj2[i].tower_data.Fan.coldTempData1 + '</td>\
  160. <td>°C</td>\
  161. </tr>\
  162. <tr>\
  163. <td>水冷槽溫度2</td>\
  164. <td>'+ obj2[i].tower_data.Fan.coldTempData2 + '</td>\
  165. <td>°C</td>\
  166. </tr>\
  167. </tbody>\
  168. </table>\
  169. </div>\
  170. <div class="col-lg-6">\
  171. <div class="row px-0 mx-0">\
  172. <div class="card col-lg-5">\
  173. <p class="fw-bold ">ch001,通道1</p>\
  174. <div>\
  175. <p class="text-center">'+ obj2[i].tower_data.Moter[0].Vrms + ',' + obj2[i].tower_data.Moter[0].CV + '</p>\
  176. </div>\
  177. </div>\
  178. <div class="card col-lg-5">\
  179. <p class="fw-bold ">ch002,通道2</p>\
  180. <div>\
  181. <p class="text-center">'+ obj2[i].tower_data.Moter[1].Vrms + ',' + obj2[i].tower_data.Moter[1].CV + '</p>\
  182. </div>\
  183. </div>\
  184. <div class="card col-lg-5">\
  185. <p class="fw-bold ">ch003,通道3</p>\
  186. <div>\
  187. <p class="text-center">'+ obj2[i].tower_data.Moter[2].Vrms + ',' + obj2[i].tower_data.Moter[2].CV + '</p>\
  188. </div>\
  189. </div>\
  190. <div class="card col-lg-5">\
  191. <p class="fw-bold ">ch004,通道4</p>\
  192. <div>\
  193. <p class="text-center">'+ obj2[i].tower_data.Moter[3].Vrms + ',' + obj2[i].tower_data.Moter[3].CV + '</p>\
  194. </div>\
  195. </div>\
  196. </div>\
  197. </div>\
  198. </div>\
  199. </div>\
  200. </div>';
  201. console.log(obj2[i].tower_data.Moter[3].Vrms);
  202. }
  203. }
  204. document.getElementById("tower_info").innerHTML = inner;
  205. console.log(inner);
  206. get_tower_perfrom('dev001');
  207. }
  208. //document就是這html文件。
  209. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  210. function start() {
  211. companySelect = document.getElementById("company-list");
  212. factorySelect = document.getElementById("factory-list");
  213. departmentSelect = document.getElementById("department-list");
  214. towerGroupSelect = document.getElementById("towerGroup-list");
  215. var inner = '';
  216. var company_arr = new Array();
  217. for (var i = 0; i < obj.length; i++) {
  218. if (company_arr.indexOf(obj[i].company) == -1 && obj[i].able == 1) {
  219. inner = inner + '<option value="' + obj[i].company + '">公司' + obj[i].company + '</option>';
  220. company_arr.push(obj[i].company);
  221. }
  222. }
  223. //innerHTML 賦值inner給這element屬性
  224. companySelect.innerHTML = inner;
  225. }
  226. //製造一個字串,以html的語法填入院的陣列
  227. function onChangeColumn1() {
  228. companySelect = document.getElementById("company-list");
  229. factorySelect = document.getElementById("factory-list");
  230. departmentSelect = document.getElementById("department-list");
  231. towerGroupSelect = document.getElementById("towerGroup-list");
  232. factorySelect.innerHTML = '';
  233. let factory_arr = new Array();
  234. let factory_inner = '';
  235. for (var i = 0; i < obj.length; i++) {
  236. if (companySelect.value == obj[i].company) {
  237. if (factory_arr.indexOf(obj[i].factory) == -1 && obj[i].able == 1) {
  238. factory_inner = factory_inner + '<option value="' + obj[i].factory + '">廠區' + obj[i].factory + '</option>';
  239. factory_arr.push(obj[i].factory);
  240. }
  241. }
  242. //alert(companySelect.value);
  243. }
  244. factorySelect.innerHTML = factory_inner;
  245. }
  246. function onChangeColumn2() {
  247. companySelect = document.getElementById("company-list");
  248. factorySelect = document.getElementById("factory-list");
  249. departmentSelect = document.getElementById("department-list");
  250. towerGroupSelect = document.getElementById("towerGroup-list");
  251. departmentSelect.innerHTML = '';
  252. let department_arr = new Array();
  253. let department_inner = '';
  254. for (var i = 0; i < obj.length; i++) {
  255. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory) {
  256. if (department_arr.indexOf(obj[i].department) == -1 && obj[i].able == 1) {
  257. department_inner = department_inner + '<option value="' + obj[i].department + '">課' + obj[i].department + '</option>';
  258. department_arr.push(obj[i].department);
  259. }
  260. }
  261. }
  262. document.getElementById("department-list").innerHTML = department_inner;
  263. }
  264. function onChangeColumn3() {
  265. companySelect = document.getElementById("company-list");
  266. factorySelect = document.getElementById("factory-list");
  267. departmentSelect = document.getElementById("department-list");
  268. towerGroupSelect = document.getElementById("towerGroup-list");
  269. towerGroupSelect.innerHTML = '';
  270. let towerGroup_inner = '';
  271. for (var i = 0; i < obj.length; i++) {
  272. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department) {
  273. if (obj[i].able == 1) {
  274. for (var ii = 0; ii < obj[i].group.length; ii++) {
  275. towerGroup_inner = towerGroup_inner + '<option value="' + obj[i].group[ii] + '">機組' + obj[i].group[ii] + '</option>';
  276. }
  277. }
  278. }
  279. }
  280. document.getElementById("towerGroup-list").innerHTML = towerGroup_inner;
  281. }
  282. function get_tower_perfrom(tower_id) {
  283. var xhr3 = new XMLHttpRequest();
  284. var url3 = "tower/performance/" + tower_id;
  285. console.log("sss");
  286. obj3 = "";
  287. xhr3.open("GET", url3);
  288. xhr3.onload = function () {
  289. obj3 = JSON.parse(xhr3.responseText);
  290. console.log(obj3);
  291. tower_perform_show(obj3);
  292. };
  293. xhr3.send();
  294. }
  295. function tower_perform_show(obj_tmp) {
  296. inner = "<div class='card mt-5'><div class='row'>\
  297. <div class='col-lg-6'>\
  298. <h1><i style='color:#0174c7;' class='fas fa-tachometer-alt me-2'></i>設計條件</h1>\
  299. </div>\
  300. <div class='col-lg-6'>\
  301. <h1><i style='color:#0174c7;' class='fas fa-cogs me-2'></i>測試狀態</h1>\
  302. </div>\
  303. <div>\
  304. <div class='row px-0 mx-0'>\
  305. <div class='col-lg-6'>\
  306. <table style='font-size:16px;' class='table'>\
  307. <thead>\
  308. <tr>\
  309. <th scope='col'>數據名稱</th>\
  310. <th scope='col'>值</th>\
  311. <th scope='col'>單位</th>\
  312. </tr>\
  313. </thead>\
  314. <tbody>\
  315. <tr>\
  316. <td>水流量</td>\
  317. <td>" + obj_tmp[0].designWFR + "</td>\
  318. <td>M³/H</td>\
  319. </tr>\
  320. <tr>\
  321. <td>風車馬力</td>\
  322. <td>" + obj_tmp[0].designHP + "</td>\
  323. <td>mm/s</td>\
  324. </tr>\
  325. <tr>\
  326. <td>額定電流</td>\
  327. <td>" + obj_tmp[0].designCurrent + "</td>\
  328. <td>A</td>\
  329. </tr>\
  330. <tr>\
  331. <td>入水溫度</td>\
  332. <td>" + obj_tmp[0].designHWT + "</td>\
  333. <td>°C</td>\
  334. </tr>\
  335. <tr>\
  336. <td>出水溫度</td>\
  337. <td>" + obj_tmp[0].designCWT + "</td>\
  338. <td>°C</td>\
  339. </tr>\
  340. <tr>\
  341. <td>濕求溫度</td>\
  342. <td>" + obj_tmp[0].designWBT + "</td>\
  343. <td>°C</td>\
  344. </tr>\
  345. </tbody>\
  346. </table>\
  347. </div>\
  348. <div class='col-lg-6'>\
  349. <table style='font-size:16px;' class='table'>\
  350. <thead>\
  351. <tr>\
  352. <th scope='col'>數據名稱</th>\
  353. <th scope='col'>值</th>\
  354. <th scope='col'>單位</th>\
  355. </tr>\
  356. </thead>\
  357. <tbody>\
  358. <tr>\
  359. <td>水流量</td>\
  360. <td>" + obj_tmp[0].testWFR + "</td>\
  361. <td>M³/H</td>\
  362. </tr>\
  363. <tr>\
  364. <td>風車馬力</td>\
  365. <td> " + obj_tmp[0].testBHP + "</td>\
  366. <td>mm/s</td>\
  367. </tr>\
  368. <tr>\
  369. <td>運轉電流</td>\
  370. <td>" + obj_tmp[0].testCurrent + "</td>\
  371. <td>A</td>\
  372. </tr>\
  373. <tr>\
  374. <td>入水溫度</td>\
  375. <td>" + obj_tmp[0].testHWT + "</td>\
  376. <td>°C</td>\
  377. </tr>\
  378. <tr>\
  379. <td>出水溫度</td>\
  380. <td>" + obj_tmp[0].testCorrectCWT + "</td>\
  381. <td>°C</td>\
  382. </tr>\
  383. <tr>\
  384. <td>濕求溫度</td>\
  385. <td>" + obj_tmp[0].testWBT + "</td>\
  386. <td>°C</td>\
  387. </tr>\
  388. <tr>\
  389. <td>風速</td>\
  390. <td>" + obj_tmp[0].testWindSpeed + "</td>\
  391. <td>°C</td>\
  392. </tr>\
  393. <tr>\
  394. <td>補充水量</td>\
  395. <td>" + obj_tmp[0].testMakeupWFR + "</td>\
  396. <td>°C</td>\
  397. </tr>\
  398. <tr>\
  399. <td>補充水溫</td>\
  400. <td>" + obj_tmp[0].testMakeupCWT + "</td>\
  401. <td>°C</td>\
  402. </tr>\
  403. <tr>\
  404. <td>CORRECT CWT</td>\
  405. <td> " + obj_tmp[0].testCorrectCWT + "</td>\
  406. <td>°C</td>\
  407. </tr>\
  408. <tr>\
  409. <td>COLLING RANGE</td>\
  410. <td> " + obj_tmp[0].testCoolingRange + "</td>\
  411. <td>°C</td>\
  412. </tr>\
  413. </tbody>\
  414. </table>\
  415. </div>\
  416. </div>\
  417. </div>\
  418. </div>" ;
  419. // "測試狀態<br> " +
  420. // "水流量: " + obj_tmp[0].testWFR + "<br>" +
  421. // "風車馬力: " + obj_tmp[0].testBHP + "<br>" +
  422. // "運轉電流: " + obj_tmp[0].testCurrent + "<br>" +
  423. // "入水溫度: " + obj_tmp[0].testHWT + "<br>" +
  424. // "出水溫度: " + obj_tmp[0].testCorrectCWT + "<br>" +
  425. // "濕球溫度: " + obj_tmp[0].testWBT + "<br>" +
  426. // "風速: " + obj_tmp[0].testWindSpeed + "<br>" +
  427. // "補充水量: " + obj_tmp[0].testMakeupWFR + "<br>" +
  428. // "補充水溫: " + obj_tmp[0].testMakeupCWT + "<br>" +
  429. // "CORRECT CWT: " + obj_tmp[0].testCorrectCWT + "<br>" +
  430. // "COLLING RANGE: " + obj_tmp[0].testCoolingRange + "<br>";
  431. document.getElementById('tower_perfrom').innerHTML = inner;
  432. }
  433. // function tower_perform_show(obj_tmp){
  434. // inner = "設計條件<br>" +
  435. // "水流量: " + obj_tmp[0].designWFR + "<br>" +
  436. // "風車馬力: " + obj_tmp[0].designHP + "<br>" +
  437. // "額定電流: " + obj_tmp[0].designCurrent + "<br>" +
  438. // "入水溫度: " + obj_tmp[0].designHWT + "<br>" +
  439. // "出水溫度: " + obj_tmp[0].designCWT + "<br>" +
  440. // "濕求溫度: " + obj_tmp[0].designWBT + "<br>" +
  441. // "測試狀態<br> " +
  442. // "水流量: " + obj_tmp[0].testWFR + "<br>" +
  443. // "風車馬力: " + obj_tmp[0].testBHP + "<br>" +
  444. // "運轉電流: " + obj_tmp[0].testCurrent + "<br>" +
  445. // "入水溫度: " + obj_tmp[0].testHWT + "<br>" +
  446. // "出水溫度: " + obj_tmp[0].testCorrectCWT + "<br>" +
  447. // "濕球溫度: " + obj_tmp[0].testWBT + "<br>" +
  448. // "風速: " + obj_tmp[0].testWindSpeed + "<br>" +
  449. // "補充水量: " + obj_tmp[0].testMakeupWFR + "<br>" +
  450. // "補充水溫: " + obj_tmp[0].testMakeupCWT + "<br>" +
  451. // "CORRECT CWT: " + obj_tmp[0].testCorrectCWT + "<br>" +
  452. // "COLLING RANGE: " + obj_tmp[0].testCoolingRange + "<br>" ;
  453. // document.getElementById('tower_perfrom').innerHTML=inner;
  454. // }
  455. get_predict();
  456. function get_predict() {
  457. var xhr = new XMLHttpRequest();
  458. var url = "channel_predict/dev001/ch01";
  459. obj3 = "";
  460. xhr.open("GET", url);
  461. xhr.onload = function () {
  462. obj3 = JSON.parse(xhr.responseText);
  463. labels = new Array();
  464. for (var i = 0; i < obj3.data.length; i++) {
  465. labels.push(i);
  466. }
  467. console.log(obj3)
  468. var Data = {
  469. labels: labels, //顯示區間名稱
  470. datasets: [{
  471. label: "predict", // tootip 出現的名稱
  472. lineTension: 0, // 曲線的彎度,設0 表示直線
  473. backgroundColor: "#ea464d",
  474. borderColor: "#ea464d",
  475. borderWidth: 5,
  476. data: obj3.data, // 資料
  477. fill: false, // 是否填滿色彩
  478. },]
  479. };
  480. var ctx = document.getElementById("channel_predict").getContext("2d");
  481. drawLineCanvas(ctx, Data);
  482. };
  483. xhr.send();
  484. }
  485. function drawLineCanvas(ctx, data) {
  486. window.myLine = new Chart(ctx, { //先建立一個 chart
  487. type: 'line', // 型態
  488. data: data,
  489. showSymbol:false,
  490. options: {
  491. responsive: true,
  492. legend: { //是否要顯示圖示
  493. display: true,
  494. },
  495. tooltips: { //是否要顯示 tooltip
  496. enabled: true
  497. },
  498. scales: { //是否要顯示 x、y 軸
  499. xAxes: [{
  500. display: true
  501. }],
  502. yAxes: [{
  503. display: true
  504. }]
  505. },
  506. }
  507. });
  508. };