diff --git a/CHANGELOG.md b/CHANGELOG.md index c8e7be5..f36d2bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.1.0 - 2024-09-27 +### Changed +- aggregate very old server versions to minor version +- display only top 5 in charts + ## 1.0.0 - 2024-09-20 ### Added - NC29 compatibility 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 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( 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..6e21be5 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 } /** @@ -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'); } @@ -205,35 +208,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 +223,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 @@ -280,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 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 @@


+
+ +