Skip to content

Commit

Permalink
feat(active users): add more active user statistics intervals and imp…
Browse files Browse the repository at this point in the history
…rove presentation

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Oct 4, 2024
1 parent 394e80f commit 9285949
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 13 deletions.
32 changes: 32 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,35 @@
align-items: center;
height: 24px;
}

.active-users-wrapper {
flex: 1;
display: flex;
gap: 0 1rem;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}

.active-users-box {
padding: 0.25rem 1rem;
flex: 1;
min-width: 150px;
border-left: 2px solid var(--color-border);
}

@media (width <= 1280px) {
.active-users-box {
padding: 1rem 0.5rem;
border: none;
text-align: center;
}
}

.active-users-box:first-child {
border: none;
}

.active-users-box .info {
font-size: 2rem;
}
10 changes: 10 additions & 0 deletions lib/SessionStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class SessionStatistics {
private const OFFSET_5MIN = 300;
private const OFFSET_1HOUR = 3600;
private const OFFSET_1DAY = 86400;
private const OFFSET_7DAYS = 604800;
private const OFFSET_1MONTH = 2592000;
private const OFFSET_3MONTHS = 7776000;
private const OFFSET_6MONTHS = 15552000;
private const OFFSET_1YEAR = 31536000;

private IDBConnection $connection;
private ITimeFactory $timeFactory;
Expand All @@ -39,6 +44,11 @@ public function getSessionStatistics(): array {
'last5minutes' => $this->getNumberOfActiveUsers(self::OFFSET_5MIN),
'last1hour' => $this->getNumberOfActiveUsers(self::OFFSET_1HOUR),
'last24hours' => $this->getNumberOfActiveUsers(self::OFFSET_1DAY),
'last7days' => $this->getNumberOfActiveUsers(self::OFFSET_7DAYS),
'last1month' => $this->getNumberOfActiveUsers(self::OFFSET_1MONTH),
'last3months' => $this->getNumberOfActiveUsers(self::OFFSET_3MONTHS),
'last6months' => $this->getNumberOfActiveUsers(self::OFFSET_6MONTHS),
'lastyear' => $this->getNumberOfActiveUsers(self::OFFSET_1YEAR),
];
}

Expand Down
45 changes: 32 additions & 13 deletions templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,46 @@ function FormatMegabytes(int $byte): string {

<div class="col col-12">
<div class="row">
<div class="col col-4 col-l-6 col-m-12">
<div class="col">
<div class="infobox">
<div class="interface-wrapper">
<?php if ($_['storage']['num_users'] > 0) : ?>
<?php p($l->t('Total users:')); ?>
<span class="info"><?php p($_['storage']['num_users']); ?></span><br>
<div class="interface-wrapper active-users-wrapper">
<?php if ($_['activeUsers']['last1hour'] > 0) : ?>
<div class="active-users-box">
<?php p($l->t('1 Hour Active Users')); ?><br>
<span class="info"><?php p($_['activeUsers']['last1hour']) ?></span><br>
<em><?php p($l->t('%s%% of all users', [round($_['activeUsers']['last1hour'] * 100 / $_['storage']['num_users'], 1)])) ?></em>
</div>
<?php endif; ?>

<?php if ($_['activeUsers']['last24hours'] > 0) : ?>
<?php p($l->t('24 hours:')); ?>
<span class="info"><?php p($_['activeUsers']['last24hours']) ?></span><br>
<div class="active-users-box">
<?php p($l->t('1 Day Active Users')); ?><br>
<span class="info"><?php p($_['activeUsers']['last24hours']) ?></span><br>
<em><?php p($l->t('%s%% of all users', [round($_['activeUsers']['last24hours'] * 100 / $_['storage']['num_users'], 1)])) ?></em>
</div>
<?php endif; ?>

<?php if ($_['activeUsers']['last1hour'] > 0) : ?>
<?php p($l->t('1 hour:')); ?>
<span class="info"><?php p($_['activeUsers']['last1hour']) ?></span><br>
<?php if ($_['activeUsers']['last7days'] > 0) : ?>
<div class="active-users-box">
<?php p($l->t('7 Day Active Users')); ?><br>
<span class="info"><?php p($_['activeUsers']['last7days']) ?></span><br>
<em><?php p($l->t('%s%% of all users', [round($_['activeUsers']['last7days'] * 100 / $_['storage']['num_users'], 1)])) ?></em>
</div>
<?php endif; ?>

<?php if ($_['activeUsers']['last1month'] > 0) : ?>
<div class="active-users-box">
<?php p($l->t('1 Month Active Users')); ?><br>
<span class="info"><?php p($_['activeUsers']['last1month']) ?></span><br>
<em><?php p($l->t('%s%% of all users', [round($_['activeUsers']['last1month'] * 100 / $_['storage']['num_users'], 1)])) ?></em>
</div>
<?php endif; ?>

<?php if ($_['activeUsers']['last5minutes'] > 0) : ?>
<?php p($l->t('5 mins:')); ?>
<span class="info"><?php p($_['activeUsers']['last5minutes']) ?></span><br>
<?php if ($_['storage']['num_users'] > 0) : ?>
<div class="active-users-box">
<?php p($l->t('Total users')); ?><br>
<span class="info"><?php p($_['storage']['num_users']); ?></span><br>
</div>
<?php endif; ?>
</div>
</div>
Expand Down

0 comments on commit 9285949

Please sign in to comment.