main.js 37 KB

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