r03.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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 switchNumber = 0;
  18. passString('SIS');
  19. var wellTBA = [];
  20. var wellNameLists = [];
  21. var isAll = true;
  22. var dataTable;
  23. var sparklinePieData = [];
  24. $(document).ready(function () {
  25. GetCheckAllAJAXValue();
  26. LoadPage();
  27. $("#menu > ul > li.nav-parent.nav-active.nav-expanded > ul > li.nav-parent.nav-expanded > ul > li:nth-child(1) > a").css("color", "#0088cc");
  28. $(".monitor").on('click', function () {
  29. $('.monitor').css('color', '#abb4be')
  30. let site = $(this).parent().parent().parent().attr("monitor");
  31. $(this).css("color", "#0088cc");
  32. if (site != 'r03') {
  33. location.href = `../${site}/Index.php`;
  34. } else {
  35. let option = $(this).attr("monitor");
  36. isAll = true;
  37. passString(option);
  38. document.getElementById("monitorName").innerHTML = option + "監測儀器";
  39. LoadPage();
  40. }
  41. });
  42. })
  43. //Pass monitor equipment's name to index.php select form
  44. function passString(option) {
  45. window.localStorage.setItem("option", option);
  46. }
  47. //unity選擇到一個監測儀器後,在selectWell.cs會給一個監測儀器名稱(例:OW-1)給網頁
  48. function GetWellName(wellName) {
  49. showWell(wellName, true);
  50. }
  51. //網頁用SendMessage()傳Initialization()給unity時,unity會回傳一個所有監測儀器名稱(例:OW-1,OW-2 ...)給網頁
  52. function GetWellNameList(wellNameList) {
  53. window.localStorage.setItem("wellNameList", wellNameList);
  54. }
  55. //unity載入後會先跑LoadPage();
  56. function LoadPage() {
  57. var option = window.localStorage.getItem("option");
  58. $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
  59. document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
  60. var wellTBALocal = getCheckValue();
  61. var dataValue = option;
  62. for (i = 0; i < wellTBALocal.length; i++) {
  63. dataValue = dataValue.concat(',', wellTBALocal[i]);
  64. }
  65. if (isLoad) {
  66. //dataValue = 監測儀器代號,超出警戒值的儀器名稱
  67. //AddDataTable會存option:監測儀器代號(string)
  68. // abnormal:超出警戒值的儀器名稱(array)
  69. // gameObjects:所有監測儀器名稱(array)
  70. // optionGameObjects:包含監測儀器代號的所有監測儀器名稱(array)
  71. // 到unity的DataTable.cs裡面
  72. myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
  73. //原本的模型牆被挖空,SID、RS、VG都有建各自的牆,若選擇一種監測儀器則另外兩種隱藏掉
  74. //unity會跑addData(DataTable.option);
  75. //功能是依照DataTable的option將所有optionGameObjects改成normal的顏色
  76. //unity會跑Search(DataTable.option, DataTable.abnormal);
  77. //功能是將所有abnormal的儀器改成abnormal的顏色
  78. myGameInstance.SendMessage("Monitor", "Initialization");
  79. }
  80. var wellNameList = window.localStorage.getItem("wellNameList");
  81. var wellNameListsLocal = wellNameList.split(",");
  82. wellNameLists = wellNameListsLocal.sort();
  83. wellTBA = wellTBALocal;
  84. SetList();
  85. ResetCamera();
  86. showWell(wellNameLists[0], false);
  87. }
  88. //get well info from sql server
  89. function showWell(str, changeCamera) {
  90. var strLocal = "";
  91. strLocal = str;
  92. $("#monitorSelect2").innerHTML = strLocal;
  93. getTable(str);
  94. getChart(str);
  95. if (isLoad) {
  96. //把現在選擇的儀器名稱(例:OW-1)傳到unity,unity找模型名稱相同的改變模型顏色以及鏡頭置中模型
  97. myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
  98. }
  99. if (!changeCamera) {
  100. ResetCamera();
  101. }
  102. }
  103. function getTable(monitor) {
  104. $.ajax({
  105. url: '/BIM-Monitor/script/php/get_monitor_table.php',
  106. type: "GET",
  107. dataType: "JSON",
  108. data: {
  109. monitor: monitor
  110. }
  111. }).success(function (result) {
  112. let table = result.table;
  113. let unit = result.unit;
  114. let haveDepth = result.haveDepth;
  115. let haveDirection = result.haveDirection;
  116. var header = "";
  117. if (haveDepth) {
  118. for (i = 0; i < table[0].length - 1; i++) {
  119. head = i * 0.5;
  120. if (head == 0)
  121. head = "TOP";
  122. header += `<th>${head}</th>`;
  123. }
  124. } else if (haveDirection) {
  125. header = `<th>${monitor}(1~3向)</th><th>${monitor}(2~4向)</th>`;
  126. } else {
  127. header = `<th id="unit">測量值 單位:</th>`;
  128. }
  129. $("#tabData").empty();
  130. $("#tabData").append(`<table id="dataTable" class="display">
  131. <thead>
  132. <tr id="dataTableCol">
  133. <th>測量日期</th>
  134. ${header}
  135. </tr>
  136. </thead>
  137. <tbody id="table">
  138. </tbody>
  139. </table>`);
  140. dataTable = $('#dataTable').DataTable({
  141. bProcessing: true,
  142. responsive: true,
  143. "searching": true,
  144. "pageLength": 10,
  145. "language": {
  146. "processing": "處理中...",
  147. "loadingRecords": "載入中...",
  148. "lengthMenu": "顯示 _MENU_ 項結果",
  149. "zeroRecords": "沒有符合的結果或是沒有資料",
  150. "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
  151. "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
  152. "infoFiltered": "(從 _MAX_ 項結果中過濾)",
  153. "infoPostFix": "",
  154. "search": "",
  155. "paginate": {
  156. "first": '<i class="fa fa-step-backward"></i>',
  157. "previous": '<i class="fa fa-backward"></i>',
  158. "next": '<i class="fa fa-forward"></i>',
  159. "last": '<i class="fa fa-step-forward"></i>'
  160. },
  161. "aria": {
  162. "sortAscending": ": 升冪排列",
  163. "sortDescending": ": 降冪排列"
  164. }
  165. },
  166. });
  167. if (dataTable != null) {
  168. dataTable.clear();
  169. dataTable.draw();
  170. }
  171. if (monitor == '') {
  172. monitor = '查無監測儀器或';
  173. }
  174. $("#tableName").text(monitor + "資料表");
  175. $("#unit").text(`測量值(${unit})`);
  176. table.forEach(function (data) {
  177. dataTable.row.add(data)
  178. dataTable.draw();
  179. });
  180. }).error(function (error) {
  181. console.log(error);
  182. }).complete(function (e) {
  183. });
  184. }
  185. //建立pie chart
  186. function getCheckValue() {
  187. var dataArray = [];
  188. var option = window.localStorage.getItem("option");
  189. $.ajax({
  190. url: "/BIM-Monitor/script/php/get_abnormal.php",
  191. data: {
  192. type: option
  193. },
  194. async: false,
  195. contentType: "application/json",
  196. dataType: "json"
  197. })
  198. .success(function (response) {
  199. dataArray = response['wellTBA'];
  200. var normal_count = response['normal_count'];
  201. var abnormal_count = response['abnormal_count'];
  202. sparklinePieData = [normal_count, abnormal_count];
  203. var all = normal_count + abnormal_count;
  204. var percent = abnormal_count / all;
  205. var url = "/BIM-Monitor/assets/javascripts/ui-elements/pie.charts.js";
  206. var script = document.createElement('script');
  207. script.setAttribute('type', 'text/javascript');
  208. script.setAttribute('src', url);
  209. document.getElementsByTagName('head')[0].appendChild(script);
  210. document.getElementById("percent").innerHTML = Math.round(percent * 100) + "%";
  211. })
  212. .error(function () {
  213. console.log("錯誤統計未正常獲取");
  214. })
  215. .complete(function () {});
  216. return dataArray;
  217. }
  218. //建立左側監測儀器(異常數量/總數量)
  219. function GetCheckAllAJAXValue() {
  220. for (i = 0; i < sites["r03"].length; i++) {
  221. var option = sites["r03"][i].code;
  222. $.ajax({
  223. url: "/BIM-Monitor/script/php/get_abnormal.php",
  224. data: {
  225. type: option
  226. },
  227. async: false,
  228. contentType: "application/json",
  229. dataType: "json"
  230. })
  231. .success(function (response) {
  232. var normal_count = response['normal_count'];
  233. var abnormal_count = response['abnormal_count'];
  234. var all_count = 0 + normal_count + abnormal_count;
  235. $(`.${option}`).html("(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")");
  236. })
  237. .error(function () {
  238. console.log("錯誤統計未正常獲取");
  239. })
  240. .complete(function () {});
  241. }
  242. errorArray = [];
  243. var phase
  244. if (document.getElementById("phase") !== null) {
  245. phase = document.getElementById("phase").value;
  246. } else {
  247. phase = 7;
  248. }
  249. for (i = 0; i < errorTable.length; i++) {
  250. var method = errorTable[i].method;
  251. var option = errorTable[i].table_name;
  252. var table_name = errorTable[i].table_name + "data";
  253. var warning1 = errorTable[i].warning1;
  254. var warning2 = errorTable[i].warning2;
  255. var warning_Count = errorTable[i].warning_Count;
  256. $.ajax({
  257. url: "/BIM-Monitor/script/php/checkValue2.php",
  258. data: {
  259. method: method,
  260. table_name: table_name,
  261. warning1: warning1,
  262. warning2: warning2,
  263. warning_Count: warning_Count,
  264. phase: phase
  265. },
  266. async: false,
  267. contentType: "application/json",
  268. dataType: "json"
  269. })
  270. .success(function (response) {
  271. var normal_count = response['normal_count'];
  272. var abnormal_count = response['abnormal_count'];
  273. var all_count = 0 + normal_count + abnormal_count;
  274. document.getElementById(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
  275. errorArray.push(abnormal_count);
  276. })
  277. .error(function () {
  278. alert("錯誤統計未正常獲取");
  279. })
  280. .complete(function () {});
  281. }
  282. }
  283. function CheckError() {
  284. var checkBox = document.getElementById("errorCheck");
  285. if (checkBox.checked == true) {
  286. isAll = false;
  287. } else {
  288. isAll = true;
  289. }
  290. SetList();
  291. }
  292. //Display chart
  293. function getChart(monitor) {
  294. type = monitor.split("-")[0];
  295. $.ajax({
  296. url: "/BIM-Monitor/script/php/get_monitor_chart.php",
  297. type: "GET",
  298. async: false,
  299. contentType: "application/json",
  300. dataType: "json",
  301. data: {
  302. monitor: monitor
  303. }
  304. }).done(function (response) {
  305. charts = response.chart;
  306. label = response.label;
  307. unit = response.unit;
  308. displayChart(monitor, label, unit, charts);
  309. }).error(function (error) {
  310. console.log(error);
  311. });
  312. }
  313. function displayChart(monitor, label, unit, charts) {
  314. var ctx = document.getElementById("myChart").getContext("2d");
  315. var date = [];
  316. var data = [];
  317. var warning1 = [];
  318. var action1 = [];
  319. var warning2 = [];
  320. var action2 = [];
  321. var type = monitor.split("-")[0];
  322. var SIS_data = {};
  323. if (window.chart != undefined) {
  324. window.chart.destroy();
  325. }
  326. if (type == "SIS" || type == "SID") {
  327. SIS_data["depth"] = [];
  328. SIS_data["warning1"] = [];
  329. SIS_data["warning2"] = [];
  330. SIS_data["action1"] = [];
  331. SIS_data["action2"] = [];
  332. SIS_data["data"] = {};
  333. charts.forEach(element => {
  334. var sis_date = element["Date"];
  335. var sis_warning = element["WarningValue"].split("±")[1];
  336. var sis_action = element["ActionValue"].split("±")[1];
  337. delete element["Date"];
  338. delete element["WarningValue"];
  339. delete element["ActionValue"];
  340. var sis_data_length = Object.keys(element).length;
  341. SIS_data["data"][sis_date] = [];
  342. for (i = 1; i <= sis_data_length; i++) {
  343. SIS_data["data"][sis_date].push(element["" + i * 0.5]);
  344. if (SIS_data["depth"].length < sis_data_length) {
  345. SIS_data["depth"].push(i * 0.5);
  346. SIS_data["warning1"].push(+sis_warning);
  347. SIS_data["warning2"].push(-sis_warning);
  348. SIS_data["action1"].push(+sis_action);
  349. SIS_data["action2"].push(-sis_action);
  350. }
  351. }
  352. });
  353. var datasets = [{
  354. label: "警戒值+",
  355. data: SIS_data["warning1"],
  356. borderColor: "#FF0000",
  357. borderDash: [5, 5],
  358. pointRadius: 0
  359. }, {
  360. label: "警戒值-",
  361. data: SIS_data["warning2"],
  362. borderColor: "#FF0000",
  363. borderDash: [5, 5],
  364. pointRadius: 0
  365. }, {
  366. label: "行動值+",
  367. data: SIS_data["action1"],
  368. borderColor: "#FF0000",
  369. pointRadius: 0
  370. }, {
  371. label: "行動值-",
  372. data: SIS_data["action2"],
  373. borderColor: "#FF0000",
  374. pointRadius: 0
  375. }];
  376. Object.keys(SIS_data["data"]).forEach(element => {
  377. datasets.push({
  378. label: element,
  379. data: SIS_data["data"][element],
  380. borderColor: randomColorBlue(),
  381. pointRadius: 0
  382. });
  383. });
  384. window.chart = new Chart(ctx, {
  385. //Line chart
  386. type: 'line',
  387. data: {
  388. labels: SIS_data["depth"],
  389. datasets: datasets
  390. },
  391. options: {
  392. spanGaps: true,
  393. maintainAspectRatio: false,
  394. responsive: true,
  395. indexAxis: 'y',
  396. scales: {
  397. y: {
  398. title: {
  399. display: true,
  400. text: "觀測深度(m)"
  401. }
  402. },
  403. x: {
  404. title: {
  405. display: true,
  406. text: label + '(' + unit + ')'
  407. }
  408. }
  409. }
  410. }
  411. });
  412. } else {
  413. charts.forEach(function (chart) {
  414. Object.keys(chart).forEach(function (key) {
  415. if (key == "Date") {
  416. date.push(chart[key]);
  417. } else if (key.includes("WarningValue")) {
  418. let value = 0;
  419. if (chart[key].includes("±")) {
  420. value = chart[key].split("±")[1];
  421. warning1.push(+value);
  422. warning2.push(-value);
  423. }
  424. if (key.includes("High")) {
  425. warning1.push(chart[key]);
  426. } else if (key.includes("Low")) {
  427. warning2.push(chart[key]);
  428. }
  429. } else if (key.includes("ActionValue")) {
  430. let value = 0;
  431. if (chart[key].includes("±")) {
  432. value = chart[key].split("±")[1];
  433. action1.push(+value);
  434. action2.push(-value);
  435. }
  436. if (key.includes("High")) {
  437. action1.push(chart[key]);
  438. } else if (key.includes("Low")) {
  439. action2.push(chart[key]);
  440. }
  441. } else {
  442. data.push(chart[key]);
  443. }
  444. });
  445. })
  446. var datasets = [{
  447. label: "警戒值+",
  448. data: warning1,
  449. borderColor: "#FF0000",
  450. borderDash: [5, 5],
  451. pointRadius: 0
  452. }, {
  453. label: "警戒值-",
  454. data: warning2,
  455. borderColor: "#FF0000",
  456. borderDash: [5, 5],
  457. pointRadius: 0
  458. }, {
  459. label: "行動值+",
  460. data: action1,
  461. borderColor: "#FF0000",
  462. pointRadius: 0
  463. }, {
  464. label: "行動值-",
  465. data: action2,
  466. borderColor: "#FF0000",
  467. pointRadius: 0
  468. }];
  469. if (type == "TI") {
  470. var data1 = [];
  471. var data2 = [];
  472. for (i = 0; i < data.length; i += 2) {
  473. data1.push(data[i]);
  474. data2.push(data[i + 1]);
  475. }
  476. datasets.push({
  477. label: monitor + "(1-3)",
  478. data: data1,
  479. borderColor: "#3e95cd"
  480. });
  481. datasets.push({
  482. label: monitor + "(2-4)",
  483. data: data2,
  484. borderColor: "#000000"
  485. });
  486. } else {
  487. datasets.push({
  488. label: monitor,
  489. data: data,
  490. borderColor: "#3e95cd"
  491. });
  492. }
  493. window.chart = new Chart(ctx, {
  494. //Line chart
  495. type: 'line',
  496. data: {
  497. //X-axis displays the date
  498. labels: date,
  499. datasets: datasets
  500. },
  501. options: {
  502. spanGaps: true,
  503. maintainAspectRatio: false,
  504. responsive: true,
  505. scales: {
  506. x: {
  507. title: {
  508. display: true,
  509. text: "日期"
  510. }
  511. },
  512. y: {
  513. title: {
  514. display: true,
  515. text: label + '(' + unit + ')'
  516. }
  517. }
  518. }
  519. }
  520. });
  521. }
  522. }
  523. function ResetCamera() {
  524. if (isLoad) {
  525. myGameInstance.SendMessage("MainCamera", "ResetCamera");
  526. }
  527. }
  528. //選擇觀測儀器
  529. function SetList() {
  530. var wellNameListsLocal = "";
  531. var isError = false;
  532. var monitorSelect = document.getElementById("monitorSelect");
  533. var monitorButton = document.getElementById("monitorButton");
  534. while (monitorSelect.hasChildNodes()) {
  535. monitorSelect.removeChild(monitorSelect.firstChild);
  536. }
  537. while (monitorButton.hasChildNodes()) {
  538. monitorButton.removeChild(monitorButton.firstChild);
  539. }
  540. monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
  541. GetCheckAllAJAXValue();
  542. for (i = 0; i < wellNameLists.length; i++) {
  543. wellNameListsLocal = wellNameLists[i];
  544. var option = document.createElement("li");
  545. var createA = document.createElement("a");
  546. var createAText = document.createTextNode(wellNameListsLocal);
  547. var createButton = document.createElement("button");
  548. var createButtonText = document.createTextNode(wellNameListsLocal);
  549. createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
  550. for (j = 0; j < wellTBA.length; j++) {
  551. if (wellNameLists[i] == (wellTBA[j])) {
  552. createA.style = "color:red;";
  553. createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
  554. isError = true;
  555. }
  556. }
  557. createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  558. createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  559. createButton.setAttribute('type', "button");
  560. if (isAll || (!isAll && isError)) {
  561. createA.appendChild(createAText);
  562. createButton.appendChild(createButtonText);
  563. option.appendChild(createA);
  564. monitorSelect.appendChild(option);
  565. monitorButton.appendChild(createButton);
  566. }
  567. isError = false;
  568. }
  569. }
  570. function UpdateGPS(GPS) {
  571. if (isLoad) {
  572. myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
  573. }
  574. }
  575. function randomColorBlue() {
  576. var mid = Math.floor(Math.random() * 255);
  577. return "#30" + mid.toString(16) + "ff";
  578. }