r03.js 36 KB

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