main.js 37 KB

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