Browse Source

新增錯誤統計

manto07m 3 years ago
parent
commit
35fabe0321

+ 2 - 2
R03/display_info.json

@@ -81,10 +81,10 @@
  },
  },
  {
  {
   "type": "SP",
   "type": "SP",
-  "display": "WaterLevelElevation",
+  "display": "WaterPressure",
   "haveDepth": false,
   "haveDepth": false,
   "haveDirection": false,
   "haveDirection": false,
-  "unit": "m",
+  "unit": "t/m²",
   "label":""
   "label":""
  },
  },
  {
  {

+ 4 - 4
assets/json/r03-monitorList.json

@@ -19,6 +19,10 @@
       "code": "TI",
       "code": "TI",
       "name": "建物傾斜計"
       "name": "建物傾斜計"
     },
     },
+    {
+      "code": "SP",
+      "name": "豎管式水壓計"
+    },
     {
     {
       "code": "SS",
       "code": "SS",
       "name": "淺層沉陷點"
       "name": "淺層沉陷點"
@@ -39,10 +43,6 @@
       "code": "OW",
       "code": "OW",
       "name": "水位觀測井"
       "name": "水位觀測井"
     },
     },
-    {
-      "code": "SP",
-      "name": "豎管式水壓計"
-    },
     {
     {
       "code": "EP",
       "code": "EP",
       "name": "電力傳感式水壓計"
       "name": "電力傳感式水壓計"

+ 1 - 42
script/js/global.js

@@ -16,47 +16,6 @@ const vm = Vue.createApp({
         }
         }
     }
     }
 });
 });
-vm.component('side-bar-home', {
-    data() {
-        return {
-            sites: sites,
-        }
-    },
-    template: `<aside id="sidebar-left" class="sidebar-left">
-                    <div class="sidebar-header">
-                        <div class="sidebar-title"> 導覽 </div>
-                        <div class="sidebar-toggle hidden-xs" data-toggle-class="sidebar-left-collapsed" data-target="html" data-fire-event="sidebar-left-toggle"> <i class="fa fa-bars" aria-label="Toggle sidebar"></i> </div>
-                    </div>
-                    <div class="nano">
-                        <div class="nano-content">
-                            <nav id="menu" class="nav-main" role="navigation">
-                                <ul class="nav nav-main">
-                                    <li>
-                                        <a href="/BIM-Monitor/home.php"> <i class="fa fa-home" aria-hidden="true"></i> <span>首頁</span> </a>
-                                    </li>
-
-                                    <li class="nav-parent nav-active nav-expanded">
-                                        <a>
-                                            <i class="fa fa-desktop" aria-hidden="true"></i>
-                                            <span>BIM監測查詢網</span>
-                                        </a>
-                                        <ul class="nav nav-children">
-                                            <li class="nav-parent nav-active nav-expanded">
-                                                <a>
-                                                    <span>C3工地監測儀器</span>
-                                                </a>
-                                                <ul class="nav nav-children">
-                                                    <monitor-li v-for="monitor in sites['c3']" :id='monitor.code' :name='monitor.name'></monitor-li>
-                                                </ul>
-                                            </li>
-                                        </ul>
-                                    </li>
-                                </ul>
-                            </nav>
-                        </div>
-                    </div>
-                </aside>`
-});
 
 
 
 
 vm.component('upload-csv', {
 vm.component('upload-csv', {
@@ -150,7 +109,7 @@ vm.component('side-bar', {
 
 
 vm.component('monitor-li', {
 vm.component('monitor-li', {
     template: `<li> <a :href="GetHref(id)" class="monitor" :monitor="id">
     template: `<li> <a :href="GetHref(id)" class="monitor" :monitor="id">
-                    {{name}}<span :id="id" class="pull-right" data-toggle="tooltip" data-placement="right" title="(異常儀器數量/所有儀器數量)">0</span>
+                    {{name}}<span :id="id" class="pull-right" :class="id"  data-toggle="tooltip" data-placement="right" title="(異常儀器數量/所有儀器數量)">0</span>
                 </a> </li>`,
                 </a> </li>`,
     props: {
     props: {
         id: String,
         id: String,

+ 93 - 158
script/js/r03.js

@@ -251,7 +251,7 @@ function getTable(monitor) {
 
 
 //建立pie chart
 //建立pie chart
 function getCheckValue() {
 function getCheckValue() {
-    /*
+    
     var dataArray = [];
     var dataArray = [];
 
 
     var option = window.localStorage.getItem("option");
     var option = window.localStorage.getItem("option");
@@ -266,13 +266,9 @@ function getCheckValue() {
     }
     }
 
 
     $.ajax({
     $.ajax({
-            url: "/BIM-Monitor/script/php/checkValue2.php",
+            url: "/BIM-Monitor/script/php/get_abnormal.php",
             data: {
             data: {
-                method: method,
-                table_name: table_name,
-                warning1: warning1,
-                warning2: warning2,
-                warning_Count: warning_Count
+                type:option
             },
             },
             async: false,
             async: false,
             contentType: "application/json",
             contentType: "application/json",
@@ -282,9 +278,7 @@ function getCheckValue() {
         .success(function (response) {
         .success(function (response) {
             console.log(response)
             console.log(response)
             dataArray = response['wellTBA'];
             dataArray = response['wellTBA'];
-            for (var i = 0; i < dataArray.length; i++) {
-                dataArray[i] = dataArray[i].replace('_', '-');
-            }
+            
             var normal_count = response['normal_count'];
             var normal_count = response['normal_count'];
             var abnormal_count = response['abnormal_count'];
             var abnormal_count = response['abnormal_count'];
             sparklinePieData = [normal_count, abnormal_count];
             sparklinePieData = [normal_count, abnormal_count];
@@ -302,31 +296,22 @@ function getCheckValue() {
         })
         })
         .complete(function () {});
         .complete(function () {});
     return dataArray;
     return dataArray;
-    */
+    
     var dataArray = [];
     var dataArray = [];
     return dataArray;
     return dataArray;
 }
 }
 
 
 //建立左側監測儀器(異常數量/總數量)
 //建立左側監測儀器(異常數量/總數量)
 function GetCheckAllAJAXValue() {
 function GetCheckAllAJAXValue() {
-    /*
+    
         errorArray = [];
         errorArray = [];
-        for (i = 0; i < errorTable.length; i++) {
+        for (i = 0; i < sites["r03"].length; i++) {
 
 
-            var method = errorTable[i].method;
-            var option = errorTable[i].table_name;
-            var table_name = errorTable[i].table_name + "data";
-            var warning1 = errorTable[i].warning1;
-            var warning2 = errorTable[i].warning2;
-            var warning_Count = errorTable[i].warning_Count;
+            var option = sites["r03"][i].code;
             $.ajax({
             $.ajax({
-                    url: "/BIM-Monitor/script/php/checkValue2.php",
+                    url: "/BIM-Monitor/script/php/get_abnormal.php",
                     data: {
                     data: {
-                        method: method,
-                        table_name: table_name,
-                        warning1: warning1,
-                        warning2: warning2,
-                        warning_Count: warning_Count
+                        type: option
                     },
                     },
                     async: false,
                     async: false,
                     contentType: "application/json",
                     contentType: "application/json",
@@ -338,9 +323,9 @@ function GetCheckAllAJAXValue() {
                     var normal_count = response['normal_count'];
                     var normal_count = response['normal_count'];
                     var abnormal_count = response['abnormal_count'];
                     var abnormal_count = response['abnormal_count'];
                     var all_count = 0 + normal_count + abnormal_count;
                     var all_count = 0 + normal_count + abnormal_count;
-
-
-                    document.getElementById(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
+                    console.log("option: " + option);
+                    $(`.${option}`).html("(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")");
+                    //document.getElementByName(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
                     errorArray.push(abnormal_count);
                     errorArray.push(abnormal_count);
                 })
                 })
                 .error(function () {
                 .error(function () {
@@ -348,7 +333,7 @@ function GetCheckAllAJAXValue() {
                 })
                 })
                 .complete(function () {});
                 .complete(function () {});
         }
         }
-    */
+    
 }
 }
 
 
 
 
@@ -458,13 +443,13 @@ function displayChart(monitor, label, unit, charts) {
             label: "警戒值+",
             label: "警戒值+",
             data: SIS_data["warning1"],
             data: SIS_data["warning1"],
             borderColor: "#FF0000",
             borderColor: "#FF0000",
-            borderDash: [5,5],
+            borderDash: [5, 5],
             pointRadius: 0
             pointRadius: 0
         }, {
         }, {
             label: "警戒值-",
             label: "警戒值-",
             data: SIS_data["warning2"],
             data: SIS_data["warning2"],
             borderColor: "#FF0000",
             borderColor: "#FF0000",
-            borderDash: [5,5],
+            borderDash: [5, 5],
             pointRadius: 0
             pointRadius: 0
         }, {
         }, {
             label: "行動值+",
             label: "行動值+",
@@ -522,20 +507,32 @@ function displayChart(monitor, label, unit, charts) {
             Object.keys(chart).forEach(function (key) {
             Object.keys(chart).forEach(function (key) {
                 if (key == "Date") {
                 if (key == "Date") {
                     date.push(chart[key]);
                     date.push(chart[key]);
-                } else if (key == "WarningValue") {
+                } else if (key.includes("WarningValue")) {
                     let value = 0;
                     let value = 0;
                     if (chart[key].includes("±")) {
                     if (chart[key].includes("±")) {
                         value = chart[key].split("±")[1];
                         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]);
                     }
                     }
-                    warning1.push(+value);
-                    warning2.push(-value);
-                } else if (key == "ActionValue") {
+
+                } else if (key.includes("ActionValue")) {
                     let value = 0;
                     let value = 0;
                     if (chart[key].includes("±")) {
                     if (chart[key].includes("±")) {
                         value = chart[key].split("±")[1];
                         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]);
                     }
                     }
-                    action1.push(+value);
-                    action2.push(-value);
+
                 } else {
                 } else {
                     data.push(chart[key]);
                     data.push(chart[key]);
                 }
                 }
@@ -546,13 +543,13 @@ function displayChart(monitor, label, unit, charts) {
             label: "警戒值+",
             label: "警戒值+",
             data: warning1,
             data: warning1,
             borderColor: "#FF0000",
             borderColor: "#FF0000",
-            borderDash: [5,5],
+            borderDash: [5, 5],
             pointRadius: 0
             pointRadius: 0
         }, {
         }, {
             label: "警戒值-",
             label: "警戒值-",
             data: warning2,
             data: warning2,
             borderColor: "#FF0000",
             borderColor: "#FF0000",
-            borderDash: [5,5],
+            borderDash: [5, 5],
             pointRadius: 0
             pointRadius: 0
         }, {
         }, {
             label: "行動值+",
             label: "行動值+",
@@ -786,19 +783,19 @@ function init(c_wellName, c_m_date, c_m_value, elementID) {
             //X-axis displays the date
             //X-axis displays the date
             labels: c_m_date,
             labels: c_m_date,
             datasets: [{
             datasets: [{
-                //Label above the chart to illustrate which color has which purpose
-                label: c_wellName,
-                //Data value
-                data: c_m_value,
-                //Detemine line's color
-                borderColor: '#3e95cd'
-            },
-            {
-                label: "警戒值",
-                data: warning,
-                borderColor: "#FF0000",
-                pointRadius: 0
-            }
+                    //Label above the chart to illustrate which color has which purpose
+                    label: c_wellName,
+                    //Data value
+                    data: c_m_value,
+                    //Detemine line's color
+                    borderColor: '#3e95cd'
+                },
+                {
+                    label: "警戒值",
+                    data: warning,
+                    borderColor: "#FF0000",
+                    pointRadius: 0
+                }
             ]
             ]
         },
         },
         options: {
         options: {
@@ -912,15 +909,15 @@ function init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_val
         data: {
         data: {
             labels: c_m_date,
             labels: c_m_date,
             datasets: [{
             datasets: [{
-                label: c_wellName,
-                data: c_m_value,
-                borderColor: '#3e95cd'
-            },
-            {
-                label: c2_wellName,
-                data: c2_m_value,
-                borderColor: '#63fff5'
-            }
+                    label: c_wellName,
+                    data: c_m_value,
+                    borderColor: '#3e95cd'
+                },
+                {
+                    label: c2_wellName,
+                    data: c2_m_value,
+                    borderColor: '#63fff5'
+                }
             ]
             ]
         },
         },
         options: {
         options: {
@@ -1081,41 +1078,41 @@ function init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_well
         data: {
         data: {
             labels: c_m_date,
             labels: c_m_date,
             datasets: [{
             datasets: [{
-                label: c_wellName,
-                data: c_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: c2_wellName,
-                data: c2_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: c3_wellName,
-                data: c3_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: c4_wellName,
-                data: c4_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: c5_wellName,
-                data: c5_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: c6_wellName,
-                data: c6_m_value,
-                borderColor: randomColor()
-            },
-            {
-                label: "警戒值",
-                data: warning,
-                borderColor: "#FF0000",
-                pointRadius: 0
-            }
+                    label: c_wellName,
+                    data: c_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: c2_wellName,
+                    data: c2_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: c3_wellName,
+                    data: c3_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: c4_wellName,
+                    data: c4_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: c5_wellName,
+                    data: c5_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: c6_wellName,
+                    data: c6_m_value,
+                    borderColor: randomColor()
+                },
+                {
+                    label: "警戒值",
+                    data: warning,
+                    borderColor: "#FF0000",
+                    pointRadius: 0
+                }
             ]
             ]
         },
         },
         options: {
         options: {
@@ -1158,68 +1155,6 @@ function init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_well
     }
     }
 
 
 }
 }
-/*
-function initCompare(m_date, chart_data, index, label) {
-    var ctx = document.getElementById("myChart").getContext("2d");
-    var value = -7.9;
-    let warning = [];
-    var phase = document.getElementById("phase").value;
-
-
-    yLabel = "水位高程GL(m)";
-    xLabel = "日期";
-
-    for (i = 0; i < m_date.length; i++) {
-        warning.push(value);
-    }
-
-    if (window.chart != undefined) {
-        window.chart.destroy();
-    }
-    window.chart = new Chart(ctx, {
-        type: 'line',
-        data: {
-            labels: m_date
-        },
-        options: {
-            responsive: true,
-            maintainAspectRatio: false,
-            scales: {
-                y: {
-                    title: {
-                        display: true,
-                        text: yLabel
-                    }
-                },
-                x: {
-                    title: {
-                        display: true,
-                        text: xLabel
-                    }
-                }
-            }
-        }
-    });
-
-    for (i = 1; i < index + 1; i++) {
-        window.chart.data.datasets.push({
-            label: label[i].replaceAll("_", "-"),
-            data: chart_data[i],
-            borderColor: randomColorBlue()
-        });
-    }
-    /*
-        if(label[1].includes("ELP") && phase != 2 && phase != 7){
-            window.chart.data.datasets.push({
-                label: "警戒值",
-                data: warning,
-                borderColor: "#FF0000",
-                pointRadius: 0
-            });		
-        }
-    */
-//window.chart.update();
-//}
 
 
 //Chart has multiple lines that need different color
 //Chart has multiple lines that need different color
 function randomColor() {
 function randomColor() {

+ 80 - 0
script/php/get_abnormal.php

@@ -0,0 +1,80 @@
+<?php
+include("./connect_sql.php");
+$json = file_get_contents('../../r03/display_info.json');
+$display_info = json_decode($json, true);
+$type = "";
+$normal_count = 0;
+$abnormal_count = 0;
+$ajax = [];
+$wellTBA = [];
+
+if (isset($_GET["type"])) {
+    $type = $_GET["type"];
+}
+$key = array_search($type, array_column($display_info, 'type'));
+switch ($type) {
+    case "SIS":
+    case "SID":
+        $sql = "SELECT [EquipmentID] FROM [BIMMonitor].[dbo].[{$type}_Data]
+        WHERE [WarningValue] <> 'NULL' AND [{$type}_Data].[Date] = (SELECT TOP 1 [{$type}_Data].[Date] FROM [{$type}_Data] GROUP BY [Date]  ORDER BY [Date] desc)
+        AND (convert(float,[TotalDisplacement]) > convert(float,(SELECT TOP 1 RIGHT([WarningValue], len([WarningValue])-1) FROM [{$type}_Data] WHERE [WarningValue] <> 'NULL'))
+        OR convert(float,[TotalDisplacement]) < -convert(float,(SELECT TOP 1 RIGHT([WarningValue], len([WarningValue])-1) FROM [{$type}_Data] WHERE [WarningValue] <> 'NULL')))
+        GROUP BY [EquipmentID]";
+        break;
+
+    case "TI":
+        $sql = "SELECT [EquipmentID]
+        FROM [BIMMonitor].[dbo].[TI_Data]
+        WHERE [TI_Data].[Date] = (SELECT TOP 1 [TI_Data].[Date] FROM [TI_Data] GROUP BY [Date]  ORDER BY [Date] desc)
+        AND (convert(float,[TotalTilt]) > 264 OR convert(float,[TotalTilt]) < -264 ) GROUP BY [EquipmentID]";
+        break;
+
+    case "SB":
+        $sql = "SELECT [SB_Data].[EquipmentID]
+        FROM [SB_Data] JOIN [SB_Warning] ON  [SB_Data].[EquipmentID] = [SB_Warning].[EquipmentID] 
+        WHERE [SB_Data].[Date] = (SELECT TOP 1 [SB_Data].[Date] FROM [SB_Data] GROUP BY [Date]  ORDER BY [Date] desc)
+        AND (convert(float,[TotalSettlement]) > convert(float,(SELECT TOP 1 RIGHT([WarningValue], len([WarningValue])-1) FROM [SB_Warning]))
+        OR convert(float,[TotalSettlement]) < -convert(float,(SELECT TOP 1 RIGHT([WarningValue], len([WarningValue])-1) FROM [SB_Warning])))";
+        break;
+
+    case "SM":
+        $sql = "SELECT [EquipmentID] FROM [SM_Data]
+        WHERE [SM_Data].[Date] = (SELECT TOP 1 [SM_Data].[Date] FROM [SM_Data] GROUP BY [Date]  ORDER BY [Date] desc)
+        AND (convert(float,[TotalSettlement]) > 30 OR convert(float,[TotalSettlement]) < -30 ) GROUP BY [EquipmentID]";
+        break;
+    case "SP":
+        $sql = "SELECT [EquipmentID] FROM [SP_Data]
+        WHERE [SP_Data].[Date] = (SELECT TOP 1 [SP_Data].[Date] FROM [SP_Data] GROUP BY [Date]  ORDER BY [Date] desc)
+        AND (convert(float,[WaterPressure]) > (SELECT TOP 1 [HighWarningValue] FROM [SP_Warning]) OR convert(float,[WaterPressure]) < (SELECT TOP 1 [LowWarningValue] FROM [SP_Warning]) )
+        AND [WaterPressure] <> '---' GROUP BY [EquipmentID];";
+        break;
+}
+
+$fetchResult = sqlsrv_query($conn, $sql);
+while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_NUMERIC)) {
+    array_push($wellTBA,$row);
+    $abnormal_count++;
+}
+$all_count = 0;
+$sql = "SELECT [EquipmentID] FROM [BIMMonitor].[dbo].[{$type}_Data] GROUP BY [EquipmentID];";
+$fetchResult = sqlsrv_query($conn, $sql);
+while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_NUMERIC)) {
+    $all_count++;
+}
+$normal_count = $all_count - $abnormal_count;
+if ($fetchResult === false) {
+    if (($errors = sqlsrv_errors()) != null) {
+        foreach ($errors as $error) {
+            echo "SQLSTATE: " . $error['SQLSTATE'] . "<br />";
+            echo "code: " . $error['code'] . "<br />";
+            echo "message: " . $error['message'] . "<br />";
+            echo ($sql . "<br />");
+            var_dump($row);
+        }
+    }
+}
+
+$ajax['wellTBA'] = $wellTBA;
+$ajax['normal_count'] = $normal_count;
+$ajax['abnormal_count'] = $abnormal_count;
+echo json_encode($ajax);

+ 5 - 0
script/php/get_monitor_chart.php

@@ -65,6 +65,11 @@ switch ($type) {
         FROM [SM_Data]
         FROM [SM_Data]
         WHERE [EquipmentID] = '{$monitor}';";
         WHERE [EquipmentID] = '{$monitor}';";
         break;
         break;
+    case "SP":
+        $sql = "SELECT [SP_Data].[Date], [WaterPressure], [HighWarningValue], [LowWarningValue],[HighActionValue],[LowActionValue]
+        FROM [SP_Data] JOIN [SP_Warning] ON  [SP_Data].[EquipmentID] = [SP_Warning].[EquipmentID]
+        WHERE [SP_Data].[EquipmentID] = '{$monitor}';";
+        break;
 }
 }
 
 
 $fetchResult = sqlsrv_query($conn, $sql);
 $fetchResult = sqlsrv_query($conn, $sql);