r03.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. var unityName = "R03Monitor";
  2. var errorTable;
  3. var sites = {};
  4. $.ajaxSettings.async = false;
  5. var jqxhr = $.getJSON("/BIM-Monitor/assets/errorTable.json", function (json) {
  6. errorTable = json;
  7. });
  8. var C3Json = $.getJSON("/BIM-Monitor/assets/json/c3-monitorList.json", function (json) {
  9. sites["c3"] = json;
  10. });
  11. var R03Json = $.getJSON("/BIM-Monitor/assets/json/r03-monitorList.json", function (json) {
  12. sites["r03"] = json;
  13. });
  14. $.ajaxSettings.async = true;
  15. var lastNode;
  16. var errorArray = [];
  17. var switchNumber = 0;
  18. passString('SIS');
  19. var wellTBA = [];
  20. var wellNameLists = [];
  21. var isAll = true;
  22. var isCompare = false;
  23. var saveCheckCompare = "";
  24. var dataTable;
  25. $(document).ready(function () {
  26. GetCheckAllAJAXValue();
  27. LoadPage();
  28. $("#menu > ul > li.nav-parent.nav-active.nav-expanded > ul > li.nav-parent.nav-active.nav-expanded > ul > li:nth-child(1) > a").css("color", "#0088cc");
  29. $(".monitor").on('click', function () {
  30. $('.monitor').css('color', '#abb4be')
  31. let site = $(this).parent().parent().parent().attr("monitor");
  32. $(this).css("color", "#0088cc");
  33. if (site != 'r03') {
  34. location.href = `../${site}/Index.php`;
  35. } else {
  36. let option = $(this).attr("monitor");
  37. isAll = true;
  38. isCompare = false;
  39. passString(option);
  40. document.getElementById("monitorName").innerHTML = option + "監測儀器";
  41. /*if (lastNode != null) {
  42. lastNode.style = "color:#abb4be;";
  43. }
  44. document.getElementById("errorCheck").checked = false;
  45. document.getElementById("compareCheck").checked = false;
  46. lastNode = document.getElementById(option).parentNode;
  47. lastNode.style = "color:#0088cc;";*/
  48. LoadPage();
  49. }
  50. });
  51. })
  52. //Pass monitor equipment's name to index.php select form
  53. function passString(option) {
  54. window.localStorage.setItem("option", option);
  55. }
  56. //unity給一個wellname(string)
  57. function GetWellName(wellName) {
  58. showWell(wellName, true);
  59. }
  60. function submitForm() {
  61. document.getElementById("CSVform").submit();
  62. }
  63. function GetWellNameList(wellNameList) {
  64. window.localStorage.setItem("wellNameList", wellNameList);
  65. }
  66. //display well name and send its name to showWell function
  67. function displayWellInfo2(equipment) {
  68. $.ajaxSettings.async = false;
  69. $.ajax({
  70. url: '/BIM-Monitor/script/php/getEquipmentName.php',
  71. type: "GET",
  72. data: {
  73. equipment: equipment,
  74. }
  75. }).success(function (data) {
  76. GetWellNameList(data);
  77. }).error(function (error) {
  78. console.log("錯誤");
  79. });
  80. $.ajaxSettings.async = true;
  81. }
  82. var sparklinePieData = [];
  83. function LoadPage() {
  84. if(isLoad){
  85. //myGameInstance.SendMessage("Monitor", "ChangeSiteModel", "R03");
  86. }
  87. var option = window.localStorage.getItem("option");
  88. displayWellInfo2(option);
  89. $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
  90. document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
  91. if (option == "ELP" || option == "OW")
  92. document.getElementById("displayCompareChart").style.display = 'block';
  93. else
  94. document.getElementById("displayCompareChart").style.display = 'none';
  95. if (option != "ELP" && option != "SIS" && option != "SID") {
  96. document.getElementById("phase").style.display = "none";
  97. } else {
  98. document.getElementById("phase").style.display = "block";
  99. }
  100. var wellTBALocal = getCheckValue();
  101. var dataValue = option;
  102. for (i = 0; i < wellTBALocal.length; i++) {
  103. dataValue = dataValue.concat(',', wellTBALocal[i]);
  104. }
  105. if (isLoad) {
  106. myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
  107. myGameInstance.SendMessage("Monitor", "Initialization");
  108. }
  109. var wellNameList = window.localStorage.getItem("wellNameList");
  110. var wellNameListsLocal = wellNameList.split(",");
  111. var order = new Array(wellNameListsLocal.length);
  112. for (i = 0; i < wellNameListsLocal.length; i++) {
  113. order[i] = wellNameListsLocal[i].match(/\d+/g);
  114. }
  115. for (i = 0; i < order.length; i++) {
  116. for (j = 0; j < order.length; j++) {
  117. if (order[j] > order[j + 1]) {
  118. let temp = order[j];
  119. order[j] = order[j + 1];
  120. order[j + 1] = temp;
  121. let temp2 = wellNameListsLocal[j];
  122. wellNameListsLocal[j] = wellNameListsLocal[j + 1];
  123. wellNameListsLocal[j + 1] = temp2;
  124. }
  125. }
  126. }
  127. wellNameLists = wellNameListsLocal;
  128. wellTBA = wellTBALocal;
  129. SetList();
  130. ResetCamera();
  131. showWell(wellNameLists[0], false);
  132. }
  133. //get well info from sql server
  134. function showWell(str, changeCamera) {
  135. var strLocal = "";
  136. var executed = false;
  137. var xhttp;
  138. isCompare = false;
  139. $("#compareCheck").checked = false;
  140. strLocal = str;
  141. $("#monitorSelect2").innerHTML = strLocal;
  142. getTable(str);
  143. displayChart(str, "myChart");
  144. if (isLoad) {
  145. myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
  146. }
  147. if (!changeCamera) {
  148. ResetCamera();
  149. }
  150. }
  151. var sparklinePieData = [];
  152. function getTable(monitor) {
  153. $.ajax({
  154. url: '/BIM-Monitor/script/php/get_monitor_table.php',
  155. type: "GET",
  156. dataType: "JSON",
  157. data: {
  158. monitor: monitor
  159. }
  160. }).success(function (result) {
  161. let table = result.table;
  162. let unit = result.unit;
  163. let haveDepth = result.haveDepth;
  164. let haveDirection = result.haveDirection;
  165. var header = "";
  166. if (haveDepth) {
  167. for (i = 0; i < table[0].length - 1; i++) {
  168. head = i * 0.5;
  169. if (head == 0)
  170. head = "TOP";
  171. header += `<th>${head}</th>`;
  172. }
  173. } else if(haveDirection){
  174. header = `<th>${monitor}(1~3向)</th><th>${monitor}(2~4向)</th>`;
  175. }else {
  176. header = `<th id="unit">測量值 單位:</th>`;
  177. }
  178. $("#tabData").empty();
  179. $("#tabData").append(`<table id="dataTable" class="display">
  180. <thead>
  181. <tr id="dataTableCol">
  182. <th>測量日期</th>
  183. ${header}
  184. </tr>
  185. </thead>
  186. <tbody id="table">
  187. </tbody>
  188. </table>`);
  189. dataTable = $('#dataTable').DataTable({
  190. bProcessing: true,
  191. responsive: true,
  192. "searching": true,
  193. "pageLength": 10,
  194. "language": {
  195. "processing": "處理中...",
  196. "loadingRecords": "載入中...",
  197. "lengthMenu": "顯示 _MENU_ 項結果",
  198. "zeroRecords": "沒有符合的結果或是沒有資料",
  199. "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
  200. "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
  201. "infoFiltered": "(從 _MAX_ 項結果中過濾)",
  202. "infoPostFix": "",
  203. "search": "",
  204. "paginate": {
  205. "first": '<i class="fa fa-step-backward"></i>',
  206. "previous": '<i class="fa fa-backward"></i>',
  207. "next": '<i class="fa fa-forward"></i>',
  208. "last": '<i class="fa fa-step-forward"></i>'
  209. },
  210. "aria": {
  211. "sortAscending": ": 升冪排列",
  212. "sortDescending": ": 降冪排列"
  213. }
  214. },
  215. });
  216. if (dataTable != null) {
  217. dataTable.clear();
  218. dataTable.draw();
  219. }
  220. if (monitor == '') {
  221. monitor = '查無監測儀器或';
  222. }
  223. $("#tableName").text(monitor + "資料表");
  224. $("#unit").text(`測量值(${unit})`);
  225. table.forEach(function (data) {
  226. dataTable.row.add(data)
  227. dataTable.draw();
  228. });
  229. /*$("#tableName").innerHTML = monitor + "資料表";
  230. saveCheckCompare = monitor + "資料表";
  231. displayChart(monitor, "myChart");
  232. reset();
  233. document.getElementById("dataTable").innerHTML = data;*/
  234. console.log(result);
  235. }).error(function (error) {
  236. console.log(error);
  237. }).complete(function (e) {
  238. });
  239. }
  240. function getCheckValue() {
  241. var dataArray = [];
  242. var phase
  243. if (document.getElementById("phase") !== null) {
  244. phase = document.getElementById("phase").value;
  245. } else {
  246. phase = 7;
  247. }
  248. var option = window.localStorage.getItem("option");
  249. for (i = 0; i < errorTable.length; i++) {
  250. if (errorTable[i].table_name == option) {
  251. var method = errorTable[i].method;
  252. var table_name = errorTable[i].table_name + "data";
  253. var warning1 = errorTable[i].warning1;
  254. var warning2 = errorTable[i].warning2;
  255. var warning_Count = errorTable[i].warning_Count;
  256. }
  257. }
  258. $.ajax({
  259. url: "/BIM-Monitor/script/php/checkValue2.php",
  260. data: {
  261. method: method,
  262. table_name: table_name,
  263. warning1: warning1,
  264. warning2: warning2,
  265. warning_Count: warning_Count,
  266. phase: phase
  267. },
  268. async: false,
  269. contentType: "application/json",
  270. dataType: "json"
  271. })
  272. .success(function (response) {
  273. console.log(response)
  274. dataArray = response['wellTBA'];
  275. for (var i = 0; i < dataArray.length; i++) {
  276. dataArray[i] = dataArray[i].replace('_', '-');
  277. }
  278. var normal_count = response['normal_count'];
  279. var abnormal_count = response['abnormal_count'];
  280. sparklinePieData = [normal_count, abnormal_count];
  281. var all = normal_count + abnormal_count;
  282. var percent = abnormal_count / all;
  283. var url = "/BIM-Monitor/assets/javascripts/ui-elements/pie.charts.js";
  284. var script = document.createElement('script');
  285. script.setAttribute('type', 'text/javascript');
  286. script.setAttribute('src', url);
  287. document.getElementsByTagName('head')[0].appendChild(script);
  288. document.getElementById("percent").innerHTML = Math.round(percent * 100) + "%";
  289. })
  290. .error(function () {
  291. //alert("錯誤統計未正常獲取");
  292. })
  293. .complete(function () {});
  294. return dataArray;
  295. }
  296. function GetCheckAllAJAXValue() {
  297. errorArray = [];
  298. var phase
  299. if (document.getElementById("phase") !== null) {
  300. phase = document.getElementById("phase").value;
  301. } else {
  302. phase = 7;
  303. }
  304. for (i = 0; i < errorTable.length; i++) {
  305. var method = errorTable[i].method;
  306. var option = errorTable[i].table_name;
  307. var table_name = errorTable[i].table_name + "data";
  308. var warning1 = errorTable[i].warning1;
  309. var warning2 = errorTable[i].warning2;
  310. var warning_Count = errorTable[i].warning_Count;
  311. $.ajax({
  312. url: "/BIM-Monitor/script/php/checkValue2.php",
  313. data: {
  314. method: method,
  315. table_name: table_name,
  316. warning1: warning1,
  317. warning2: warning2,
  318. warning_Count: warning_Count,
  319. phase: phase
  320. },
  321. async: false,
  322. contentType: "application/json",
  323. dataType: "json"
  324. })
  325. .success(function (response) {
  326. var normal_count = response['normal_count'];
  327. var abnormal_count = response['abnormal_count'];
  328. var all_count = 0 + normal_count + abnormal_count;
  329. document.getElementById(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
  330. errorArray.push(abnormal_count);
  331. })
  332. .error(function () {
  333. alert("錯誤統計未正常獲取");
  334. })
  335. .complete(function () {});
  336. }
  337. }
  338. function CheckCompare() {
  339. var option = window.localStorage.getItem("option");
  340. var text = "";
  341. if (option == "ELP" || option == "OW") {
  342. if (option == "ELP") {
  343. text = "水壓計";
  344. } else if (option == "OW") {
  345. text = "水位觀測井";
  346. }
  347. var checkBox = document.getElementById("compareCheck");
  348. if (checkBox.checked == true) {
  349. document.getElementById("tableName").innerHTML = option + text + '總表';
  350. isCompare = true;
  351. } else {
  352. document.getElementById("tableName").innerHTML = saveCheckCompare;
  353. isCompare = false;
  354. }
  355. if (option == "ELP")
  356. displayChart("ELP-1", "myChart");
  357. else if (option == "OW")
  358. displayChart("OW-1", "myChart");
  359. }
  360. }
  361. function CheckError() {
  362. var checkBox = document.getElementById("errorCheck");
  363. if (checkBox.checked == true) {
  364. isAll = false;
  365. } else {
  366. isAll = true;
  367. }
  368. SetList();
  369. }
  370. function uploadCSV() {
  371. var input = $("#fileToUpload");
  372. var inputLength = input[0].files.length; //No of files selected
  373. var file;
  374. var formData = new FormData();
  375. for (var i = 0; i < inputLength; i++) {
  376. file = input[0].files[i];
  377. formData.append('fileToUpload[]', file);
  378. }
  379. $.ajax({
  380. url: "/BIM-Monitor/script/php/upload.php",
  381. type: "POST",
  382. data: formData,
  383. processData: false,
  384. contentType: false,
  385. beforeSend: function () {
  386. }
  387. }).done(function (data) {
  388. var stack_bar_top = {
  389. "dir1": "down",
  390. "dir2": "right",
  391. "push": "top",
  392. "spacing1": 0,
  393. "spacing2": 0
  394. };
  395. if (data.includes("IS")) {
  396. var notice = new PNotify({
  397. title: '通知',
  398. text: '上傳成功!',
  399. type: 'success',
  400. addclass: 'stack-bar-top',
  401. stack: stack_bar_top,
  402. width: "100%"
  403. });
  404. } else {
  405. var notice = new PNotify({
  406. title: '通知',
  407. text: '上傳失敗!',
  408. type: 'error',
  409. addclass: 'stack-bar-top',
  410. stack: stack_bar_top,
  411. width: "100%"
  412. });
  413. }
  414. }).error(function () {
  415. });
  416. }
  417. //Display chart
  418. function displayChart(str, elementID) {
  419. var xhttp;
  420. xhttp = new XMLHttpRequest();
  421. xhttp.onreadystatechange = function () {
  422. if (this.readyState == 4 && this.status == 200) {
  423. if (str.includes("ELP") || str.includes("OW") || str.includes("SM") || str.includes("SB") || str.includes("SBM") || str.includes("VG") || str.includes("HM")) {
  424. //Split the response text into well name array, date array and value array
  425. var v_variables = this.responseText.split("*");
  426. var c_wellName = v_variables[0];
  427. var c_m_date = v_variables[1].split(" ");
  428. var c_m_value = v_variables[2].split(" ");
  429. //Start to make the chart
  430. if (isCompare) {
  431. displayCompareChart();
  432. } else {
  433. init(c_wellName, c_m_date, c_m_value, elementID);
  434. }
  435. } else if (str.includes("TI")) {
  436. var v_variables = this.responseText.split("*");
  437. var c_wellName = v_variables[0];
  438. var c_m_date = v_variables[1].split(" ");
  439. var c_m_value = v_variables[2].split(" ");
  440. //Multiple line
  441. var c2_wellName = v_variables[3];
  442. var c2_m_date = v_variables[4].split(" ");
  443. var c2_m_value = v_variables[5].split(" ");
  444. if (isCompare) {
  445. displayCompareChart();
  446. } else {
  447. init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID);
  448. }
  449. } else if (str.includes("SIS") || str.includes("SID")) {
  450. var v_variables = this.responseText.split("*");
  451. var c_m_date = v_variables[0].split(" ");
  452. var c_m_depth = v_variables[1].split(" ");
  453. var c_m_valueArray = v_variables[2].split("//");
  454. //Abnormal value, don't know why it happened so I brute force it
  455. c_m_valueArray[0] = c_m_valueArray[0].replace("0.4770.468", "0.477 0.468");
  456. var dateCount = c_m_date.length;
  457. let c_m_value = [];
  458. for (x = 0; x < dateCount; x++) {
  459. c_m_value[x] = c_m_valueArray[x].split(" ");
  460. }
  461. initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str);
  462. } else if (str.includes("RS")) {
  463. var v_variables = this.responseText.split("*");
  464. var c_wellName = v_variables[0];
  465. var c_m_date = v_variables[1].split(" ");
  466. var c_m_value = v_variables[2].split(" ");
  467. var c2_wellName = v_variables[3];
  468. var c2_m_date = v_variables[4].split(" ");
  469. var c2_m_value = v_variables[5].split(" ");
  470. var c3_wellName = v_variables[6];
  471. var c3_m_date = v_variables[7].split(" ");
  472. var c3_m_value = v_variables[8].split(" ");
  473. var c4_wellName = v_variables[9];
  474. var c4_m_date = v_variables[10].split(" ");
  475. var c4_m_value = v_variables[11].split(" ");
  476. var c5_wellName = v_variables[12];
  477. var c5_m_date = v_variables[13].split(" ");
  478. var c5_m_value = v_variables[14].split(" ");
  479. var c6_wellName = v_variables[15];
  480. var c6_m_date = v_variables[16].split(" ");
  481. var c6_m_value = v_variables[17].split(" ");
  482. init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_wellName, c3_m_value, c4_wellName, c4_m_value, c5_wellName, c5_m_value, c6_wellName, c6_m_value, elementID);
  483. }
  484. }
  485. };
  486. xhttp.open("GET", "/BIM-Monitor/script/php/getChartData2.php?q=" + str, true);
  487. xhttp.send();
  488. }
  489. function displayCompareChart() {
  490. var option = window.localStorage.getItem("option");
  491. var m_date = [];
  492. var label = [];
  493. var index = 7;
  494. if (option == "ELP")
  495. index = 14;
  496. var chart_data = new Array();
  497. for (var i = 0; i < index; i++) {
  498. chart_data[i] = new Array();
  499. for (var j = 0; j < m_date.length; j++) {
  500. chart_data[i][j] = 0;
  501. }
  502. }
  503. $.ajax({
  504. url: "/BIM-Monitor/script/php/getCompareChartData.php",
  505. async: false,
  506. contentType: "application/json",
  507. dataType: "json",
  508. data: {
  509. option: option
  510. }
  511. })
  512. .success(function (response) {
  513. m_date = response['m_date'];
  514. chart_data = response['chart_data'];
  515. label = response['label'];
  516. initCompare(m_date, chart_data, index, label);
  517. console.log("getCompareChartData正常獲取");
  518. })
  519. .error(function () {
  520. console.log("getCompareChartData未正常獲取");
  521. })
  522. .complete(function () {});
  523. }
  524. //Reset the camera
  525. function ResetCamera() {
  526. if (isLoad) {
  527. myGameInstance.SendMessage("MainCamera", "ResetCamera");
  528. }
  529. }
  530. function SetList() {
  531. var wellNameListsLocal = "";
  532. var isError = false;
  533. var monitorSelect = document.getElementById("monitorSelect");
  534. var monitorButton = document.getElementById("monitorButton");
  535. while (monitorSelect.hasChildNodes()) {
  536. monitorSelect.removeChild(monitorSelect.firstChild);
  537. }
  538. while (monitorButton.hasChildNodes()) {
  539. monitorButton.removeChild(monitorButton.firstChild);
  540. }
  541. monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
  542. GetCheckAllAJAXValue();
  543. for (i = 0; i < wellNameLists.length; i++) {
  544. wellNameListsLocal = wellNameLists[i];
  545. var option = document.createElement("li");
  546. var createA = document.createElement("a");
  547. /*if(wellNameLists[i].includes("ELP")){
  548. if(wellNameLists[i].includes("A")){
  549. wellNameListsLocal = wellNameLists[i] + ',' + wellNameLists[i].replace('A','-1A');
  550. }else{
  551. wellNameListsLocal = wellNameLists[i] + ',' + wellNameLists[i] + '-1';
  552. }
  553. } */
  554. var createAText = document.createTextNode(wellNameListsLocal);
  555. var createButton = document.createElement("button");
  556. var createButtonText = document.createTextNode(wellNameListsLocal);
  557. createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
  558. for (j = 0; j < wellTBA.length; j++) {
  559. if (wellNameLists[i] == (wellTBA[j])) {
  560. createA.style = "color:red;";
  561. createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
  562. isError = true;
  563. }
  564. }
  565. createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  566. createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  567. createButton.setAttribute('type', "button");
  568. if (isAll || (!isAll && isError)) {
  569. createA.appendChild(createAText);
  570. createButton.appendChild(createButtonText);
  571. option.appendChild(createA);
  572. monitorSelect.appendChild(option);
  573. monitorButton.appendChild(createButton);
  574. }
  575. isError = false;
  576. }
  577. }
  578. function UpdateGPS(GPS) {
  579. if (isLoad) {
  580. myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
  581. }
  582. }
  583. function forLoopSMOption() {
  584. var elm = document.getElementById('SM'), // get the select
  585. df = document.createDocumentFragment(); // create a document fragment to hold the options while we create them
  586. for (var i = 1; i <= 81; i++) { // loop, i like 42.
  587. var option = document.createElement('option'); // create the option element
  588. option.value = "SM-" + i; // set the value property
  589. option.appendChild(document.createTextNode("SM-" + i)); // set the textContent in a safe way.
  590. df.appendChild(option); // append the option to the document fragment
  591. }
  592. elm.appendChild(df); // append the document fragment to the DOM. this is the better way rather than setting innerHTML a bunch of times (or even once with a long string)
  593. }
  594. function forLoopHMOption() {
  595. var elm = document.getElementById('HM'),
  596. df = document.createDocumentFragment();
  597. for (var i = 1; i <= 15; i++) {
  598. var option = document.createElement('option');
  599. option.value = "HM-1-" + i;
  600. option.appendChild(document.createTextNode("HM1-" + i));
  601. df.appendChild(option);
  602. }
  603. for (var j = 1; j <= 7; j++) {
  604. var option = document.createElement('option');
  605. option.value = "HM-2-" + j;
  606. option.appendChild(document.createTextNode("HM2-" + j));
  607. df.appendChild(option);
  608. }
  609. for (var k = 1; k <= 11; k++) {
  610. var option = document.createElement('option');
  611. option.value = "HM-3-" + k;
  612. option.appendChild(document.createTextNode("HM3-" + k));
  613. df.appendChild(option);
  614. }
  615. for (var l = 1; l <= 7; l++) {
  616. var option = document.createElement('option');
  617. option.value = "HM-4-" + l;
  618. option.appendChild(document.createTextNode("HM4-" + l));
  619. df.appendChild(option);
  620. }
  621. elm.appendChild(df);
  622. }
  623. var errorChart = null;
  624. //Start making the chart
  625. function init(c_wellName, c_m_date, c_m_value, elementID) {
  626. var ctx = document.getElementById(elementID).getContext("2d");
  627. var phase = document.getElementById("phase").value;
  628. var ELPwarning = [0, -4.6, -10, -15.3, -23.2, 0];
  629. var ELP_1warning = [0, -7.9, -13.3, 0, 0, 0];
  630. //Warning value
  631. let warning = [];
  632. var OWFirstData = {
  633. "OW-1": -1.81,
  634. "OW-2": -1.59,
  635. "OW-3": -6.3,
  636. "OW-4": -3.67,
  637. "OW-5": -3.16,
  638. "OW-6": -1.78,
  639. "OW-7": -3.31
  640. };
  641. var OWwarning1 = 0;
  642. var OWwarning2 = 0;
  643. var yLabel = "";
  644. var xLabel = "";
  645. if (c_wellName.includes("ELP")) {
  646. if (c_wellName != "ELP-1" && c_wellName.includes("-1")) {
  647. if (ELP_1warning[phase - 2] != 0) {
  648. for (i = 0; i < c_m_date.length; i++) {
  649. warning.push(ELP_1warning[phase - 2]);
  650. }
  651. }
  652. } else {
  653. if (ELPwarning[phase - 2] != 0) {
  654. for (i = 0; i < c_m_date.length; i++) {
  655. warning.push(ELPwarning[phase - 2]);
  656. }
  657. }
  658. }
  659. yLabel = "水位高程GL(m)";
  660. xLabel = "日期";
  661. } else if (c_wellName.includes("OW")) {
  662. for (const [key, value] of Object.entries(OWFirstData)) {
  663. if (c_wellName == key) {
  664. OWwarning1 = value + 2;
  665. OWwarning2 = value - 2;
  666. }
  667. }
  668. for (i = 0; i < c_m_date.length; i++) {
  669. warning.push(OWwarning1);
  670. }
  671. yLabel = "水位高程GL(m)";
  672. xLabel = "日期";
  673. } else if (c_wellName.includes("SM")) {
  674. for (i = 0; i < c_m_date.length; i++) {
  675. warning.push(45);
  676. }
  677. yLabel = "沉陷量(mm)";
  678. xLabel = "日期";
  679. } else if (c_wellName.includes("SBM")) {
  680. for (i = 0; i < c_m_date.length; i++) {
  681. warning.push(9.5);
  682. }
  683. yLabel = "沉陷量(mm)";
  684. xLabel = "日期";
  685. } else if (c_wellName.includes("SB")) {
  686. for (i = 0; i < c_m_date.length; i++) {
  687. warning.push(0.0008);
  688. }
  689. yLabel = "沉陷量(mm)";
  690. xLabel = "日期";
  691. } else if (c_wellName.includes("VG")) {
  692. for (i = 0; i < c_m_date.length; i++) {
  693. warning.push(110);
  694. }
  695. yLabel = "應力值(t)";
  696. xLabel = "日期";
  697. } else if (c_wellName.includes("HM")) {
  698. for (i = 0; i < c_m_date.length; i++) {
  699. warning.push(25);
  700. }
  701. yLabel = "沉陷量(mm)";
  702. xLabel = "日期";
  703. }
  704. for (j = 0; j < c_m_value.length; j++) {
  705. if (c_m_value[j] == "") {
  706. c_m_value[j] = null;
  707. }
  708. }
  709. //Destroy chart if it already exists. If not, there'll be multiple charts stack together
  710. if (window.chart != undefined) {
  711. window.chart.destroy();
  712. }
  713. window.chart = new Chart(ctx, {
  714. //Line chart
  715. type: 'line',
  716. data: {
  717. //X-axis displays the date
  718. labels: c_m_date,
  719. datasets: [{
  720. //Label above the chart to illustrate which color has which purpose
  721. label: c_wellName,
  722. //Data value
  723. data: c_m_value,
  724. //Detemine line's color
  725. borderColor: '#3e95cd'
  726. },
  727. {
  728. label: "警戒值",
  729. data: warning,
  730. borderColor: "#FF0000",
  731. pointRadius: 0
  732. }
  733. ]
  734. },
  735. options: {
  736. spanGaps: true,
  737. maintainAspectRatio: false,
  738. responsive: true,
  739. scales: {
  740. y: {
  741. title: {
  742. display: true,
  743. text: yLabel
  744. }
  745. },
  746. x: {
  747. title: {
  748. display: true,
  749. text: xLabel
  750. }
  751. }
  752. }
  753. }
  754. });
  755. if (c_wellName.includes("SBM")) {
  756. let warning2 = [];
  757. for (i = 0; i < c_m_date.length; i++) {
  758. warning2.push(-9.5);
  759. }
  760. window.chart.data.datasets.push({
  761. label: "警戒值2",
  762. data: warning2,
  763. borderColor: "#FF0000",
  764. pointRadius: 0
  765. });
  766. window.chart.update();
  767. } else if (c_wellName.includes("SB")) {
  768. let warning2 = [];
  769. for (i = 0; i < c_m_date.length; i++) {
  770. warning2.push(-0.0008);
  771. }
  772. window.chart.data.datasets.push({
  773. label: "警戒值2",
  774. data: warning2,
  775. borderColor: "#FF0000",
  776. pointRadius: 0
  777. });
  778. window.chart.update();
  779. } else if (c_wellName.includes("OW")) {
  780. let warning2 = [];
  781. for (i = 0; i < c_m_date.length; i++) {
  782. warning2.push(OWwarning2);
  783. }
  784. window.chart.data.datasets.push({
  785. label: "警戒值2",
  786. data: warning2,
  787. borderColor: "#FF0000",
  788. pointRadius: 0
  789. });
  790. window.chart.update();
  791. }
  792. }
  793. function init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID) {
  794. var ctx = document.getElementById(elementID).getContext("2d");
  795. var yLabel = "";
  796. var xLabel = "";
  797. let warning = [];
  798. if (c_wellName.includes("TI")) {
  799. for (i = 0; i < c2_m_date.length; i++) {
  800. warning.push(0.00106);
  801. }
  802. yLabel = "徑度量(δ/ L)";
  803. xLabel = "日期";
  804. }
  805. for (j = 0; j < c_m_value.length; j++) {
  806. if (c_m_value[j] == "") {
  807. c_m_value[j] = null;
  808. }
  809. }
  810. if (window.chart != undefined) {
  811. window.chart.destroy();
  812. }
  813. c_m_value.forEach(function (item, index, array) {
  814. });
  815. window.chart = new Chart(ctx, {
  816. type: 'line',
  817. data: {
  818. labels: c_m_date,
  819. datasets: [{
  820. label: c_wellName,
  821. data: c_m_value,
  822. borderColor: '#3e95cd'
  823. },
  824. {
  825. label: c2_wellName,
  826. data: c2_m_value,
  827. borderColor: '#63fff5'
  828. }
  829. ]
  830. },
  831. options: {
  832. responsive: true,
  833. maintainAspectRatio: false,
  834. scales: {
  835. y: {
  836. title: {
  837. display: true,
  838. text: yLabel
  839. }
  840. },
  841. x: {
  842. title: {
  843. display: true,
  844. text: xLabel
  845. }
  846. }
  847. }
  848. }
  849. });
  850. /*if(c_wellName.includes("ELP") && phase != 2 && phase != 7){
  851. window.chart.data.datasets.push({
  852. label: "警戒值",
  853. data: warning,
  854. borderColor: "#FF0000",
  855. pointRadius: 0
  856. });
  857. if(phase == 3 || phase == 4){
  858. let warning2 = [];
  859. for (i = 0; i < c2_m_date.length; i++) {
  860. warning2.push(ELP_1warning[phase-2]);
  861. }
  862. window.chart.data.datasets.push({
  863. label: "警戒值2",
  864. data: warning2,
  865. borderColor: "#FF0000",
  866. pointRadius: 0
  867. });
  868. }
  869. window.chart.update();
  870. }*/
  871. //ELP does not have second warning line, so you need to update it seperately
  872. if (c_wellName.includes("TI")) {
  873. let warning2 = [];
  874. for (i = 0; i < c2_m_date.length; i++) {
  875. warning2.push(-0.00106);
  876. }
  877. window.chart.data.datasets.push({
  878. label: "警戒值2",
  879. data: warning2,
  880. borderColor: "#FF0000",
  881. pointRadius: 0
  882. });
  883. window.chart.update();
  884. }
  885. }
  886. //SIS SID's lines are vertical
  887. function initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str) {
  888. var ctx = document.getElementById(elementID).getContext("2d");
  889. var datasetValue = [];
  890. let warning = [];
  891. var phase = document.getElementById("phase").value;
  892. var SID_data = [];
  893. var SIS_data = [];
  894. var SIS_array = ['SIS-1', 'SIS-2-1', 'SIS-2-2', 'SIS-3', 'SIS-4', 'SIS-6', 'SIS-7'];
  895. var SID_array = ['SID-1', 'SID-2-1', 'SID-2-2', 'SID-3-1', 'SID-3-2', 'SID-4', 'SID-5-1', 'SID-5-2', 'SID-6', 'SID-7'];
  896. var index = 0;
  897. var num = 0;
  898. if (phase == 2) {
  899. SID_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.698, 1.698, 1.186, 1.186, 1.032];
  900. SIS_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.186, 1.032];
  901. } else if (phase == 3) {
  902. SID_data = [2.39, 1.434, 1.434, 1.434, 2.304, 2.304, 2.304, 1.7, 1.7, 1.569];
  903. SIS_data = [2.39, 1.434, 1.434, 1.434, 2.304, 1.7, 1.569];
  904. } else if (phase == 4) {
  905. SID_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.968, 2.968, 2.267, 2.267, 2.176];
  906. SIS_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.267, 2.176];
  907. } else if (phase == 5) {
  908. SID_data = [3.36, 2.626, 2.626, 2.626, 4.531, 4.531, 4.531, 3.727, 3.727, 3.285];
  909. SIS_data = [3.36, 2.626, 2.626, 2.626, 4.531, 3.727, 3.285];
  910. } else if (phase == 6) {
  911. SID_data = [4.015, 3.832, 3.832, 3.832, 7.966, 7.966, 7.966, 5.049, 5.049, 5.208];
  912. SIS_data = [4.015, 3.832, 3.832, 3.832, 7.966, 5.049, 5.208];
  913. } else if (phase == 7) {
  914. SID_data = [4.918, 4.458, 4.458, 4.458, 8.909, 8.909, 8.909, 5.797, 5.797, 5.988];
  915. SIS_data = [4.918, 4.458, 4.458, 4.458, 8.909, 5.797, 5.988];
  916. }
  917. if (str.includes("SIS")) {
  918. index = SIS_array.indexOf(str);
  919. num = SIS_data[index];
  920. } else if (str.includes("SID")) {
  921. index = SID_array.indexOf(str);
  922. num = SID_data[index];
  923. }
  924. for (i = 0; i < c_m_value[0].length; i++) {
  925. warning.push(num);
  926. }
  927. yLabel = "觀測深度GL(m)";
  928. xLabel = "變位量(cm)";
  929. for (j = 0; j < c_m_value.length; j++) {
  930. if (c_m_value[j] == "") {
  931. c_m_value[j] = null;
  932. }
  933. }
  934. if (window.chart != undefined) {
  935. window.chart.destroy();
  936. }
  937. for (j = 0; j <= c_m_date.length; j++) {
  938. if (j == c_m_date.length) {
  939. datasetValue[j] = {
  940. axis: 'y',
  941. fill: false,
  942. label: "警戒值",
  943. data: warning,
  944. borderColor: "#FF0000",
  945. pointRadius: 0
  946. }
  947. } else {
  948. datasetValue[j] = {
  949. axis: 'y',
  950. label: c_m_date[j],
  951. data: c_m_value[j],
  952. borderColor: randomColor()
  953. }
  954. }
  955. }
  956. window.chart = new Chart(ctx, {
  957. type: 'line',
  958. data: {
  959. labels: c_m_depth,
  960. datasets: datasetValue
  961. },
  962. options: {
  963. //Turns line to vertical
  964. maintainAspectRatio: false,
  965. responsive: true,
  966. indexAxis: 'y',
  967. scales: {
  968. y: {
  969. title: {
  970. display: true,
  971. text: yLabel
  972. }
  973. },
  974. x: {
  975. beginAtZero: true,
  976. title: {
  977. display: true,
  978. text: xLabel
  979. }
  980. }
  981. }
  982. }
  983. });
  984. }
  985. function init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_wellName, c3_m_value, c4_wellName, c4_m_value, c5_wellName, c5_m_value, c6_wellName, c6_m_value, elementID) {
  986. var ctx = document.getElementById(elementID).getContext("2d");
  987. let warning = [];
  988. if (c_wellName.includes("RS")) {
  989. for (i = 0; i < c_m_date.length; i++) {
  990. warning.push(2000);
  991. }
  992. yLabel = "應力值(kg/cm²)";
  993. xLabel = "日期";
  994. }
  995. if (window.chart != undefined) {
  996. window.chart.destroy();
  997. }
  998. window.chart = new Chart(ctx, {
  999. type: 'line',
  1000. data: {
  1001. labels: c_m_date,
  1002. datasets: [{
  1003. label: c_wellName,
  1004. data: c_m_value,
  1005. borderColor: randomColor()
  1006. },
  1007. {
  1008. label: c2_wellName,
  1009. data: c2_m_value,
  1010. borderColor: randomColor()
  1011. },
  1012. {
  1013. label: c3_wellName,
  1014. data: c3_m_value,
  1015. borderColor: randomColor()
  1016. },
  1017. {
  1018. label: c4_wellName,
  1019. data: c4_m_value,
  1020. borderColor: randomColor()
  1021. },
  1022. {
  1023. label: c5_wellName,
  1024. data: c5_m_value,
  1025. borderColor: randomColor()
  1026. },
  1027. {
  1028. label: c6_wellName,
  1029. data: c6_m_value,
  1030. borderColor: randomColor()
  1031. },
  1032. {
  1033. label: "警戒值",
  1034. data: warning,
  1035. borderColor: "#FF0000",
  1036. pointRadius: 0
  1037. }
  1038. ]
  1039. },
  1040. options: {
  1041. responsive: true,
  1042. maintainAspectRatio: false,
  1043. scales: {
  1044. y: {
  1045. title: {
  1046. display: true,
  1047. text: yLabel
  1048. }
  1049. },
  1050. x: {
  1051. title: {
  1052. display: true,
  1053. text: xLabel
  1054. }
  1055. }
  1056. }
  1057. }
  1058. });
  1059. //ELP does not have second warning line, so you need to update it seperately
  1060. if (c_wellName.includes("RS")) {
  1061. let warning2 = [];
  1062. for (i = 0; i < c_m_date.length; i++) {
  1063. warning2.push(-2000);
  1064. }
  1065. window.chart.data.datasets.push({
  1066. label: "警戒值2",
  1067. data: warning2,
  1068. borderColor: "#FF0000",
  1069. pointRadius: 0
  1070. });
  1071. window.chart.update();
  1072. }
  1073. }
  1074. function initCompare(m_date, chart_data, index, label) {
  1075. var ctx = document.getElementById("myChart").getContext("2d");
  1076. var value = -7.9;
  1077. let warning = [];
  1078. var phase = document.getElementById("phase").value;
  1079. yLabel = "水位高程GL(m)";
  1080. xLabel = "日期";
  1081. for (i = 0; i < m_date.length; i++) {
  1082. warning.push(value);
  1083. }
  1084. if (window.chart != undefined) {
  1085. window.chart.destroy();
  1086. }
  1087. window.chart = new Chart(ctx, {
  1088. type: 'line',
  1089. data: {
  1090. labels: m_date
  1091. },
  1092. options: {
  1093. responsive: true,
  1094. maintainAspectRatio: false,
  1095. scales: {
  1096. y: {
  1097. title: {
  1098. display: true,
  1099. text: yLabel
  1100. }
  1101. },
  1102. x: {
  1103. title: {
  1104. display: true,
  1105. text: xLabel
  1106. }
  1107. }
  1108. }
  1109. }
  1110. });
  1111. for (i = 1; i < index + 1; i++) {
  1112. window.chart.data.datasets.push({
  1113. label: label[i].replaceAll("_", "-"),
  1114. data: chart_data[i],
  1115. borderColor: randomColorBlue()
  1116. });
  1117. }
  1118. /*
  1119. if(label[1].includes("ELP") && phase != 2 && phase != 7){
  1120. window.chart.data.datasets.push({
  1121. label: "警戒值",
  1122. data: warning,
  1123. borderColor: "#FF0000",
  1124. pointRadius: 0
  1125. });
  1126. }
  1127. */
  1128. window.chart.update();
  1129. }
  1130. //Chart has multiple lines that need different color
  1131. function randomColor() {
  1132. return "#" + ((1 << 24) * Math.random() | 0).toString(16);
  1133. }
  1134. function randomColorBlue() {
  1135. var mid = Math.floor(Math.random() * 255);
  1136. return "#30" + mid.toString(16) + "ff";
  1137. }
  1138. //Need to display multiple epuiment's data table and can't find the function to reset it. So I kill all the nodes.
  1139. function reset() {
  1140. const myNode = document.getElementById("tabData");
  1141. while (myNode.firstChild) {
  1142. myNode.removeChild(myNode.lastChild);
  1143. }
  1144. var table = document.createElement("table");
  1145. table.id = "dataTable";
  1146. table.className = "display";
  1147. //table.style.width = "100%";
  1148. myNode.appendChild(table);
  1149. }