From 38c5930107b289594c5434553da61c2c82034406 Mon Sep 17 00:00:00 2001 From: Rello Date: Fri, 27 Sep 2024 17:01:24 +0200 Subject: [PATCH 1/4] Just show top 5 in charts Signed-off-by: Rello --- CHANGELOG.md | 3 +++ js/script.js | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8e7be5..56efb78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Changed +- Just show top 5 in charts + ## 1.0.0 - 2024-09-20 ### Added - NC29 compatibility diff --git a/js/script.js b/js/script.js index 857a29a..ff0e88d 100644 --- a/js/script.js +++ b/js/script.js @@ -112,19 +112,29 @@ let colors = ["#aec7e8", "#ffbb78", "#98df8a", "#ff9896", "#c5b0d5", "#c49c94", "#f7b6d2", "#c7c7c7", "#dbdb8d", "#9edae5"]; let counter = 0; - for (let key in rawdata) { - let colorIndex = counter - (Math.floor(counter / colors.length) * colors.length) - var span = document.createElement('span'); - span.textContent = key + ': ' + rawdata[key]; - details.appendChild(span); + // Convert rawdata to an array of [key, value] pairs and sort by value in descending order + let sortedData = Object.entries(rawdata).sort((a, b) => b[1] - a[1]); - var br = document.createElement('br'); - details.appendChild(br); + // Extract top 5 values and aggregate the rest + let topData = sortedData.slice(0, 5); + let othersData = sortedData.slice(5); + // Calculate the sum of the remaining values + let othersSum = othersData.reduce((sum, item) => sum + item[1], 0); + + // Add top 5 values to chart data + topData.forEach(([key, value]) => { chartLabels.push(key); - data.push(rawdata[key]); - backgroundColor.push(colors[colorIndex]); + data.push(value); + backgroundColor.push(colors[counter % colors.length]); counter++; + }); + + // Add "Others" category if there are remaining values + if (othersSum > 0) { + chartLabels.push('Others'); + data.push(othersSum); + backgroundColor.push(colors[counter % colors.length]); } let chartData = { @@ -147,6 +157,16 @@ } } }); + + // List all values in the details section + Object.entries(rawdata).forEach(([key, value]) => { + var span = document.createElement('span'); + span.textContent = key + ': ' + value; + details.appendChild(span); + + var br = document.createElement('br'); + details.appendChild(br); + }); }; $.get( From e7ac20bb8de8d279d46e2cb9788f7b27f73ba6be Mon Sep 17 00:00:00 2001 From: Rello Date: Fri, 27 Sep 2024 17:02:11 +0200 Subject: [PATCH 2/4] aggregate very old server versions to minor version Signed-off-by: Rello --- CHANGELOG.md | 4 +- js/settings/admin.js | 3 +- lib/BackgroundJobs/ComputeStatistics.php | 69 +++++++++++++++--------- lib/Controller/SettingsController.php | 7 +-- lib/Service/SettingsService.php | 7 +-- lib/Settings/Admin.php | 4 +- templates/settings/admin.php | 3 ++ 7 files changed, 62 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56efb78..f36d2bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Changelog +## 1.1.0 - 2024-09-27 ### Changed -- Just show top 5 in charts +- aggregate very old server versions to minor version +- display only top 5 in charts ## 1.0.0 - 2024-09-20 ### Added diff --git a/js/settings/admin.js b/js/settings/admin.js index e5e098c..8ee56d1 100644 --- a/js/settings/admin.js +++ b/js/settings/admin.js @@ -9,7 +9,8 @@ document.addEventListener('DOMContentLoaded', function () { document.getElementById('surveyYearsSave').addEventListener('click', surveyYearsSave); function surveyYearsSave() { - let params = 'time=' + document.getElementById('deletion_time').value; + let params = 'deletion_time=' + document.getElementById('deletion_time').value + + '&version_aggregation=' + document.getElementById('version_aggregation').value; let xhr = new XMLHttpRequest(); xhr.open('POST', OC.generateUrl('apps/survey_server/settings', true), true); xhr.setRequestHeader('requesttoken', OC.requestToken); diff --git a/lib/BackgroundJobs/ComputeStatistics.php b/lib/BackgroundJobs/ComputeStatistics.php index a0bb01b..fe8db0f 100644 --- a/lib/BackgroundJobs/ComputeStatistics.php +++ b/lib/BackgroundJobs/ComputeStatistics.php @@ -44,7 +44,7 @@ public function __construct( $this->connection = $connection ? $connection : \OC::$server->getDatabaseConnection(); $this->config = $config = $config ? $config : \OC::$server->getConfig(); $this->EvaluateStatistics = $EvaluateStatistics ? $EvaluateStatistics : new EvaluateStatistics(); - $this->setInterval(60 * 60); //todo + $this->setInterval(60); //todo } /** @@ -205,35 +205,12 @@ private function getNumericalEvaluatedStatistics($category, $key) { } private function clearValue($category, $key, $value): string { - if (strpos($key, 'memcache.') === 0) { + if ($category === 'server' && strpos($key, 'memcache.') === 0) { return $value !== '' ? trim($value, '\\') : 'none'; } if ($key === 'version') { - $version = explode('.', $value); - $majorMinorVersion = $version[0] . '.' . (int)$version[1]; - - if ($category === 'server') { - return $majorMinorVersion . '.' . $version[2]; - } - - if ($category === 'database') { - switch ($version[0]) { - case '2': - case '3': - return 'SQLite ' . $majorMinorVersion; - case '5': - case '6': - return 'MySQL ' . $majorMinorVersion; - case '10': - case '11': - return 'MariaDB ' . $majorMinorVersion; - default: - return $majorMinorVersion; - } - } - - return $majorMinorVersion; + return $this->clearVersionValue($category, $value); } if ($key === 'max_execution_time') { @@ -243,6 +220,46 @@ private function clearValue($category, $key, $value): string { return (string)$value; } + private function clearVersionValue($category, $value): string { + $versionAggregation = $this->config->getValueString('survey_server', 'version_aggregation', '25'); + + $version = explode('.', $value); + $majorMinorVersion = $version[0] . '.' . (int)$version[1]; + + if ($category === 'server') { + if ($version[0] < $versionAggregation) { + // for old versions, we aggregate to minor only + $version[2] = 'x'; + } + return $majorMinorVersion . '.' . $version[2]; + } + + if ($category === 'database') { + return $this->clearDatabaseVersion($version[0], $majorMinorVersion); + } + + return $majorMinorVersion; + } + + private function clearDatabaseVersion($majorVersion, $majorMinorVersion): string { + switch ($majorVersion) { + case '2': + case '3': + return 'SQLite ' . $majorMinorVersion; + case '5': + case '6': + case '7': + case '8': + case '9': + return 'MySQL ' . $majorMinorVersion; + case '10': + case '11': + return 'MariaDB ' . $majorMinorVersion; + default: + return $majorMinorVersion; + } + } + /** * get statistic of enabled apps diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 68b6173..45ce210 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -31,10 +31,11 @@ public function __construct( * update settings * * @NoAdminRequired - * @param int $time + * @param int $deletion_time + * @param int $version_aggregation * @return DataResponse */ - public function update(int $time): DataResponse { - return new DataResponse($this->SettingsService->update($time)); + public function update(int $deletion_time, int $version_aggregation): DataResponse { + return new DataResponse($this->SettingsService->update($deletion_time, $version_aggregation)); } } \ No newline at end of file diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index ce1f0d8..94b6de4 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -19,8 +19,9 @@ public function __construct(IAppConfig $config) { $this->config = $config; } - public function update(int $time): int { - $this->config->setValueString('survey_server', 'deletion_time', $time); - return $time; + public function update(int $deletion_time, int $version_aggregation): int { + $this->config->setValueString('survey_server', 'deletion_time', $deletion_time); + $this->config->setValueString('survey_server', 'version_aggregation', $version_aggregation); + return $deletion_time; } } \ No newline at end of file diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 2889a58..870b1f8 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -33,7 +33,9 @@ public function getForm() { $parameters = [ - 'deletion_time' => $this->configManager->getValueString('survey_server', 'deletion_time', '99') + 'deletion_time' => $this->configManager->getValueString('survey_server', 'deletion_time', '99'), + 'version_aggregation' => $this->configManager->getValueString('survey_server', 'version_aggregation', '25'), + ]; return new TemplateResponse('survey_server', 'settings/admin', $parameters, ''); } diff --git a/templates/settings/admin.php b/templates/settings/admin.php index 8507168..3e6077a 100644 --- a/templates/settings/admin.php +++ b/templates/settings/admin.php @@ -14,6 +14,9 @@


+
+ +

From 570678958c9d3385de649420b4352d76b180ab47 Mon Sep 17 00:00:00 2001 From: Rello Date: Fri, 27 Sep 2024 17:02:22 +0200 Subject: [PATCH 3/4] 1.1.0 Signed-off-by: Rello --- appinfo/info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 6326751..e566be0 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,11 +6,11 @@ AGPL Bjoern Schiessle Marcel Scherello - 1.0.0 + 1.1.0 SurveyServer other - + OCA\SurveyServer\Settings\AdminSection From 689a261ba0100fb3f17ae2c905d4638ff349bcec Mon Sep 17 00:00:00 2001 From: Rello Date: Mon, 30 Sep 2024 10:33:51 +0200 Subject: [PATCH 4/4] get maximum instances Signed-off-by: Rello --- lib/BackgroundJobs/ComputeStatistics.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/BackgroundJobs/ComputeStatistics.php b/lib/BackgroundJobs/ComputeStatistics.php index fe8db0f..6e21be5 100644 --- a/lib/BackgroundJobs/ComputeStatistics.php +++ b/lib/BackgroundJobs/ComputeStatistics.php @@ -68,6 +68,9 @@ protected function run($argument) { $this->logger->info('computing apps'); $newResult['apps'] = $this->getApps(); + $this->logger->info('computing max instances'); + $newResult['max'] = $this->getInstanceMaxUser(); + $this->config->setValueString('survey_server', 'evaluated_statistics', json_encode($newResult)); $this->logger->info('computing done'); } @@ -297,6 +300,21 @@ private function getApps(): array { return $statistics; } + private function getInstanceMaxUser() { + $query = $this->connection->getQueryBuilder(); + $result = $query->select('source') + ->from($this->table) + ->where($query->expr()->eq('category', $query->createNamedParameter('stats'))) + ->andWhere($query->expr()->eq('key', $query->createNamedParameter('num_users'))) + ->orderBy('value', 'DESC') + ->setMaxResults(5) + ->executeQuery(); + + $top5Ids = $result->fetchAll(); + $result->closeCursor(); + + return $top5Ids; + } /** * @throws Exception