title = __('Groups'); $this->total = $this->calculateTotalGroups(); } /** * Return the total groups. * * @return integer */ public function calculateTotalGroups():int { $total = db_get_num_rows('SELECT * FROM tgrupo;'); return $total; } /** * Return the status groups in heat map. * * @return string */ public function getStatusHeatMap():string { ui_require_css_file('heatmap'); $width = 350; $height = 275; $sql = 'SELECT * FROM tagente a LEFT JOIN tagent_secondary_group g ON g.id_agent = a.id_agente'; $all_agents = db_get_all_rows_sql($sql); if (empty($all_agents)) { return null; } $total_agents = count($all_agents); // Best square. $high = (float) max($width, $height); $low = 0.0; while (abs($high - $low) > 0.000001) { $mid = (($high + $low) / 2.0); $midval = (floor($width / $mid) * floor($height / $mid)); if ($midval >= $total_agents) { $low = $mid; } else { $high = $mid; } } $square_length = min(($width / floor($width / $low)), ($height / floor($height / $low))); // Print starmap. $heatmap = sprintf( '', $width, $height ); $heatmap .= ''; $row = 0; $column = 0; $x = 0; $y = 0; $cont = 1; foreach ($all_agents as $key => $value) { // Colour by status. $status = agents_get_status_from_counts($value); switch ($status) { case 5: // Not init status. $status = 'notinit'; break; case 1: // Critical status. $status = 'critical'; break; case 2: // Warning status. $status = 'warning'; break; case 0: // Normal status. $status = 'normal'; break; case 3: case -1: default: // Unknown status. $status = 'unknown'; break; } $heatmap .= sprintf( '', 'rect_'.$cont, $x, $y, $row, $column, $square_length, $square_length, $status, random_int(1, 10) ); $y += $square_length; $row++; if ((int) ($y + $square_length) > (int) $height) { $y = 0; $x += $square_length; $row = 0; $column++; } if ((int) ($x + $square_length) > (int) $width) { $x = 0; $y += $square_length; $column = 0; $row++; } $cont++; } $heatmap .= ''; $heatmap .= ''; $heatmap .= ''; return html_print_div( [ 'content' => $heatmap, 'style' => 'margin: 0 auto; width: fit-content; min-height: 285px;', ], true ); } }