main.js 38 KB

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