From 9ca5c9bca40fa7e962b932364228731a6b9714a8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 4 Jul 2022 18:25:06 +0200 Subject: [js_chart] Update to Chart.js 3.0.8 --- modules-available/statistics/pages/list.inc.php | 2 + modules-available/statistics/pages/summary.inc.php | 103 ++++++++++----------- 2 files changed, 50 insertions(+), 55 deletions(-) (limited to 'modules-available/statistics/pages') diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index 4eac2ee5..0e405bf5 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -65,6 +65,7 @@ class SubPage $shutdownAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.reboot'); $wolAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.wol'); $execAllowedLocations = User::getAllowedLocations('.rebootcontrol.action.exec'); + $benchmarkAllowedLocations = User::getAllowedLocations('.vmstore.benchmark'); // Only make client clickable if user is allowed to view details page $detailsAllowedLocations = User::getAllowedLocations("machine.view-details"); $location = self::buildLocationLookup(); @@ -139,6 +140,7 @@ class SubPage 'canDelete' => !empty($deleteAllowedLocations), 'canWol' => !empty($wolAllowedLocations), 'canExec' => !empty($execAllowedLocations), + 'canBenchmark' => !empty($benchmarkAllowedLocations), ); Render::addTemplate('clientlist', $data); } diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index 1adad7bd..1fa3adf2 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -64,8 +64,8 @@ class SubPage $cutoff = time() - 2 * 86400; $res = Database::simpleQuery("SELECT dateline, data FROM statistic WHERE typeid = '~stats' AND dateline > $cutoff ORDER BY dateline ASC"); $labels = array(); - $points1 = array('data' => array(), 'label' => 'Online', 'fillColor' => '#efe', 'strokeColor' => '#aea', 'pointColor' => '#7e7', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#7e7'); - $points2 = array('data' => array(), 'label' => 'In use', 'fillColor' => '#fee', 'strokeColor' => '#eaa', 'pointColor' => '#e77', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#e77'); + $points1 = array('data' => array(), 'label' => 'Online', 'borderColor' => '#8eb'); + $points2 = array('data' => array(), 'label' => 'In use', 'borderColor' => '#fa9'); $sum = 0; foreach ($res as $row) { $x = explode('#', $row['data']); @@ -100,26 +100,39 @@ class SubPage $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery('SELECT systemmodel, Round(AVG(realcores)) AS cores, Count(*) AS `count` FROM machine m' . " $join WHERE $where GROUP BY systemmodel ORDER BY `count` DESC, systemmodel ASC", $args); - $lines = array(); - $json = array(); + $lines = []; + $json = []; $id = 0; foreach ($res as $row) { if (empty($row['systemmodel'])) { continue; } settype($row['count'], 'integer'); - $row['id'] = 'systemid' . $id; $row['urlsystemmodel'] = urlencode($row['systemmodel']); + $row['idx'] = count($lines); $lines[] = $row; - $json[] = array( + $json[] = [ 'color' => self::$STATS_COLORS[$id % count(self::$STATS_COLORS)], - 'label' => 'systemid' . $id, 'value' => $row['count'], - ); + ]; ++$id; } self::capChart($json, $lines, 0.92); - Render::addTemplate('cpumodels', array('rows' => $lines, 'json' => json_encode($json))); + Render::addTemplate('cpumodels', ['rows' => $lines, 'json' => json_encode($json)]); + } + + private static function alignBySteps(int $value, array $steps): int + { + for ($i = 1; $i < count($steps); ++$i) { + if ($steps[$i] < $value) { + continue; + } + if ($steps[$i] - $value >= $value - $steps[$i - 1]) { + --$i; + } + return $steps[$i]; + } + return $value; } /** @@ -130,36 +143,26 @@ class SubPage $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY mbram", $args); - $lines = array(); + $lines = []; foreach ($res as $row) { - $gb = (int)ceil($row['mbram'] / 1024); - for ($i = 1; $i < count(StatisticsFilter::SIZE_RAM); ++$i) { - if (StatisticsFilter::SIZE_RAM[$i] < $gb) { - continue; - } - if (StatisticsFilter::SIZE_RAM[$i] - $gb >= $gb - StatisticsFilter::SIZE_RAM[$i - 1]) { - --$i; - } - $gb = StatisticsFilter::SIZE_RAM[$i]; - break; - } - if (isset($lines[$gb])) { - $lines[$gb] += $row['count']; - } else { - $lines[$gb] = $row['count']; - } + $gb = self::alignBySteps((int)ceil($row['mbram'] / 1024), StatisticsFilter::SIZE_RAM); + $lines[$gb] = ($lines[$gb] ?? 0) + $row['count']; } asort($lines); - $data = array('rows' => array()); - $json = array(); + $data = ['rows' => []]; + $json = []; $id = 0; foreach (array_reverse($lines, true) as $k => $v) { - $data['rows'][] = array('gb' => $k, 'count' => $v, 'class' => StatisticsStyling::ramColorClass($k * 1024)); - $json[] = array( + $data['rows'][] = [ + 'idx' => count($data['rows']), + 'gb' => $k, + 'count' => $v, + 'class' => StatisticsStyling::ramColorClass($k * 1024), + ]; + $json[] = [ 'color' => self::$STATS_COLORS[$id % count(self::$STATS_COLORS)], - 'label' => (string)$k, 'value' => $v, - ); + ]; ++$id; } self::capChart($json, $data['rows'], 0.92); @@ -173,16 +176,16 @@ class SubPage private static function showKvmState($filterSet) { $filterSet->makeFragments($where, $join, $args); - $colors = array('UNKNOWN' => '#666', 'UNSUPPORTED' => '#ea5', 'DISABLED' => '#e55', 'ENABLED' => '#6d6'); + $colors = ['UNKNOWN' => '#666', 'UNSUPPORTED' => '#ea5', 'DISABLED' => '#e55', 'ENABLED' => '#6d6']; $res = Database::simpleQuery("SELECT kvmstate, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args); - $lines = array(); - $json = array(); + $lines = []; + $json = []; foreach ($res as $row) { + $row['idx'] = count($lines); $lines[] = $row; $json[] = array( - 'color' => isset($colors[$row['kvmstate']]) ? $colors[$row['kvmstate']] : '#000', - 'label' => $row['kvmstate'], + 'color' => $colors[$row['kvmstate']] ?? '#000', 'value' => $row['count'], ); } @@ -200,29 +203,20 @@ class SubPage $total = 0; foreach ($res as $row) { $total += $row['count']; - $gb = (int)ceil($row['id44mb'] / 1024); - for ($i = 1; $i < count(StatisticsFilter::SIZE_ID44); ++$i) { - if (StatisticsFilter::SIZE_ID44[$i] < $gb) { - continue; - } - if (StatisticsFilter::SIZE_ID44[$i] - $gb >= $gb - StatisticsFilter::SIZE_ID44[$i - 1]) { - --$i; - } - $gb = StatisticsFilter::SIZE_ID44[$i]; - break; - } - if (isset($lines[$gb])) { - $lines[$gb] += $row['count']; - } else { - $lines[$gb] = $row['count']; - } + $gb = self::alignBySteps((int)ceil($row['id44mb'] / 1024), StatisticsFilter::SIZE_ID44); + $lines[$gb] = ($lines[$gb] ?? 0) + $row['count']; } asort($lines); $data = array('rows' => array()); $json = array(); $id = 0; foreach (array_reverse($lines, true) as $k => $v) { - $data['rows'][] = array('gb' => $k, 'count' => $v, 'class' => StatisticsStyling::hddColorClass($k)); + $data['rows'][] = [ + 'idx' => count($data['rows']), + 'gb' => $k, + 'count' => $v, + 'class' => StatisticsStyling::hddColorClass($k), + ]; if ($k === 0) { $color = '#e55'; } else { @@ -230,7 +224,6 @@ class SubPage } $json[] = array( 'color' => $color, - 'label' => (string)$k, 'value' => $v, ); } -- cgit v1.2.3-55-g7522