Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<licence>AGPL</licence>
<author>Bjoern Schiessle</author>
<author>Marcel Scherello</author>
<version>1.0.0</version>
<version>1.1.0</version>
<namespace>SurveyServer</namespace>
<category>other</category>
<dependencies>
<nextcloud min-version="25" max-version="29"/>
<nextcloud min-version="25" max-version="30"/>
</dependencies>
<settings>
<admin-section>OCA\SurveyServer\Settings\AdminSection</admin-section>
Expand Down
38 changes: 29 additions & 9 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion js/settings/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
87 changes: 61 additions & 26 deletions lib/BackgroundJobs/ComputeStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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');
}
Expand Down Expand Up @@ -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') {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
7 changes: 4 additions & 3 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
Expand Down
3 changes: 3 additions & 0 deletions templates/settings/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<label for="deletion_time">Data older than x years will be deleted with every statistic run:</label><br>
<input type="text" id="deletion_time" value="<?php p($_['deletion_time']); ?>"/>
<br><br>
<label for="version_aggregation">Nextcloud versions below x will be aggregated to the minor version:</label><br>
<input type="text" id="version_aggregation" value="<?php p($_['version_aggregation']); ?>"/>
<br><br>
<button id="surveyYearsSave">Save</button>
</div>

Expand Down