Advertisement
sreejonK19

mttr-chart

May 27th, 2023 (edited)
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.48 KB | Source Code | 0 0
  1. <?php
  2.  
  3. // init
  4. $employee_user = $_SESSION['employee_user'];
  5. $total_restoration_time = $control->fetch_restoration_time_of_all_closed_tt($client_name, $employee_user);
  6.  
  7.  
  8. // controller
  9. public function fetch_restoration_time_of_all_closed_tt($client_name, $client_username)
  10. {
  11.     return $this->moduller()->fetch_restoration_time_of_all_closed_tt($client_name, $client_username);
  12. }
  13.  
  14. // NEW
  15. public function fetchSingleRowNoc($tableName, $fields = NULL)
  16. {
  17.     $list = $this->moduller()->fetchSingleRowNoc($tableName, $fields);
  18.     return $list;
  19. }
  20.  
  21.  
  22. // model
  23. public function fetch_restoration_time_of_all_closed_tt($client_name, $client_username)
  24. {
  25.     $conn = $this->Fconnection3();
  26.  
  27.     $sql = "SELECT * FROM tbl_trouble_input WHERE fault_date_time >= '2023-01-01' AND fault_date_time IS NOT NULL AND tt_close_time IS NOT NULL AND tt_close_time <> '0000-00-00 00:00:00' AND tt_close_time > fault_date_time AND status = 0 AND client_name = '$client_name' AND client_user_name='$client_username'";
  28.  
  29.     $query = mysqli_query($conn, $sql);
  30.  
  31.     $total_time = 0;
  32.     $total_no_pre_check_list_time = 0;
  33.     $total_counter = 0;
  34.     $no_pre_check_list_counter = 0;
  35.     while ($row = mysqli_fetch_assoc($query)) {
  36.         $fault_restoration_time = strtotime($row["tt_close_time"]) - strtotime($row["fault_date_time"]);
  37.  
  38.         $link_type = $this->fetchSingleRowNoc('tbl_service_type_layer_divition', array('service_type' => $row["link_type"]));
  39.         $link_service_type = $link_type["toc_layer"];
  40.         $fault_layer_1 = $row["client_fault_type1"];
  41.         $fault_layer_2 = $row["client_fault_type2"];
  42.  
  43.         if ($link_service_type == "Data" && $fault_layer_1 == 3 && $fault_layer_2 == 2) {
  44.             if (empty($row['down_time']) || empty($row['port_status']) || empty($row['device_power_tx']) || empty($row['device_power_rx']) || empty($row['vlan_id_service_name']) || empty($row['mac_address']) || empty($row['last_mile_device'])) {
  45.                 $total_no_pre_check_list_time += $fault_restoration_time;
  46.                 $no_pre_check_list_counter++;
  47.             }
  48.         } elseif ($link_service_type == "FTTx" && $fault_layer_1 == 3 && $fault_layer_2 == 2) {
  49.             if (empty($row['down_time']) || empty($row['vlan_id_service_name']) || empty($row['mac_address']) || empty($row['ont_onu_status']) || empty($row['ont_onu_sn']) || empty($row['last_mile_device'])) {
  50.                 $total_no_pre_check_list_time += $fault_restoration_time;
  51.                 $no_pre_check_list_counter++;
  52.             }
  53.         } elseif ($link_service_type == "Data" && ($fault_layer_1 == 4 || $fault_layer_1 == 2)) {
  54.             if (empty($row['down_time']) || empty($row['port_status']) || empty($row['device_power_tx']) || empty($row['device_power_rx']) || empty($row['vlan_id_service_name']) || empty($row['utilize_bw']) || empty($row['latency_e2e']) || empty($row['carrier_delay']) || empty($row['last_mile_fiber_length'])) {
  55.                 $total_no_pre_check_list_time += $fault_restoration_time;
  56.                 $no_pre_check_list_counter++;
  57.             }
  58.         } elseif ($link_service_type == "FTTx" && ($fault_layer_1 == 4 || $fault_layer_1 == 2)) {
  59.             if (empty($row['down_time']) || empty($row['vlan_id_service_name']) || empty($row['ont_onu_status']) || empty($row['ont_onu_sn']) || empty($row['last_mile_fiber_length'])) {
  60.                 $total_no_pre_check_list_time += $fault_restoration_time;
  61.                 $no_pre_check_list_counter++;
  62.             }
  63.         } elseif (($link_service_type == "Data" || $link_service_type == "FTTx") && $fault_layer_1 == 5) {
  64.             if (empty($row['port_status'])) {
  65.                 $total_no_pre_check_list_time += $fault_restoration_time;
  66.                 $no_pre_check_list_counter++;
  67.             }
  68.         } elseif ($link_service_type == "Core" && ($fault_layer_1 == 3 || $fault_layer_1 == 5)) {
  69.             if (empty($row['down_time']) || empty($row['port_status'])) {
  70.                 $total_no_pre_check_list_time += $fault_restoration_time;
  71.                 $no_pre_check_list_counter++;
  72.             }
  73.         }
  74.  
  75.         $total_time += $fault_restoration_time;
  76.         $total_counter++;
  77.     }
  78.  
  79.     $total_pre_check_list_time = $total_time - $total_no_pre_check_list_time;
  80.     $pre_check_list_counter = $total_counter - $no_pre_check_list_counter;
  81.  
  82.     $ret = array(
  83.         "total_pre_check_list_time" => $total_pre_check_list_time,
  84.         "pre_check_list_counter" => $pre_check_list_counter,
  85.         "total_no_pre_check_list_time" => $total_no_pre_check_list_time,
  86.         "no_pre_check_list_counter" => $no_pre_check_list_counter,
  87.     );
  88.  
  89.     return $ret;
  90. }
  91.  
  92. // NEW
  93. private function Fconnection3()
  94. {
  95.     $conn1 = mysqli_connect("192.168.40.95", "clienta", "client@f!ber21", "nocdbN") or die("...Mysql connection error.");
  96.     return $conn1;
  97. }
  98.  
  99.  
  100. private function selectNoc($table, $where = NULL, $conn = NULL, $order = NULL)
  101. {
  102.     if (!isset($conn)) {
  103.         $conn = $this->Fconnection3();
  104.     }
  105.  
  106.     $sql = "SELECT * FROM {$table}";
  107.  
  108.     // check fields if exists
  109.     if (isset($where)) {
  110.         $sql .= " WHERE ";
  111.         $count = count($where);
  112.         foreach ($where as $field => $value) {
  113.             $sql .= "{$field}='{$value}' ";
  114.             if ($count > 1) {
  115.                 $sql .= " AND ";
  116.             }
  117.            
  118.             $count--;
  119.         }
  120.     }
  121.  
  122.     if (isset($order)) {
  123.         $sql .= " ORDER BY {$order} ASC";
  124.     }
  125.  
  126.     $query = mysqli_query($conn, $sql);
  127.     return $query;
  128. }
  129.  
  130.  
  131. public function fetchSingleRowNoc($table, $where = NULL)
  132. {
  133.     $query = $this->selectNoc($table, $where);
  134.     $results = mysqli_fetch_assoc($query);
  135.     return $results;
  136. }
  137.  
  138.  
  139. ?>
  140.  
  141. <!-- css -->
  142.  
  143. <style>
  144.  
  145. .chart-container {
  146.     width: 70%;
  147.     height: auto;
  148.     margin: 0 auto;
  149.     position: relative;
  150. }
  151.  
  152. </style>
  153.  
  154. <!-- html -->
  155.  
  156. <!-- chart call -->
  157. <div class="col-md-6">
  158.     <div class="callout callout-danger" style="background-color: white !important;">
  159.         <div class="chart-container">
  160.             <canvas id="mttrChart"></canvas>
  161.         </div>
  162.     </div>
  163. </div>
  164.  
  165.  
  166. <!-- chart config -->
  167. <script src="https://cdn.jsdelivr.net/npm/chart.js@4.0.1/dist/chart.umd.min.js"></script>
  168. <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2"></script>
  169. <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
  170.  
  171.  
  172. <script>
  173.     const ctx = document.getElementById('mttrChart');
  174.  
  175.     const total_pre_check_list_time = <?= $total_restoration_time["total_pre_check_list_time"] ?>;
  176.     const pre_check_list_counter = <?= $total_restoration_time["pre_check_list_counter"] ?>;
  177.     const total_no_pre_check_list_time = <?= $total_restoration_time["total_no_pre_check_list_time"] ?>;
  178.     const no_pre_check_list_counter = <?= $total_restoration_time["no_pre_check_list_counter"] ?>;
  179.  
  180.     const data = {
  181.         labels: ['MTTR (in Hour)'],
  182.         datasets: [{
  183.                 label: 'Complaints Registered with Pre-Check Info',
  184.                 data: [parseFloat((total_pre_check_list_time / pre_check_list_counter) / 3600).toFixed(2)],
  185.                 borderWidth: 1,
  186.                 backgroundColor: 'rgba(43, 173, 229, 0.9)',
  187.             },
  188.             {
  189.                 label: 'Complaints Registered without Pre-Check Info',
  190.                 data: [parseFloat((total_no_pre_check_list_time / no_pre_check_list_counter) / 3600).toFixed(2)],
  191.                 borderWidth: 1,
  192.                 backgroundColor: 'rgba(229, 43, 80, 0.9)',
  193.             },
  194.         ],
  195.     };
  196.  
  197.     const config = {
  198.         type: 'bar',
  199.         data: data,
  200.         plugins: [ChartDataLabels],
  201.         options: {
  202.             indexAxis: 'y',
  203.             elements: {
  204.                 bar: {
  205.                     borderWidth: 8,
  206.                 },
  207.             },
  208.             responsive: true,
  209.             plugins: {
  210.                 legend: {
  211.                     position: 'bottom',
  212.                 },
  213.                 title: {
  214.                     display: true,
  215.                     text: 'Fault Restoration Time Comparison',
  216.                     font: {
  217.                         size: '18em',
  218.                         weight: 'bold'
  219.                     },
  220.                 },
  221.                 datalabels: {
  222.                     color: 'rgba(0, 0, 0, 0.9)',
  223.                 },
  224.                 tooltip: {
  225.                     xAlign: 'left',
  226.                     yAlign: 'top',
  227.                 },
  228.             },
  229.         },
  230.     };
  231.  
  232.     new Chart(ctx, config);
  233. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement