map.js 38 KB

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