r03.js 39 KB

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