r03.js 40 KB

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