main.js 36 KB

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