main.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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. $(".monitor").on('click', function(){
  376. let option = $(this).attr("monitor");
  377. isAll = true;
  378. isCompare = false;
  379. passString(option);
  380. document.getElementById("monitorName").innerHTML = option + "監測儀器";
  381. if (lastNode != null) {
  382. lastNode.style = "color:#abb4be;";
  383. }
  384. document.getElementById("errorCheck").checked = false;
  385. document.getElementById("compareCheck").checked = false;
  386. lastNode = document.getElementById(option).parentNode;
  387. lastNode.style = "color:#0088cc;";
  388. LoadPage();
  389. });
  390. function SetList() {
  391. var wellNameListsLocal = "";
  392. var isError = false;
  393. var monitorSelect = document.getElementById("monitorSelect");
  394. var monitorButton = document.getElementById("monitorButton");
  395. while (monitorSelect.hasChildNodes()) {
  396. monitorSelect.removeChild(monitorSelect.firstChild);
  397. }
  398. while (monitorButton.hasChildNodes()) {
  399. monitorButton.removeChild(monitorButton.firstChild);
  400. }
  401. monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
  402. GetCheckAllAJAXValue();
  403. for (i = 0; i < wellNameLists.length; i++) {
  404. wellNameListsLocal = wellNameLists[i];
  405. var option = document.createElement("li");
  406. var createA = document.createElement("a");
  407. /*if(wellNameLists[i].includes("ELP")){
  408. if(wellNameLists[i].includes("A")){
  409. wellNameListsLocal = wellNameLists[i] + ',' + wellNameLists[i].replace('A','-1A');
  410. }else{
  411. wellNameListsLocal = wellNameLists[i] + ',' + wellNameLists[i] + '-1';
  412. }
  413. } */
  414. var createAText = document.createTextNode(wellNameListsLocal);
  415. var createButton = document.createElement("button");
  416. var createButtonText = document.createTextNode(wellNameListsLocal);
  417. createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
  418. for (j = 0; j < wellTBA.length; j++) {
  419. if (wellNameLists[i] == (wellTBA[j])) {
  420. createA.style = "color:red;";
  421. createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
  422. isError = true;
  423. //console.log(" wellNameLists:" + wellNameLists[i]);
  424. //console.log(" wellTBA:" + wellTBA[j]);
  425. }
  426. }
  427. createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  428. createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  429. createButton.setAttribute('type', "button");
  430. if (isAll || (!isAll && isError)) {
  431. //console.log(isError);
  432. createA.appendChild(createAText);
  433. createButton.appendChild(createButtonText);
  434. option.appendChild(createA);
  435. monitorSelect.appendChild(option);
  436. monitorButton.appendChild(createButton);
  437. }
  438. isError = false;
  439. }
  440. }
  441. function UpdateGPS(GPS) {
  442. myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
  443. }
  444. function LoadPage() {
  445. var option = window.localStorage.getItem("option");
  446. //Display the selected equipment
  447. $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
  448. //console.log("Choosed option: " + window.localStorage.getItem("option"));
  449. document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
  450. if (option == "ELP" || option == "OW")
  451. document.getElementById("displayCompareChart").style.display = 'block';
  452. else
  453. document.getElementById("displayCompareChart").style.display = 'none';
  454. if (option == "HM" || option == "SIS" || option == "RS" || option == "VG" || option == "SID") {
  455. myGameInstance.SendMessage("Monitor", "ChangeTransparent");
  456. myGameInstance.SendMessage("Monitor", "RemoveModel", "true");
  457. } else {
  458. myGameInstance.SendMessage("Monitor", "ChangeWhite");
  459. myGameInstance.SendMessage("Monitor", "RemoveModel", "false");
  460. }
  461. if (option != "ELP" && option != "SIS" && option != "SID") {
  462. document.getElementById("phase").style.display = "none";
  463. } else {
  464. document.getElementById("phase").style.display = "block";
  465. }
  466. var wellTBALocal = getCheckValue();
  467. var dataValue = option;
  468. for (i = 0; i < wellTBALocal.length; i++) {
  469. dataValue = dataValue.concat(',', wellTBALocal[i]);
  470. }
  471. myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
  472. myGameInstance.SendMessage("Monitor", "Initialization");
  473. var wellNameList = window.localStorage.getItem("wellNameList");
  474. var wellNameListsLocal = wellNameList.split(",");
  475. var order = new Array(wellNameListsLocal.length);
  476. for (i = 0; i < wellNameListsLocal.length; i++) {
  477. order[i] = wellNameListsLocal[i].match(/\d+/g);
  478. }
  479. for (i = 0; i < order.length; i++) {
  480. for (j = 0; j < order.length; j++) {
  481. if (order[j] > order[j + 1]) {
  482. let temp = order[j];
  483. order[j] = order[j + 1];
  484. order[j + 1] = temp;
  485. let temp2 = wellNameListsLocal[j];
  486. wellNameListsLocal[j] = wellNameListsLocal[j + 1];
  487. wellNameListsLocal[j + 1] = temp2;
  488. }
  489. }
  490. }
  491. wellNameLists = wellNameListsLocal;
  492. wellTBA = wellTBALocal;
  493. SetList();
  494. ResetCamera();
  495. showWell(wellNameLists[0], false);
  496. }
  497. function forLoopSMOption() {
  498. var elm = document.getElementById('SM'), // get the select
  499. df = document.createDocumentFragment(); // create a document fragment to hold the options while we create them
  500. for (var i = 1; i <= 81; i++) { // loop, i like 42.
  501. var option = document.createElement('option'); // create the option element
  502. option.value = "SM-" + i; // set the value property
  503. option.appendChild(document.createTextNode("SM-" + i)); // set the textContent in a safe way.
  504. df.appendChild(option); // append the option to the document fragment
  505. }
  506. 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)
  507. }
  508. function forLoopHMOption() {
  509. var elm = document.getElementById('HM'),
  510. df = document.createDocumentFragment();
  511. for (var i = 1; i <= 15; i++) {
  512. var option = document.createElement('option');
  513. option.value = "HM-1-" + i;
  514. option.appendChild(document.createTextNode("HM1-" + i));
  515. df.appendChild(option);
  516. }
  517. for (var j = 1; j <= 7; j++) {
  518. var option = document.createElement('option');
  519. option.value = "HM-2-" + j;
  520. option.appendChild(document.createTextNode("HM2-" + j));
  521. df.appendChild(option);
  522. }
  523. for (var k = 1; k <= 11; k++) {
  524. var option = document.createElement('option');
  525. option.value = "HM-3-" + k;
  526. option.appendChild(document.createTextNode("HM3-" + k));
  527. df.appendChild(option);
  528. }
  529. for (var l = 1; l <= 7; l++) {
  530. var option = document.createElement('option');
  531. option.value = "HM-4-" + l;
  532. option.appendChild(document.createTextNode("HM4-" + l));
  533. df.appendChild(option);
  534. }
  535. elm.appendChild(df);
  536. }
  537. var errorChart = null;
  538. //Start making the chart
  539. function init(c_wellName, c_m_date, c_m_value, elementID) {
  540. var ctx = document.getElementById(elementID).getContext("2d");
  541. var phase = document.getElementById("phase").value;
  542. var ELPwarning = [0, -4.6, -10, -15.3, -23.2, 0];
  543. var ELP_1warning = [0, -7.9, -13.3, 0, 0, 0];
  544. //Warning value
  545. let warning = [];
  546. var OWFirstData = {
  547. "OW-1": -1.81,
  548. "OW-2": -1.59,
  549. "OW-3": -6.3,
  550. "OW-4": -3.67,
  551. "OW-5": -3.16,
  552. "OW-6": -1.78,
  553. "OW-7": -3.31
  554. };
  555. var OWwarning1 = 0;
  556. var OWwarning2 = 0;
  557. var yLabel = "";
  558. var xLabel = "";
  559. if (c_wellName.includes("ELP")) {
  560. if (c_wellName != "ELP-1" && c_wellName.includes("-1")) {
  561. if (ELP_1warning[phase - 2] != 0) {
  562. for (i = 0; i < c_m_date.length; i++) {
  563. warning.push(ELP_1warning[phase - 2]);
  564. }
  565. }
  566. } else {
  567. if (ELPwarning[phase - 2] != 0) {
  568. for (i = 0; i < c_m_date.length; i++) {
  569. warning.push(ELPwarning[phase - 2]);
  570. }
  571. }
  572. }
  573. yLabel = "水位高程GL(m)";
  574. xLabel = "日期";
  575. } else if (c_wellName.includes("OW")) {
  576. for (const [key, value] of Object.entries(OWFirstData)) {
  577. if (c_wellName == key) {
  578. OWwarning1 = value + 2;
  579. OWwarning2 = value - 2;
  580. }
  581. }
  582. for (i = 0; i < c_m_date.length; i++) {
  583. warning.push(OWwarning1);
  584. }
  585. yLabel = "水位高程GL(m)";
  586. xLabel = "日期";
  587. } else if (c_wellName.includes("SM")) {
  588. for (i = 0; i < c_m_date.length; i++) {
  589. warning.push(45);
  590. }
  591. yLabel = "沉陷量(mm)";
  592. xLabel = "日期";
  593. } else if (c_wellName.includes("SBM")) {
  594. for (i = 0; i < c_m_date.length; i++) {
  595. warning.push(9.5);
  596. }
  597. yLabel = "沉陷量(mm)";
  598. xLabel = "日期";
  599. } else if (c_wellName.includes("SB")) {
  600. for (i = 0; i < c_m_date.length; i++) {
  601. warning.push(0.0008);
  602. }
  603. yLabel = "沉陷量(mm)";
  604. xLabel = "日期";
  605. } else if (c_wellName.includes("VG")) {
  606. for (i = 0; i < c_m_date.length; i++) {
  607. warning.push(110);
  608. }
  609. yLabel = "應力值(t)";
  610. xLabel = "日期";
  611. } else if (c_wellName.includes("HM")) {
  612. for (i = 0; i < c_m_date.length; i++) {
  613. warning.push(25);
  614. }
  615. yLabel = "沉陷量(mm)";
  616. xLabel = "日期";
  617. }
  618. for (j = 0; j < c_m_value.length; j++) {
  619. if (c_m_value[j] == "") {
  620. c_m_value[j] = null;
  621. //console.log(c_m_value[j]);
  622. }
  623. }
  624. //Destroy chart if it already exists. If not, there'll be multiple charts stack together
  625. if (window.chart != undefined) {
  626. window.chart.destroy();
  627. }
  628. window.chart = new Chart(ctx, {
  629. //Line chart
  630. type: 'line',
  631. data: {
  632. //X-axis displays the date
  633. labels: c_m_date,
  634. datasets: [{
  635. //Label above the chart to illustrate which color has which purpose
  636. label: c_wellName,
  637. //Data value
  638. data: c_m_value,
  639. //Detemine line's color
  640. borderColor: '#3e95cd'
  641. },
  642. {
  643. label: "警戒值",
  644. data: warning,
  645. borderColor: "#FF0000",
  646. pointRadius: 0
  647. }
  648. ]
  649. },
  650. options: {
  651. spanGaps: true,
  652. maintainAspectRatio: false,
  653. responsive: true,
  654. scales: {
  655. y: {
  656. title: {
  657. display: true,
  658. text: yLabel
  659. }
  660. },
  661. x: {
  662. title: {
  663. display: true,
  664. text: xLabel
  665. }
  666. }
  667. }
  668. }
  669. });
  670. if (c_wellName.includes("SBM")) {
  671. let warning2 = [];
  672. for (i = 0; i < c_m_date.length; i++) {
  673. warning2.push(-9.5);
  674. }
  675. window.chart.data.datasets.push({
  676. label: "警戒值2",
  677. data: warning2,
  678. borderColor: "#FF0000",
  679. pointRadius: 0
  680. });
  681. window.chart.update();
  682. } else if (c_wellName.includes("SB")) {
  683. let warning2 = [];
  684. for (i = 0; i < c_m_date.length; i++) {
  685. warning2.push(-0.0008);
  686. }
  687. window.chart.data.datasets.push({
  688. label: "警戒值2",
  689. data: warning2,
  690. borderColor: "#FF0000",
  691. pointRadius: 0
  692. });
  693. window.chart.update();
  694. } else if (c_wellName.includes("OW")) {
  695. let warning2 = [];
  696. for (i = 0; i < c_m_date.length; i++) {
  697. warning2.push(OWwarning2);
  698. }
  699. window.chart.data.datasets.push({
  700. label: "警戒值2",
  701. data: warning2,
  702. borderColor: "#FF0000",
  703. pointRadius: 0
  704. });
  705. window.chart.update();
  706. }
  707. }
  708. function init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID) {
  709. var ctx = document.getElementById(elementID).getContext("2d");
  710. var yLabel = "";
  711. var xLabel = "";
  712. let warning = [];
  713. if (c_wellName.includes("TI")) {
  714. for (i = 0; i < c2_m_date.length; i++) {
  715. warning.push(0.00106);
  716. }
  717. yLabel = "徑度量(δ/ L)";
  718. xLabel = "日期";
  719. }
  720. for (j = 0; j < c_m_value.length; j++) {
  721. if (c_m_value[j] == "") {
  722. c_m_value[j] = null;
  723. //console.log(c_m_value[j]);
  724. }
  725. }
  726. if (window.chart != undefined) {
  727. window.chart.destroy();
  728. }
  729. c_m_value.forEach(function (item, index, array) {
  730. //console.log(item, index);
  731. });
  732. window.chart = new Chart(ctx, {
  733. type: 'line',
  734. data: {
  735. labels: c_m_date,
  736. datasets: [{
  737. label: c_wellName,
  738. data: c_m_value,
  739. borderColor: '#3e95cd'
  740. },
  741. {
  742. label: c2_wellName,
  743. data: c2_m_value,
  744. borderColor: '#63fff5'
  745. }
  746. ]
  747. },
  748. options: {
  749. responsive: true,
  750. maintainAspectRatio: false,
  751. scales: {
  752. y: {
  753. title: {
  754. display: true,
  755. text: yLabel
  756. }
  757. },
  758. x: {
  759. title: {
  760. display: true,
  761. text: xLabel
  762. }
  763. }
  764. }
  765. }
  766. });
  767. /*if(c_wellName.includes("ELP") && phase != 2 && phase != 7){
  768. window.chart.data.datasets.push({
  769. label: "警戒值",
  770. data: warning,
  771. borderColor: "#FF0000",
  772. pointRadius: 0
  773. });
  774. if(phase == 3 || phase == 4){
  775. let warning2 = [];
  776. for (i = 0; i < c2_m_date.length; i++) {
  777. warning2.push(ELP_1warning[phase-2]);
  778. }
  779. window.chart.data.datasets.push({
  780. label: "警戒值2",
  781. data: warning2,
  782. borderColor: "#FF0000",
  783. pointRadius: 0
  784. });
  785. }
  786. window.chart.update();
  787. }*/
  788. //ELP does not have second warning line, so you need to update it seperately
  789. if (c_wellName.includes("TI")) {
  790. let warning2 = [];
  791. for (i = 0; i < c2_m_date.length; i++) {
  792. warning2.push(-0.00106);
  793. }
  794. window.chart.data.datasets.push({
  795. label: "警戒值2",
  796. data: warning2,
  797. borderColor: "#FF0000",
  798. pointRadius: 0
  799. });
  800. window.chart.update();
  801. }
  802. }
  803. //SIS SID's lines are vertical
  804. function initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str) {
  805. var ctx = document.getElementById(elementID).getContext("2d");
  806. var datasetValue = [];
  807. let warning = [];
  808. var phase = document.getElementById("phase").value;
  809. var SID_data = [];
  810. var SIS_data = [];
  811. var SIS_array = ['SIS-1', 'SIS-2-1', 'SIS-2-2', 'SIS-3', 'SIS-4', 'SIS-6', 'SIS-7'];
  812. 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'];
  813. var index = 0;
  814. var num = 0;
  815. if (phase == 2) {
  816. SID_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.698, 1.698, 1.186, 1.186, 1.032];
  817. SIS_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.186, 1.032];
  818. } else if (phase == 3) {
  819. SID_data = [2.39, 1.434, 1.434, 1.434, 2.304, 2.304, 2.304, 1.7, 1.7, 1.569];
  820. SIS_data = [2.39, 1.434, 1.434, 1.434, 2.304, 1.7, 1.569];
  821. } else if (phase == 4) {
  822. SID_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.968, 2.968, 2.267, 2.267, 2.176];
  823. SIS_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.267, 2.176];
  824. } else if (phase == 5) {
  825. SID_data = [3.36, 2.626, 2.626, 2.626, 4.531, 4.531, 4.531, 3.727, 3.727, 3.285];
  826. SIS_data = [3.36, 2.626, 2.626, 2.626, 4.531, 3.727, 3.285];
  827. } else if (phase == 6) {
  828. SID_data = [4.015, 3.832, 3.832, 3.832, 7.966, 7.966, 7.966, 5.049, 5.049, 5.208];
  829. SIS_data = [4.015, 3.832, 3.832, 3.832, 7.966, 5.049, 5.208];
  830. } else if (phase == 7) {
  831. SID_data = [4.918, 4.458, 4.458, 4.458, 8.909, 8.909, 8.909, 5.797, 5.797, 5.988];
  832. SIS_data = [4.918, 4.458, 4.458, 4.458, 8.909, 5.797, 5.988];
  833. }
  834. if (str.includes("SIS")) {
  835. index = SIS_array.indexOf(str);
  836. num = SIS_data[index];
  837. } else if (str.includes("SID")) {
  838. index = SID_array.indexOf(str);
  839. num = SID_data[index];
  840. }
  841. for (i = 0; i < c_m_value[0].length; i++) {
  842. warning.push(num);
  843. }
  844. yLabel = "觀測深度GL(m)";
  845. xLabel = "變位量(cm)";
  846. for (j = 0; j < c_m_value.length; j++) {
  847. if (c_m_value[j] == "") {
  848. c_m_value[j] = null;
  849. //console.log(c_m_value[j]);
  850. }
  851. }
  852. if (window.chart != undefined) {
  853. window.chart.destroy();
  854. }
  855. for (j = 0; j <= c_m_date.length; j++) {
  856. if (j == c_m_date.length) {
  857. datasetValue[j] = {
  858. axis: 'y',
  859. fill: false,
  860. label: "警戒值",
  861. data: warning,
  862. borderColor: "#FF0000",
  863. pointRadius: 0
  864. }
  865. } else {
  866. datasetValue[j] = {
  867. axis: 'y',
  868. label: c_m_date[j],
  869. data: c_m_value[j],
  870. borderColor: randomColor()
  871. }
  872. }
  873. }
  874. window.chart = new Chart(ctx, {
  875. type: 'line',
  876. data: {
  877. labels: c_m_depth,
  878. datasets: datasetValue
  879. },
  880. options: {
  881. //Turns line to vertical
  882. maintainAspectRatio: false,
  883. responsive: true,
  884. indexAxis: 'y',
  885. scales: {
  886. y: {
  887. title: {
  888. display: true,
  889. text: yLabel
  890. }
  891. },
  892. x: {
  893. beginAtZero: true,
  894. title: {
  895. display: true,
  896. text: xLabel
  897. }
  898. }
  899. }
  900. }
  901. });
  902. }
  903. 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) {
  904. var ctx = document.getElementById(elementID).getContext("2d");
  905. let warning = [];
  906. if (c_wellName.includes("RS")) {
  907. for (i = 0; i < c_m_date.length; i++) {
  908. warning.push(2000);
  909. }
  910. yLabel = "應力值(kg/cm²)";
  911. xLabel = "日期";
  912. }
  913. if (window.chart != undefined) {
  914. window.chart.destroy();
  915. }
  916. window.chart = new Chart(ctx, {
  917. type: 'line',
  918. data: {
  919. labels: c_m_date,
  920. datasets: [{
  921. label: c_wellName,
  922. data: c_m_value,
  923. borderColor: randomColor()
  924. },
  925. {
  926. label: c2_wellName,
  927. data: c2_m_value,
  928. borderColor: randomColor()
  929. },
  930. {
  931. label: c3_wellName,
  932. data: c3_m_value,
  933. borderColor: randomColor()
  934. },
  935. {
  936. label: c4_wellName,
  937. data: c4_m_value,
  938. borderColor: randomColor()
  939. },
  940. {
  941. label: c5_wellName,
  942. data: c5_m_value,
  943. borderColor: randomColor()
  944. },
  945. {
  946. label: c6_wellName,
  947. data: c6_m_value,
  948. borderColor: randomColor()
  949. },
  950. {
  951. label: "警戒值",
  952. data: warning,
  953. borderColor: "#FF0000",
  954. pointRadius: 0
  955. }
  956. ]
  957. },
  958. options: {
  959. responsive: true,
  960. maintainAspectRatio: false,
  961. scales: {
  962. y: {
  963. title: {
  964. display: true,
  965. text: yLabel
  966. }
  967. },
  968. x: {
  969. title: {
  970. display: true,
  971. text: xLabel
  972. }
  973. }
  974. }
  975. }
  976. });
  977. //ELP does not have second warning line, so you need to update it seperately
  978. if (c_wellName.includes("RS")) {
  979. let warning2 = [];
  980. for (i = 0; i < c_m_date.length; i++) {
  981. warning2.push(-2000);
  982. }
  983. window.chart.data.datasets.push({
  984. label: "警戒值2",
  985. data: warning2,
  986. borderColor: "#FF0000",
  987. pointRadius: 0
  988. });
  989. window.chart.update();
  990. }
  991. }
  992. function initCompare(m_date, chart_data, index, label) {
  993. var ctx = document.getElementById("myChart").getContext("2d");
  994. var value = -7.9;
  995. let warning = [];
  996. var phase = document.getElementById("phase").value;
  997. yLabel = "水位高程GL(m)";
  998. xLabel = "日期";
  999. for (i = 0; i < m_date.length; i++) {
  1000. warning.push(value);
  1001. }
  1002. if (window.chart != undefined) {
  1003. window.chart.destroy();
  1004. }
  1005. window.chart = new Chart(ctx, {
  1006. type: 'line',
  1007. data: {
  1008. labels: m_date
  1009. },
  1010. options: {
  1011. responsive: true,
  1012. maintainAspectRatio: false,
  1013. scales: {
  1014. y: {
  1015. title: {
  1016. display: true,
  1017. text: yLabel
  1018. }
  1019. },
  1020. x: {
  1021. title: {
  1022. display: true,
  1023. text: xLabel
  1024. }
  1025. }
  1026. }
  1027. }
  1028. });
  1029. for (i = 1; i < index + 1; i++) {
  1030. window.chart.data.datasets.push({
  1031. label: label[i].replaceAll("_", "-"),
  1032. data: chart_data[i],
  1033. borderColor: randomColorBlue()
  1034. });
  1035. }
  1036. /*
  1037. if(label[1].includes("ELP") && phase != 2 && phase != 7){
  1038. window.chart.data.datasets.push({
  1039. label: "警戒值",
  1040. data: warning,
  1041. borderColor: "#FF0000",
  1042. pointRadius: 0
  1043. });
  1044. }
  1045. */
  1046. window.chart.update();
  1047. }
  1048. //Chart has multiple lines that need different color
  1049. function randomColor() {
  1050. return "#" + ((1 << 24) * Math.random() | 0).toString(16);
  1051. }
  1052. function randomColorBlue() {
  1053. var mid = Math.floor(Math.random() * 255);
  1054. return "#30" + mid.toString(16) + "ff";
  1055. }
  1056. //Need to display multiple epuiment's data table and can't find the function to reset it. So I kill all the nodes.
  1057. function reset() {
  1058. const myNode = document.getElementById("tabData");
  1059. while (myNode.firstChild) {
  1060. myNode.removeChild(myNode.lastChild);
  1061. }
  1062. var table = document.createElement("table");
  1063. table.id = "dataTable";
  1064. table.className = "display";
  1065. //table.style.width = "100%";
  1066. myNode.appendChild(table);
  1067. }