| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- var unityName = "R03Monitor";
- var errorTable;
- var sites = {};
- var display_info = {};
- $.ajaxSettings.async = false;
- var jqxhr = $.getJSON("/BIM-Monitor/assets/errorTable.json", function (json) {
- errorTable = json;
- });
- var C3Json = $.getJSON("/BIM-Monitor/assets/json/c3-monitorList.json", function (json) {
- sites["c3"] = json;
- });
- var R03Json = $.getJSON("/BIM-Monitor/assets/json/r03-monitorList.json", function (json) {
- sites["r03"] = json;
- });
- $.ajaxSettings.async = true;
- var lastNode;
- var switchNumber = 0;
- passString('SIS');
- var wellTBA = [];
- var wellNameLists = [];
- var isAll = true;
- var dataTable;
- var sparklinePieData = [];
- $(document).ready(function () {
- GetCheckAllAJAXValue();
- LoadPage();
- $("#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");
- $(".monitor").on('click', function () {
- $('.monitor').css('color', '#abb4be')
- let site = $(this).parent().parent().parent().attr("monitor");
- $(this).css("color", "#0088cc");
- if (site != 'r03') {
- location.href = `../${site}/Index.php`;
- } else {
- let option = $(this).attr("monitor");
- isAll = true;
- passString(option);
- document.getElementById("monitorName").innerHTML = option + "監測儀器";
- LoadPage();
- }
- });
- })
- //Pass monitor equipment's name to index.php select form
- function passString(option) {
- window.localStorage.setItem("option", option);
- }
- //unity選擇到一個監測儀器後,在selectWell.cs會給一個監測儀器名稱(例:OW-1)給網頁
- function GetWellName(wellName) {
- showWell(wellName, true);
- }
- //網頁用SendMessage()傳Initialization()給unity時,unity會回傳一個所有監測儀器名稱(例:OW-1,OW-2 ...)給網頁
- function GetWellNameList(wellNameList) {
- window.localStorage.setItem("wellNameList", wellNameList);
- }
- //display well name and send its name to showWell function
- function getEquipmentName(equipment) {
- $.ajaxSettings.async = false;
- $.ajax({
- url: '/BIM-Monitor/script/php/getEquipmentName.php',
- type: "GET",
- data: {
- equipment: equipment,
- }
- }).success(function (data) {
- GetWellNameList(data);
- }).error(function (error) {
- console.log("錯誤");
- });
- $.ajaxSettings.async = true;
- }
- //unity載入後會先跑LoadPage();
- function LoadPage() {
- var option = window.localStorage.getItem("option");
- getEquipmentName(option);
- $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
- document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
- var wellTBALocal = getCheckValue();
- var dataValue = option;
- for (i = 0; i < wellTBALocal.length; i++) {
- dataValue = dataValue.concat(',', wellTBALocal[i]);
- }
- if (isLoad) {
- //dataValue = 監測儀器代號,超出警戒值的儀器名稱
- //AddDataTable會存option:監測儀器代號(string)
- // abnormal:超出警戒值的儀器名稱(array)
- // gameObjects:所有監測儀器名稱(array)
- // optionGameObjects:包含監測儀器代號的所有監測儀器名稱(array)
- // 到unity的DataTable.cs裡面
- myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
- //原本的模型牆被挖空,SID、RS、VG都有建各自的牆,若選擇一種監測儀器則另外兩種隱藏掉
- //unity會跑addData(DataTable.option);
- //功能是依照DataTable的option將所有optionGameObjects改成normal的顏色
- //unity會跑Search(DataTable.option, DataTable.abnormal);
- //功能是將所有abnormal的儀器改成abnormal的顏色
- myGameInstance.SendMessage("Monitor", "Initialization");
- }
- var wellNameList = window.localStorage.getItem("wellNameList");
- var wellNameListsLocal = wellNameList.split(",");
- var order = new Array(wellNameListsLocal.length);
- for (i = 0; i < wellNameListsLocal.length; i++) {
- order[i] = wellNameListsLocal[i].match(/\d+/g);
- }
- for (i = 0; i < order.length; i++) {
- for (j = 0; j < order.length; j++) {
- if (order[j] > order[j + 1]) {
- let temp = order[j];
- order[j] = order[j + 1];
- order[j + 1] = temp;
- let temp2 = wellNameListsLocal[j];
- wellNameListsLocal[j] = wellNameListsLocal[j + 1];
- wellNameListsLocal[j + 1] = temp2;
- }
- }
- }
- wellNameLists = wellNameListsLocal;
- wellTBA = wellTBALocal;
- SetList();
- ResetCamera();
- showWell(wellNameLists[0], false);
- }
- //get well info from sql server
- function showWell(str, changeCamera) {
- var strLocal = "";
- strLocal = str;
- $("#monitorSelect2").innerHTML = strLocal;
- getTable(str);
- getChart(str);
- if (isLoad) {
- //把現在選擇的儀器名稱(例:OW-1)傳到unity,unity找模型名稱相同的改變模型顏色以及鏡頭置中模型
- myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
- }
- if (!changeCamera) {
- ResetCamera();
- }
- }
- function getTable(monitor) {
- $.ajax({
- url: '/BIM-Monitor/script/php/get_monitor_table.php',
- type: "GET",
- dataType: "JSON",
- data: {
- monitor: monitor
- }
- }).success(function (result) {
- let table = result.table;
- let unit = result.unit;
- let haveDepth = result.haveDepth;
- let haveDirection = result.haveDirection;
- var header = "";
- if (haveDepth) {
- for (i = 0; i < table[0].length - 1; i++) {
- head = i * 0.5;
- if (head == 0)
- head = "TOP";
- header += `<th>${head}</th>`;
- }
- } else if (haveDirection) {
- header = `<th>${monitor}(1~3向)</th><th>${monitor}(2~4向)</th>`;
- } else {
- header = `<th id="unit">測量值 單位:</th>`;
- }
- $("#tabData").empty();
- $("#tabData").append(`<table id="dataTable" class="display">
- <thead>
- <tr id="dataTableCol">
- <th>測量日期</th>
- ${header}
- </tr>
- </thead>
- <tbody id="table">
- </tbody>
- </table>`);
- dataTable = $('#dataTable').DataTable({
- bProcessing: true,
- responsive: true,
- "searching": true,
- "pageLength": 10,
- "language": {
- "processing": "處理中...",
- "loadingRecords": "載入中...",
- "lengthMenu": "顯示 _MENU_ 項結果",
- "zeroRecords": "沒有符合的結果或是沒有資料",
- "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
- "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
- "infoFiltered": "(從 _MAX_ 項結果中過濾)",
- "infoPostFix": "",
- "search": "",
- "paginate": {
- "first": '<i class="fa fa-step-backward"></i>',
- "previous": '<i class="fa fa-backward"></i>',
- "next": '<i class="fa fa-forward"></i>',
- "last": '<i class="fa fa-step-forward"></i>'
- },
- "aria": {
- "sortAscending": ": 升冪排列",
- "sortDescending": ": 降冪排列"
- }
- },
- });
- if (dataTable != null) {
- dataTable.clear();
- dataTable.draw();
- }
- if (monitor == '') {
- monitor = '查無監測儀器或';
- }
- $("#tableName").text(monitor + "資料表");
- $("#unit").text(`測量值(${unit})`);
- table.forEach(function (data) {
- dataTable.row.add(data)
- dataTable.draw();
- });
- }).error(function (error) {
- console.log(error);
- }).complete(function (e) {
- });
- }
- //建立pie chart
- function getCheckValue() {
- var dataArray = [];
- var option = window.localStorage.getItem("option");
- $.ajax({
- url: "/BIM-Monitor/script/php/get_abnormal.php",
- data: {
- type: option
- },
- async: false,
- contentType: "application/json",
- dataType: "json"
- })
- .success(function (response) {
- dataArray = response['wellTBA'];
- var normal_count = response['normal_count'];
- var abnormal_count = response['abnormal_count'];
- sparklinePieData = [normal_count, abnormal_count];
- var all = normal_count + abnormal_count;
- var percent = abnormal_count / all;
- var url = "/BIM-Monitor/assets/javascripts/ui-elements/pie.charts.js";
- var script = document.createElement('script');
- script.setAttribute('type', 'text/javascript');
- script.setAttribute('src', url);
- document.getElementsByTagName('head')[0].appendChild(script);
- document.getElementById("percent").innerHTML = Math.round(percent * 100) + "%";
- })
- .error(function () {
- console.log("錯誤統計未正常獲取");
- })
- .complete(function () {});
- return dataArray;
- }
- //建立左側監測儀器(異常數量/總數量)
- function GetCheckAllAJAXValue() {
- for (i = 0; i < sites["r03"].length; i++) {
- var option = sites["r03"][i].code;
- $.ajax({
- url: "/BIM-Monitor/script/php/get_abnormal.php",
- data: {
- type: option
- },
- async: false,
- contentType: "application/json",
- dataType: "json"
- })
- .success(function (response) {
- var normal_count = response['normal_count'];
- var abnormal_count = response['abnormal_count'];
- var all_count = 0 + normal_count + abnormal_count;
- $(`.${option}`).html("(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")");
- })
- .error(function () {
- console.log("錯誤統計未正常獲取");
- })
- .complete(function () {});
- }
- }
- function CheckError() {
- var checkBox = document.getElementById("errorCheck");
- if (checkBox.checked == true) {
- isAll = false;
- } else {
- isAll = true;
- }
- SetList();
- }
- //Display chart
- function getChart(monitor) {
- console.log("monitor: " + monitor);
- type = monitor.split("-")[0];
- $.ajax({
- url: "/BIM-Monitor/script/php/get_monitor_chart.php",
- type: "GET",
- async: false,
- contentType: "application/json",
- dataType: "json",
- data: {
- monitor: monitor
- }
- }).done(function (response) {
- charts = response.chart;
- label = response.label;
- unit = response.unit;
- displayChart(monitor, label, unit, charts);
- }).error(function (error) {
- console.log(error);
- });
- }
- function displayChart(monitor, label, unit, charts) {
- var ctx = document.getElementById("myChart").getContext("2d");
- var date = [];
- var data = [];
- var warning1 = [];
- var action1 = [];
- var warning2 = [];
- var action2 = [];
- var type = monitor.split("-")[0];
- var SIS_data = {};
- if (window.chart != undefined) {
- window.chart.destroy();
- }
- if (type == "SIS" || type == "SID") {
- SIS_data["depth"] = [];
- SIS_data["warning1"] = [];
- SIS_data["warning2"] = [];
- SIS_data["action1"] = [];
- SIS_data["action2"] = [];
- SIS_data["data"] = {};
- charts.forEach(element => {
- var sis_date = element["Date"];
- var sis_warning = element["WarningValue"].split("±")[1];
- var sis_action = element["ActionValue"].split("±")[1];
- delete element["Date"];
- delete element["WarningValue"];
- delete element["ActionValue"];
- var sis_data_length = Object.keys(element).length;
- SIS_data["data"][sis_date] = [];
- for (i = 1; i <= sis_data_length; i++) {
- SIS_data["data"][sis_date].push(element["" + i * 0.5]);
- if (SIS_data["depth"].length < sis_data_length) {
- SIS_data["depth"].push(i * 0.5);
- SIS_data["warning1"].push(+sis_warning);
- SIS_data["warning2"].push(-sis_warning);
- SIS_data["action1"].push(+sis_action);
- SIS_data["action2"].push(-sis_action);
- }
- }
- });
- var datasets = [{
- label: "警戒值+",
- data: SIS_data["warning1"],
- borderColor: "#FF0000",
- borderDash: [5, 5],
- pointRadius: 0
- }, {
- label: "警戒值-",
- data: SIS_data["warning2"],
- borderColor: "#FF0000",
- borderDash: [5, 5],
- pointRadius: 0
- }, {
- label: "行動值+",
- data: SIS_data["action1"],
- borderColor: "#FF0000",
- pointRadius: 0
- }, {
- label: "行動值-",
- data: SIS_data["action2"],
- borderColor: "#FF0000",
- pointRadius: 0
- }];
- Object.keys(SIS_data["data"]).forEach(element => {
- datasets.push({
- label: element,
- data: SIS_data["data"][element],
- borderColor: randomColorBlue(),
- pointRadius: 0
- });
- });
- window.chart = new Chart(ctx, {
- //Line chart
- type: 'line',
- data: {
- labels: SIS_data["depth"],
- datasets: datasets
- },
- options: {
- spanGaps: true,
- maintainAspectRatio: false,
- responsive: true,
- indexAxis: 'y',
- scales: {
- y: {
- title: {
- display: true,
- text: "觀測深度(m)"
- }
- },
- x: {
- title: {
- display: true,
- text: label + '(' + unit + ')'
- }
- }
- }
- }
- });
- } else {
- charts.forEach(function (chart) {
- Object.keys(chart).forEach(function (key) {
- if (key == "Date") {
- date.push(chart[key]);
- } else if (key.includes("WarningValue")) {
- let value = 0;
- if (chart[key].includes("±")) {
- value = chart[key].split("±")[1];
- warning1.push(+value);
- warning2.push(-value);
- }
- if (key.includes("High")) {
- warning1.push(chart[key]);
- } else if (key.includes("Low")) {
- warning2.push(chart[key]);
- }
- } else if (key.includes("ActionValue")) {
- let value = 0;
- if (chart[key].includes("±")) {
- value = chart[key].split("±")[1];
- action1.push(+value);
- action2.push(-value);
- }
- if (key.includes("High")) {
- action1.push(chart[key]);
- } else if (key.includes("Low")) {
- action2.push(chart[key]);
- }
- } else {
- data.push(chart[key]);
- }
- });
- })
- var datasets = [{
- label: "警戒值+",
- data: warning1,
- borderColor: "#FF0000",
- borderDash: [5, 5],
- pointRadius: 0
- }, {
- label: "警戒值-",
- data: warning2,
- borderColor: "#FF0000",
- borderDash: [5, 5],
- pointRadius: 0
- }, {
- label: "行動值+",
- data: action1,
- borderColor: "#FF0000",
- pointRadius: 0
- }, {
- label: "行動值-",
- data: action2,
- borderColor: "#FF0000",
- pointRadius: 0
- }];
- if (type == "TI") {
- var data1 = [];
- var data2 = [];
- for (i = 0; i < data.length; i += 2) {
- data1.push(data[i]);
- data2.push(data[i + 1]);
- }
- datasets.push({
- label: monitor + "(1-3)",
- data: data1,
- borderColor: "#3e95cd"
- });
- datasets.push({
- label: monitor + "(2-4)",
- data: data2,
- borderColor: "#000000"
- });
- } else {
- datasets.push({
- label: monitor,
- data: data,
- borderColor: "#3e95cd"
- });
- }
- window.chart = new Chart(ctx, {
- //Line chart
- type: 'line',
- data: {
- //X-axis displays the date
- labels: date,
- datasets: datasets
- },
- options: {
- spanGaps: true,
- maintainAspectRatio: false,
- responsive: true,
- scales: {
- x: {
- title: {
- display: true,
- text: "日期"
- }
- },
- y: {
- title: {
- display: true,
- text: label + '(' + unit + ')'
- }
- }
- }
- }
- });
- }
- }
- function ResetCamera() {
- if (isLoad) {
- myGameInstance.SendMessage("MainCamera", "ResetCamera");
- }
- }
- //選擇觀測儀器
- function SetList() {
- var wellNameListsLocal = "";
- var isError = false;
- var monitorSelect = document.getElementById("monitorSelect");
- var monitorButton = document.getElementById("monitorButton");
- while (monitorSelect.hasChildNodes()) {
- monitorSelect.removeChild(monitorSelect.firstChild);
- }
- while (monitorButton.hasChildNodes()) {
- monitorButton.removeChild(monitorButton.firstChild);
- }
- monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
- GetCheckAllAJAXValue();
- for (i = 0; i < wellNameLists.length; i++) {
- wellNameListsLocal = wellNameLists[i];
- var option = document.createElement("li");
- var createA = document.createElement("a");
- var createAText = document.createTextNode(wellNameListsLocal);
- var createButton = document.createElement("button");
- var createButtonText = document.createTextNode(wellNameListsLocal);
- createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
- for (j = 0; j < wellTBA.length; j++) {
- if (wellNameLists[i] == (wellTBA[j])) {
- createA.style = "color:red;";
- createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
- isError = true;
- }
- }
- createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
- createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
- createButton.setAttribute('type', "button");
- if (isAll || (!isAll && isError)) {
- createA.appendChild(createAText);
- createButton.appendChild(createButtonText);
- option.appendChild(createA);
- monitorSelect.appendChild(option);
- monitorButton.appendChild(createButton);
- }
- isError = false;
- }
- }
- function UpdateGPS(GPS) {
- if (isLoad) {
- myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
- }
- }
- function randomColorBlue() {
- var mid = Math.floor(Math.random() * 255);
- return "#30" + mid.toString(16) + "ff";
- }
|