Explorar el Código

新增所有表格格式

manto07m hace 3 años
padre
commit
907dd12b03
Se han modificado 3 ficheros con 129 adiciones y 45 borrados
  1. 16 2
      R03/display_info.json
  2. 66 38
      script/js/r03.js
  3. 47 5
      script/php/get_monitor_table.php

+ 16 - 2
R03/display_info.json

@@ -3,54 +3,63 @@
   "type": "BS",
   "display": "Settlement",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "EP",
   "display": "WaterValue",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "t\/m²"
  },
  {
   "type": "ETI",
   "display": "Tilt",
   "haveDepth": false,
-  "unit": "秒"
+  "haveDirection": false,
+  "unit": "s"
  },
  {
   "type": "EXM",
   "display": "TotalExtensionValue",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "OW",
   "display": "WaterLevelElevation",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "m"
  },
  {
   "type": "RB",
   "display": "RebarStress",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "kg\/cm²"
  },
  {
   "type": "SB",
   "display": "TotalSettlement",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "SID",
   "display": "TotalDisplacement",
   "haveDepth": true,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "SIS",
   "display": "TotalDisplacement",
   "haveDepth": true,
+  "haveDirection": false,
   "unit": "mm",
   "warning1": true,
   "warning2": true,
@@ -61,30 +70,35 @@
   "type": "SM",
   "display": "TotalSettlement",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "SP",
   "display": "WaterLevelElevation",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "m"
  },
  {
   "type": "SS",
   "display": "Settlement",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "mm"
  },
  {
   "type": "TI",
   "display": "TotalTilt",
   "haveDepth": false,
-  "unit": "秒"
+  "haveDirection": true,
+  "unit": "s"
  },
  {
   "type": "VG",
   "display": "AverageForce",
   "haveDepth": false,
+  "haveDirection": false,
   "unit": "t"
  }
 ]

+ 66 - 38
script/js/r03.js

@@ -55,33 +55,7 @@ $(document).ready(function () {
         }
     });
 
-    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": ": 降冪排列"
-            }
-        },
-    });
+
 
 })
 
@@ -200,17 +174,11 @@ function showWell(str, changeCamera) {
     isCompare = false;
     $("#compareCheck").checked = false;
 
-    if (str == "") {
-        dataTable.clear();
-        dataTable.draw();
-        $("#tableName").text("模型無此監測儀器");
-        return;
-    }
     strLocal = str;
 
     $("#monitorSelect2").innerHTML = strLocal;
 
-    getTable(str, changeCamera);
+    getTable(str);
     displayChart(str, "myChart");
     if (isLoad) {
         myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
@@ -231,17 +199,77 @@ function getTable(monitor) {
             monitor: monitor
         }
     }).success(function (result) {
+
         let table = result.table;
         let unit = result.unit;
-        dataTable.clear();
-        dataTable.draw();
+        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();
         });
-        
+
         /*$("#tableName").innerHTML = monitor + "資料表";
         saveCheckCompare = monitor + "資料表";
         displayChart(monitor, "myChart");
@@ -249,7 +277,7 @@ function getTable(monitor) {
 
         document.getElementById("dataTable").innerHTML = data;*/
 
-        console.log(dataTable);
+        console.log(result);
 
     }).error(function (error) {
         console.log(error);

+ 47 - 5
script/php/get_monitor_table.php

@@ -7,20 +7,60 @@ $type = "";
 if (isset($_GET["monitor"])) {
     $monitor = $_GET["monitor"];
     $type = explode('-', $monitor)[0];
-    if($type == "SIS" || $type == "SID"){
+    if ($type == "SIS" || $type == "SID") {
         $monitor .= "A";
     }
 }
-
+$table = [];
+$unit = "";
+$haveDepth = false;
+$haveDirection = false;
 $key = array_search($type, array_column($display_info, 'type'));
 if ($key !== false) {
     $display = $display_info[$key]["display"];
     $unit = $display_info[$key]["unit"];
-    //echo($display);
-    $sql = "SELECT [Date],[{$display}] FROM [{$type}_Data] WHERE [EquipmentID] = '{$monitor}';";
+    $haveDepth = $display_info[$key]["haveDepth"];
+    $haveDirection = $display_info[$key]["haveDirection"];
+    if ($haveDepth) {
+        $display .= '],[Depth';
+        $sql = "  SELECT [Date],count(DISTINCT [Depth])
+        FROM [BIMMonitor].[dbo].[{$type}_Data] WHERE [EquipmentID] = '{$monitor}' GROUP BY [Date]";
+
+
+        $stmt = sqlsrv_query($conn, $sql);
+        $fetchResult = sqlsrv_query($conn, $sql);
+        $depth = "";
+        while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_NUMERIC)) {
+            $depthCount = $row[1];
+        }
+        for ($i = 1; $i < $depthCount; $i++) {
+            $depth = $depth . ",[" . $i * 0.5 . "]";
+        }
+        $sql = "  SELECT *
+        FROM (
+            SELECT [Date],[TotalDisplacement],[Depth]
+          FROM [BIMMonitor].[dbo].[{$type}_Data] WHERE [EquipmentID] = '{$monitor}'
+        ) o
+        PIVOT (
+            MAX([TotalDisplacement])
+            FOR [Depth] IN ([TOP] ${depth})
+        ) n;";
+    } else if ($haveDirection) {
+        $sql = "  SELECT *
+        FROM (
+            SELECT [Date],[Direction],[TotalTilt]
+          FROM [BIMMonitor].[dbo].[{$type}_Data] WHERE [EquipmentID] like '%{$monitor}%'
+        ) o
+        PIVOT (
+            MAX([TotalTilt])
+            FOR [Direction] IN ([1-3], [2-4])
+        ) n;";
+    } else {
+        $sql = "SELECT [Date],[{$display}] FROM [{$type}_Data] WHERE [EquipmentID] = '{$monitor}';";
+    }
+
     $stmt = sqlsrv_query($conn, $sql);
     $fetchResult = sqlsrv_query($conn, $sql);
-    $table = [];
     while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_NUMERIC)) {
         array_push($table, $row);
     }
@@ -39,4 +79,6 @@ if ($key !== false) {
 
 $ajax["table"] = $table;
 $ajax["unit"] = $unit;
+$ajax["haveDepth"] = $haveDepth;
+$ajax["haveDirection"] = $haveDirection;
 echo (json_encode($ajax));