r03.js 35 KB

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