r03.js 39 KB

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