Skip to content

Commit ef5077c

Browse files
author
dustinhuynh
committed
Fix display bug with metrics #197
1 parent c0311bb commit ef5077c

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

classes/metric/online_users_metric.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function generate_metric_items($backwardperiod, $finishtime = null, \prog
111111
FROM {logstore_standard_log}
112112
WHERE timecreated >= :starttime
113113
AND timecreated <= :finishtime
114+
AND action = "loggedin"
114115
)
115116
116117
SELECT user_data.time as time, COUNT(DISTINCT(user_data.userid)) as value

classes/metric/yearly_active_users_metric.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ public function is_autobackfill(): bool {
116116
*/
117117
public function generate_metric_item(int $starttime, int $finishtime): metric_item {
118118
global $DB;
119-
$lastyear = $finishtime - (60 * 60 * 24 * 365);
119+
$lastyear = $finishtime - YEARSECS;
120120
$users = $DB->count_records_select(
121121
'user',
122-
'confirmed = 1 AND (lastlogin > ? OR currentlogin > ?)',
122+
'confirmed = 1 AND (lastlogin >= ? OR currentlogin >= ?)',
123123
[$lastyear, $lastyear]
124124
);
125125
return new metric_item($this->get_name(), $finishtime, $users, $this);
@@ -146,10 +146,11 @@ public function generate_metric_items(int $backwardperiod, ?int $finishtime = nu
146146
if ($finishtime < $starttime) {
147147
return [];
148148
}
149-
$sql = 'SELECT COUNT(DISTINCT userid)
149+
$sql = "SELECT COUNT(DISTINCT userid)
150150
FROM {logstore_standard_log}
151151
WHERE timecreated >= :from
152-
AND timecreated <= :to';
152+
AND timecreated <= :to
153+
AND action = 'loggedin'";
153154
// Variables for updating progress.
154155
$count = 0;
155156
$total = ($finishtime - $starttime) / $interval;

collector/database/tests/cltr_database_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function test_backfillable_metric() {
184184
$dataobjects[] = [
185185
'eventname' => '\core\event\user_created',
186186
'component' => 'core',
187-
'action' => 'created',
187+
'action' => 'loggedin',
188188
'target' => 'user',
189189
'crud' => 'r',
190190
'edulevel' => 0,
@@ -193,7 +193,7 @@ public function test_backfillable_metric() {
193193
'contextinstanceid' => 0,
194194
'userid' => $i,
195195
'anonymous' => 0,
196-
'timecreated' => $i
196+
'timecreated' => $i,
197197
];
198198
}
199199
set_config('enabled_stores', 'logstore_standard', 'tool_log');

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2025072300;
29-
$plugin->release = 2025072300;
28+
$plugin->version = 2025072301;
29+
$plugin->release = 2025072301;
3030

3131
$plugin->requires = 2024042200; // Our lowest supported Moodle (4.4.0).
3232

0 commit comments

Comments
 (0)