r03.js 39 KB

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