c3.js 38 KB

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