channel.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. obj="";
  2. obj2 = "";
  3. get_org();
  4. function get_org(){
  5. var xhr = new XMLHttpRequest();
  6. var url = "/org";
  7. xhr.open("GET",url);
  8. xhr.onload = function(){
  9. obj = JSON.parse(xhr.responseText);
  10. //insertHTML();
  11. start();
  12. onChangeColumn1();
  13. onChangeColumn2();
  14. onChangeColumn3();
  15. click_button();
  16. };
  17. xhr.send();
  18. }
  19. function insertHTML2(data){
  20. //aria.innerHTML=data[0].tower_name;
  21. var inner='';
  22. for(var i=0;i<data.length;i++){
  23. inner+='<option value="'+data[i].tower_name+'">'+data[i].tower_name+'</option>';
  24. }
  25. document.getElementById("tower").innerHTML=inner;
  26. }
  27. function click_button() {
  28. //alert("click");
  29. companySelect=document.getElementById("company-list");
  30. factorySelect=document.getElementById("factory-list");
  31. departmentSelect=document.getElementById("department-list");
  32. towerGroupSelect=document.getElementById("towerGroup-list");
  33. if(companySelect.value!=0 && factorySelect.value!=0 && departmentSelect.value!=0 && towerGroupSelect.value!=0){
  34. var url2 = "tower/?company="+ companySelect.value + "&factory=" + factorySelect.value + "&department=" +departmentSelect.value + "&towerGroup=" +towerGroupSelect.value ;
  35. var xhr2 = new XMLHttpRequest();
  36. xhr2.open("GET",url2);
  37. xhr2.onload = function(){
  38. obj2 = JSON.parse(xhr2.responseText);
  39. insertHTML2(obj2);
  40. console.log(obj2);
  41. };
  42. xhr2.send();
  43. }
  44. }
  45. function start(){
  46. companySelect=document.getElementById("company-list");
  47. factorySelect=document.getElementById("factory-list");
  48. departmentSelect=document.getElementById("department-list");
  49. towerGroupSelect=document.getElementById("towerGroup-list");
  50. var inner='';
  51. var company_arr = new Array();
  52. for(var i=0;i<obj.length;i++){
  53. if(company_arr.indexOf(obj[i].company)==-1 && obj[i].able==1){
  54. inner=inner+'<option value="'+obj[i].company+'">公司'+obj[i].company+'</option>';
  55. company_arr.push(obj[i].company);
  56. }
  57. }
  58. //innerHTML 賦值inner給這element屬性
  59. companySelect.innerHTML=inner;
  60. }
  61. //製造一個字串,以html的語法填入院的陣列
  62. function onChangeColumn1() {
  63. companySelect=document.getElementById("company-list");
  64. factorySelect=document.getElementById("factory-list");
  65. departmentSelect=document.getElementById("department-list");
  66. towerGroupSelect=document.getElementById("towerGroup-list");
  67. factorySelect.innerHTML='';
  68. let factory_arr = new Array();
  69. let factory_inner = '';
  70. for(var i=0;i<obj.length;i++){
  71. if( companySelect.value == obj[i].company){
  72. if(factory_arr.indexOf(obj[i].factory)==-1 && obj[i].able==1){
  73. factory_inner=factory_inner+'<option value="'+obj[i].factory+'">廠區'+obj[i].factory+'</option>';
  74. factory_arr.push(obj[i].factory);
  75. }
  76. }
  77. //alert(companySelect.value);
  78. }
  79. factorySelect.innerHTML=factory_inner;
  80. }
  81. function onChangeColumn2() {
  82. companySelect=document.getElementById("company-list");
  83. factorySelect=document.getElementById("factory-list");
  84. departmentSelect=document.getElementById("department-list");
  85. towerGroupSelect=document.getElementById("towerGroup-list");
  86. departmentSelect.innerHTML='';
  87. let department_arr = new Array();
  88. let department_inner = '';
  89. for(var i=0;i<obj.length;i++){
  90. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory){
  91. if(department_arr.indexOf(obj[i].department)==-1 && obj[i].able==1){
  92. department_inner=department_inner+'<option value="'+obj[i].department+'">課'+obj[i].department+'</option>';
  93. department_arr.push(obj[i].department);
  94. }
  95. }
  96. }
  97. document.getElementById("department-list").innerHTML=department_inner;
  98. }
  99. function onChangeColumn3() {
  100. companySelect=document.getElementById("company-list");
  101. factorySelect=document.getElementById("factory-list");
  102. departmentSelect=document.getElementById("department-list");
  103. towerGroupSelect=document.getElementById("towerGroup-list");
  104. towerGroupSelect.innerHTML='';
  105. let towerGroup_inner = '';
  106. for(var i=0;i<obj.length;i++){
  107. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department){
  108. if( obj[i].able==1){
  109. for(var ii=0;ii<obj[i].group.length;ii++){
  110. towerGroup_inner=towerGroup_inner+'<option value="'+obj[i].group[ii]+'">機組'+obj[i].group[ii]+'</option>';
  111. }
  112. }
  113. }
  114. }
  115. document.getElementById("towerGroup-list").innerHTML= towerGroup_inner;
  116. }
  117. function get_data(){
  118. var xhr = new XMLHttpRequest();
  119. var url = "channel/dev001/ch01";
  120. obj3="";
  121. xhr.open("GET",url);
  122. xhr.onload = function(){
  123. obj3 = JSON.parse(xhr.responseText);
  124. insertHTML(obj3);
  125. console.log(obj3);
  126. };
  127. xhr.send();
  128. }
  129. function insertHTML(data){
  130. console.log(data);
  131. //aria.innerHTML=data[0].tower_name;
  132. var inner='<table> <tr> <th>主軸分析 </th><th>軸承分析 </th><th>馬達分析 </th><th>齒輪分析 </th> </tr> <tr>';
  133. inner+='<td>正常 不平衡 '+data.DW_Unbalance+'</td><td>正常 油膜旋震 '+data.DW_Whirl+'</td><td>正常 氣隙不均 '+data.DW_AirGap+'</td><td>正常 齒輪不對中 '+data.DW_GMisalignment+'</td></tr><tr>';
  134. inner+='<td>正常 軸彎曲 '+data.DW_Unbalance+'</td><td>正常 油膜晃蕩 '+data.DW_Whirl+'</td><td>正常 轉子條斷裂 '+data.DW_AirGap+'</td><td>正常 齒輪斷齒 '+data.DW_GMisalignment+'</td></tr><tr>';
  135. inner+='<td>正常 不對中 '+data.DW_Unbalance+'</td><td>正常 內還損傷 '+data.DW_Whirl+'</td><td>正常 相位問題 '+data.DW_AirGap+'</td><td>正常 齒輪磨損 '+data.DW_GMisalignment+'</td></tr><tr>';
  136. inner+='<td>正常 鬆動 '+data.DW_Unbalance+'</td><td>正常 外環損傷 '+data.DW_Whirl+'</td><td></td><td>正常 齒輪彎曲 '+data.DW_GMisalignment+'</td></tr><tr>';
  137. inner+='<td> </td><td>正常 滾珠損傷 '+data.DW_Whirl+'</td><td></td><td>正常 齒輪偏心 '+data.DW_GMisalignment+'</td></tr><tr>';
  138. document.getElementById("channel").innerHTML=inner;
  139. }
  140. get_data();
  141. get_chart_data();
  142. function get_chart_data(){
  143. var xhr = new XMLHttpRequest();
  144. var url = "channel_chart/dev001/ch01";
  145. obj="";
  146. xhr.open("GET",url);
  147. xhr.onload = function(){
  148. obj = JSON.parse(xhr.responseText);
  149. for(var i=0;i<obj.length;i++){
  150. var Data = {
  151. labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  152. datasets: [{
  153. label: obj[i].name, // tootip 出現的名稱
  154. lineTension: 0, // 曲線的彎度,設0 表示直線
  155. backgroundColor: "#ea464d",
  156. borderColor: "#ea464d",
  157. borderWidth: 5,
  158. data:obj[i].data, // 資料
  159. fill: false, // 是否填滿色彩
  160. },]
  161. };
  162. var ctx = document.getElementById(obj[i].name).getContext("2d");
  163. drawLineCanvas(ctx,Data);
  164. }
  165. };
  166. xhr.send();
  167. }
  168. // var lineChartData = {
  169. // labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  170. // datasets: [{
  171. // label: '未曾使用', // tootip 出現的名稱
  172. // lineTension: 0, // 曲線的彎度,設0 表示直線
  173. // backgroundColor: "#ea464d",
  174. // borderColor: "#ea464d",
  175. // borderWidth: 5,
  176. // data: [10, 12, 15, 18, 22, 33, 50, 60, 130], // 資料
  177. // fill: false, // 是否填滿色彩
  178. // },]
  179. // };
  180. function drawLineCanvas(ctx,data) {
  181. window.myLine = new Chart(ctx, { //先建立一個 chart
  182. type: 'line', // 型態
  183. data: data,
  184. options: {
  185. responsive: true,
  186. legend: { //是否要顯示圖示
  187. display: true,
  188. },
  189. tooltips: { //是否要顯示 tooltip
  190. enabled: true
  191. },
  192. scales: { //是否要顯示 x、y 軸
  193. xAxes: [{
  194. display: true
  195. }],
  196. yAxes: [{
  197. display: true
  198. }]
  199. },
  200. }
  201. });
  202. };
  203. // window.onload = function () {
  204. // var ctx = document.getElementById("canvas").getContext("2d");
  205. // drawLineCanvas(ctx,lineChartData);
  206. // };
  207. get_predict();
  208. function get_predict(){
  209. var xhr = new XMLHttpRequest();
  210. var url = "channel_predict/dev001/ch01";
  211. obj3="";
  212. xhr.open("GET",url);
  213. xhr.onload = function(){
  214. obj3 = JSON.parse(xhr.responseText);
  215. labels = new Array();
  216. for(var i=0;i<obj3.data.length;i++){
  217. labels.push(i);
  218. }
  219. var Data = {
  220. labels: labels, //顯示區間名稱
  221. datasets: [{
  222. label: "predict", // tootip 出現的名稱
  223. lineTension: 0, // 曲線的彎度,設0 表示直線
  224. backgroundColor: "#ea464d",
  225. borderColor: "#ea464d",
  226. borderWidth: 5,
  227. data:obj3.data, // 資料
  228. fill: false, // 是否填滿色彩
  229. },]
  230. };
  231. var ctx = document.getElementById("channel_predict").getContext("2d");
  232. drawLineCanvas(ctx,Data);
  233. };
  234. xhr.send();
  235. }
  236. get_frequency();
  237. function get_frequency(){
  238. var xhr = new XMLHttpRequest();
  239. var url = "channel_frequency/dev001/ch01";
  240. obj4="";
  241. xhr.open("GET",url);
  242. xhr.onload = function(){
  243. obj4 = JSON.parse(xhr.responseText);
  244. var Data = {
  245. labels: obj4.Hz, //顯示區間名稱
  246. datasets: [{
  247. label: "frequency", // tootip 出現的名稱
  248. lineTension: 0, // 曲線的彎度,設0 表示直線
  249. backgroundColor: "#ea464d",
  250. borderColor: "#ea464d",
  251. borderWidth: 5,
  252. data:obj4.value, // 資料
  253. fill: false, // 是否填滿色彩
  254. },]
  255. };
  256. var ctx = document.getElementById("channel_frequency").getContext("2d");
  257. drawLineCanvas(ctx,Data);
  258. };
  259. xhr.send();
  260. }