Skip to content

Commit de778ad

Browse files
author
dustinhuynh
committed
#180 - New metric for rolling 12 months active users
+ Renamed a metric class and parameters from 'rolling' to 'yearly'
1 parent bf4d3f9 commit de778ad

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

classes/metric/manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function get_frequency_labels(): array {
8484
'newusers' => self::FREQ_DAY,
8585
'onlineusers' => self::FREQ_5MIN,
8686
'dailyusers' => self::FREQ_DAY,
87-
'rollingactiveusers' => self::FREQ_DAY,
87+
'yearlyactiveusers' => self::FREQ_DAY,
8888
];
8989

9090
/**
@@ -100,7 +100,7 @@ public static function get_metrics(bool $enabledonly = true): array {
100100
'newusers' => new new_users_metric(),
101101
'onlineusers' => new online_users_metric(),
102102
'dailyusers' => new daily_users_metric(),
103-
'rollingactiveusers' => new rolling_active_users_metric(),
103+
'yearlyactiveusers' => new yearly_active_users_metric(),
104104
];
105105

106106
// Find metrics from plugins.

classes/metric/rolling_active_users_metric.php renamed to classes/metric/yearly_active_users_metric.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
namespace tool_cloudmetrics\metric;
1818

1919
/**
20-
* Metric class for 12 months rolling active users.
20+
* Metric class for 12 months yearly active users.
2121
*
2222
* @package tool_cloudmetrics
2323
* @author Dustin Huynh <dustinhuynh@catalyst-au.net>
2424
* @copyright 2025, Catalyst IT
2525
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2626
*/
27-
class rolling_active_users_metric extends builtin_user_base {
27+
class yearly_active_users_metric extends builtin_user_base {
2828

2929
/**
3030
* The metric's name.
3131
*
3232
* @return string
3333
*/
3434
public function get_name(): string {
35-
return 'rollingactiveusers';
35+
return 'yearlyactiveusers';
3636
}
3737

3838
/**

lang/en/tool_cloudmetrics.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
$string['newusers_desc'] = 'Users who have signed up recently.';
7676
$string['dailyusers'] = 'Daily users';
7777
$string['dailyusers_desc'] = 'Unique users over a day (fixed frequency).';
78-
$string['rollingactiveusers'] = 'Rolling active users';
79-
$string['rollingactiveusers_desc'] = 'Users that have been active within the past 365 days from today.';
78+
$string['yearlyactiveusers'] = 'Yearly active users';
79+
$string['yearlyactiveusers_desc'] = 'Users that have been active within the past 365 days from today.';
8080

8181
// User selection labels.
8282
$string['data_empty'] = 'Your database for this metric is empty.';

tests/tool_cloudmetrics_collect_metrics_test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static function execute_provider(): array {
171171
'online_users_metric' => [manager::FREQ_5MIN, 'midnight +75 minutes'],
172172
'active_users_metric' => [manager::FREQ_HOUR, 'midnight'],
173173
'daily_users_metric' => [manager::FREQ_DAY, 'midnight'],
174-
'rolling_active_users_metric' => [manager::FREQ_DAY, 'midnight'],
174+
'yearly_active_users_metric' => [manager::FREQ_DAY, 'midnight'],
175175
],
176176
['activeusers', 'newusers'],
177177
],
@@ -182,7 +182,7 @@ public static function execute_provider(): array {
182182
'online_users_metric' => [manager::FREQ_DAY, '2020-03-01T00:00:00'],
183183
'active_users_metric' => [manager::FREQ_MONTH, '2020-03-01T00:00:00'],
184184
'daily_users_metric' => [manager::FREQ_DAY, '2020-03-01T00:00:00'],
185-
'rolling_active_users_metric' => [manager::FREQ_DAY, '2020-03-01T00:00:00'],
185+
'yearly_active_users_metric' => [manager::FREQ_DAY, '2020-03-01T00:00:00'],
186186
],
187187
[],
188188
],
@@ -193,9 +193,9 @@ public static function execute_provider(): array {
193193
'online_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
194194
'active_users_metric' => [manager::FREQ_MONTH, '2020-02-01T00:00:00'],
195195
'daily_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
196-
'rolling_active_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
196+
'yearly_active_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
197197
],
198-
['activeusers', 'dailyusers', 'newusers', 'onlineusers', 'rollingactiveusers'],
198+
['activeusers', 'dailyusers', 'newusers', 'onlineusers', 'yearlyactiveusers'],
199199
],
200200
[
201201
'2020-02-02T00:02:00',
@@ -204,14 +204,14 @@ public static function execute_provider(): array {
204204
'online_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
205205
'active_users_metric' => [manager::FREQ_MONTH, '2020-02-01T00:00:00'],
206206
'daily_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
207-
'rolling_active_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
207+
'yearly_active_users_metric' => [manager::FREQ_DAY, '2020-02-01T00:00:00'],
208208
],
209-
['dailyusers', 'newusers', 'onlineusers', 'rollingactiveusers'],
209+
['dailyusers', 'newusers', 'onlineusers', 'yearlyactiveusers'],
210210
],
211211
[
212212
'2020-02-02T00:03:00',
213213
['new_users_metric' => [manager::FREQ_5MIN, null]],
214-
['activeusers', 'dailyusers', 'newusers', 'onlineusers', 'rollingactiveusers'],
214+
['activeusers', 'dailyusers', 'newusers', 'onlineusers', 'yearlyactiveusers'],
215215
],
216216
];
217217
}

tests/tool_cloudmetrics_users_test.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use tool_cloudmetrics\metric\new_users_metric;
2121
use tool_cloudmetrics\metric\active_users_metric;
2222
use tool_cloudmetrics\metric\online_users_metric;
23-
use tool_cloudmetrics\metric\rolling_active_users_metric;
23+
use tool_cloudmetrics\metric\yearly_active_users_metric;
2424

2525
/**
2626
* Unit tests to test the builtin user metric types.
@@ -104,14 +104,14 @@ public function test_generate_metrics(string $metricname, int $frequency, array
104104

105105

106106
/**
107-
* Tests test_generate_rolling_active_users_metric() for the builtin user metrics.
107+
* Tests test_generate_yearly_active_users_metric() for the builtin user metrics.
108108
*
109-
* @dataProvider data_for_test_generate_rolling_active_users_metric
109+
* @dataProvider data_for_test_generate_yearly_active_users_metric
110110
* @param string $metricname The name of the metric to be tested.
111111
* @param array $expected List of metric items that expect to be generated.
112112
* @throws \dml_exception
113113
*/
114-
public function test_generate_rolling_active_users_metric(string $metricname, array $expected): void {
114+
public function test_generate_yearly_active_users_metric(string $metricname, array $expected): void {
115115
global $DB;
116116

117117
foreach (self::ACTIVE_USER_DATA as $row) {
@@ -167,20 +167,20 @@ public function data_for_test_generate_metrics(): array {
167167
}
168168

169169
/**
170-
* Data provider for test_generate_metrics.
170+
* Data provider for test_generate_yearly_active_users_metric.
171171
*
172172
* @return array[]
173173
*/
174-
public function data_for_test_generate_rolling_active_users_metric(): array {
175-
$rollingactiveusers = new rolling_active_users_metric();
174+
public function data_for_test_generate_yearly_active_users_metric(): array {
175+
$yearlyactiveusers = new yearly_active_users_metric();
176176

177177
return [
178-
['rollingactiveusers', [
179-
new metric_item('rollingactiveusers', self::SECOND_IN_DAY * 366 , 10, $rollingactiveusers),
180-
new metric_item('rollingactiveusers', self::SECOND_IN_DAY * 367, 9, $rollingactiveusers),
181-
new metric_item('rollingactiveusers', self::SECOND_IN_DAY * 368, 6, $rollingactiveusers),
182-
new metric_item('rollingactiveusers', self::SECOND_IN_DAY * 369, 4, $rollingactiveusers),
183-
new metric_item('rollingactiveusers', self::SECOND_IN_DAY * 370, 2, $rollingactiveusers)],
178+
['yearlyactiveusers', [
179+
new metric_item('yearlyactiveusers', self::SECOND_IN_DAY * 366 , 10, $yearlyactiveusers),
180+
new metric_item('yearlyactiveusers', self::SECOND_IN_DAY * 367, 9, $yearlyactiveusers),
181+
new metric_item('yearlyactiveusers', self::SECOND_IN_DAY * 368, 6, $yearlyactiveusers),
182+
new metric_item('yearlyactiveusers', self::SECOND_IN_DAY * 369, 4, $yearlyactiveusers),
183+
new metric_item('yearlyactiveusers', self::SECOND_IN_DAY * 370, 2, $yearlyactiveusers)],
184184
],
185185
];
186186
}

0 commit comments

Comments
 (0)