Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // init
- $employee_user = $_SESSION['employee_user'];
- $total_restoration_time = $control->fetch_restoration_time_of_all_closed_tt($client_name, $employee_user);
- // controller
- public function fetch_restoration_time_of_all_closed_tt($client_name, $client_username)
- {
- return $this->moduller()->fetch_restoration_time_of_all_closed_tt($client_name, $client_username);
- }
- // NEW
- public function fetchSingleRowNoc($tableName, $fields = NULL)
- {
- $list = $this->moduller()->fetchSingleRowNoc($tableName, $fields);
- return $list;
- }
- // model
- public function fetch_restoration_time_of_all_closed_tt($client_name, $client_username)
- {
- $conn = $this->Fconnection3();
- $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'";
- $query = mysqli_query($conn, $sql);
- $total_time = 0;
- $total_no_pre_check_list_time = 0;
- $total_counter = 0;
- $no_pre_check_list_counter = 0;
- while ($row = mysqli_fetch_assoc($query)) {
- $fault_restoration_time = strtotime($row["tt_close_time"]) - strtotime($row["fault_date_time"]);
- $link_type = $this->fetchSingleRowNoc('tbl_service_type_layer_divition', array('service_type' => $row["link_type"]));
- $link_service_type = $link_type["toc_layer"];
- $fault_layer_1 = $row["client_fault_type1"];
- $fault_layer_2 = $row["client_fault_type2"];
- if ($link_service_type == "Data" && $fault_layer_1 == 3 && $fault_layer_2 == 2) {
- 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'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- } elseif ($link_service_type == "FTTx" && $fault_layer_1 == 3 && $fault_layer_2 == 2) {
- 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'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- } elseif ($link_service_type == "Data" && ($fault_layer_1 == 4 || $fault_layer_1 == 2)) {
- 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'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- } elseif ($link_service_type == "FTTx" && ($fault_layer_1 == 4 || $fault_layer_1 == 2)) {
- 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'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- } elseif (($link_service_type == "Data" || $link_service_type == "FTTx") && $fault_layer_1 == 5) {
- if (empty($row['port_status'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- } elseif ($link_service_type == "Core" && ($fault_layer_1 == 3 || $fault_layer_1 == 5)) {
- if (empty($row['down_time']) || empty($row['port_status'])) {
- $total_no_pre_check_list_time += $fault_restoration_time;
- $no_pre_check_list_counter++;
- }
- }
- $total_time += $fault_restoration_time;
- $total_counter++;
- }
- $total_pre_check_list_time = $total_time - $total_no_pre_check_list_time;
- $pre_check_list_counter = $total_counter - $no_pre_check_list_counter;
- $ret = array(
- "total_pre_check_list_time" => $total_pre_check_list_time,
- "pre_check_list_counter" => $pre_check_list_counter,
- "total_no_pre_check_list_time" => $total_no_pre_check_list_time,
- "no_pre_check_list_counter" => $no_pre_check_list_counter,
- );
- return $ret;
- }
- // NEW
- private function Fconnection3()
- {
- $conn1 = mysqli_connect("192.168.40.95", "clienta", "client@f!ber21", "nocdbN") or die("...Mysql connection error.");
- return $conn1;
- }
- private function selectNoc($table, $where = NULL, $conn = NULL, $order = NULL)
- {
- if (!isset($conn)) {
- $conn = $this->Fconnection3();
- }
- $sql = "SELECT * FROM {$table}";
- // check fields if exists
- if (isset($where)) {
- $sql .= " WHERE ";
- $count = count($where);
- foreach ($where as $field => $value) {
- $sql .= "{$field}='{$value}' ";
- if ($count > 1) {
- $sql .= " AND ";
- }
- $count--;
- }
- }
- if (isset($order)) {
- $sql .= " ORDER BY {$order} ASC";
- }
- $query = mysqli_query($conn, $sql);
- return $query;
- }
- public function fetchSingleRowNoc($table, $where = NULL)
- {
- $query = $this->selectNoc($table, $where);
- $results = mysqli_fetch_assoc($query);
- return $results;
- }
- ?>
- <!-- css -->
- <style>
- .chart-container {
- width: 70%;
- height: auto;
- margin: 0 auto;
- position: relative;
- }
- </style>
- <!-- html -->
- <!-- chart call -->
- <div class="col-md-6">
- <div class="callout callout-danger" style="background-color: white !important;">
- <div class="chart-container">
- <canvas id="mttrChart"></canvas>
- </div>
- </div>
- </div>
- <!-- chart config -->
- <script src="https://cdn.jsdelivr.net/npm/chart.js@4.0.1/dist/chart.umd.min.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2"></script>
- <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
- <script>
- const ctx = document.getElementById('mttrChart');
- const total_pre_check_list_time = <?= $total_restoration_time["total_pre_check_list_time"] ?>;
- const pre_check_list_counter = <?= $total_restoration_time["pre_check_list_counter"] ?>;
- const total_no_pre_check_list_time = <?= $total_restoration_time["total_no_pre_check_list_time"] ?>;
- const no_pre_check_list_counter = <?= $total_restoration_time["no_pre_check_list_counter"] ?>;
- const data = {
- labels: ['MTTR (in Hour)'],
- datasets: [{
- label: 'Complaints Registered with Pre-Check Info',
- data: [parseFloat((total_pre_check_list_time / pre_check_list_counter) / 3600).toFixed(2)],
- borderWidth: 1,
- backgroundColor: 'rgba(43, 173, 229, 0.9)',
- },
- {
- label: 'Complaints Registered without Pre-Check Info',
- data: [parseFloat((total_no_pre_check_list_time / no_pre_check_list_counter) / 3600).toFixed(2)],
- borderWidth: 1,
- backgroundColor: 'rgba(229, 43, 80, 0.9)',
- },
- ],
- };
- const config = {
- type: 'bar',
- data: data,
- plugins: [ChartDataLabels],
- options: {
- indexAxis: 'y',
- elements: {
- bar: {
- borderWidth: 8,
- },
- },
- responsive: true,
- plugins: {
- legend: {
- position: 'bottom',
- },
- title: {
- display: true,
- text: 'Fault Restoration Time Comparison',
- font: {
- size: '18em',
- weight: 'bold'
- },
- },
- datalabels: {
- color: 'rgba(0, 0, 0, 0.9)',
- },
- tooltip: {
- xAlign: 'left',
- yAlign: 'top',
- },
- },
- },
- };
- new Chart(ctx, config);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement