Permalink
Browse files

MDL-30643 - Added statslib test file.

          - Tests daily stats and daily stats related functions.
  • Loading branch information...
1 parent 4614b02 commit c0f00c5fbae6156640b95dba2bbcc1a41e1d5857 Tyler Bannister committed Aug 3, 2012
View
@@ -217,19 +217,25 @@ function stats_cron_daily($maxdays=1) {
break;
}
- stats_progress('0');
-
// Find out if any logs available for this day
$sql = "SELECT 'x' FROM {temp_log1} l";
$logspresent = $DB->get_records_sql($sql, null, 0, 1);
+ if ($logspresent) {
+ // Insert blank record to force Query 10 to generate additional row when no logs for
+ // the site with userid 0 exist. Added for backwards compatibility.
+ $DB->insert_record('temp_log1', array('userid' => 0, 'course' => SITEID, 'action' => ''));
+ }
+
// Calculate the number of active users today
$sql = 'SELECT COUNT(DISTINCT u.id)
FROM {user} u
JOIN {temp_log1} l ON l.userid = u.id
WHERE u.deleted = 0';
$dailyactiveusers = $DB->count_records_sql($sql);
+ stats_progress('0');
+
// Process login info first
// Note: PostgreSQL doesn't like aliases in HAVING clauses
$sql = "INSERT INTO {temp_stats_user_daily}
@@ -427,7 +433,6 @@ function stats_cron_daily($maxdays=1) {
SUM(CASE WHEN action $viewactionssql THEN 1 ELSE 0 END) AS statsreads,
SUM(CASE WHEN action $postactionssql THEN 1 ELSE 0 END) AS statswrites
FROM {temp_log1} l
- WHERE !(course = 0 AND userid = 0)
GROUP BY userid, courseid";
if ($logspresent && !stats_run_query($sql, array_merge($params1, $params2))) {
@@ -1640,10 +1645,10 @@ function stats_temp_table_drop() {
function stats_temp_table_fill($timestart, $timeend) {
global $DB;
- $sql = "INSERT INTO {temp_log1} (userid, course, action)
+ $sql = 'INSERT INTO {temp_log1} (userid, course, action)
SELECT userid, course, action FROM {log}
- WHERE time >= ? AND time < ?";
+ WHERE time >= ? AND time < ?';
$DB->execute($sql, array($timestart, $timeend));
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Tests no logs - Only query 3 should be processed -->
+<dataset>
+ <table name="log">
+ <column>time</column>
+ <column>userid</column>
+ <column>course</column>
+ <column>action</column>
+ </table>
+ <table name="stats_daily">
+ <column>courseid</column>
+ <column>timeend</column>
+ <column>roleid</column>
+ <column>stattype</column>
+ <column>stat1</column>
+ <column>stat2</column>
+ <row>
+ <value>[course1_id]</value>
+ <value>[end_no_logs]</value>
+ <value>5</value>
+ <value>enrolments</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="stats_user_daily">
+ <column>courseid</column>
+ <column>userid</column>
+ <column>roleid</column>
+ <column>timeend</column>
+ <column>statsreads</column>
+ <column>statswrites</column>
+ <column>stattype</column>
+ </table>
+</dataset>
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- No login test - Tests queries 2, 3, 5, 7, 9 (and 8), 10 (read) -->
+<dataset>
+ <table name="log">
+ <column>time</column>
+ <column>userid</column>
+ <column>course</column>
+ <column>action</column>
+ <row>
+ <value>[start_1]</value>
+ <value>[guest_id]</value>
+ <value>[site_id]</value>
+ <value>view</value>
+ </row>
+ </table>
+ <table name="stats_daily">
+ <column>courseid</column>
+ <column>timeend</column>
+ <column>roleid</column>
+ <column>stattype</column>
+ <column>stat1</column>
+ <column>stat2</column>
+ <!-- Query 2 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>logins</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <!-- Query 3 -->
+ <row>
+ <value>[course1_id]</value>
+ <value>[end]</value>
+ <value>[student_roleid]</value>
+ <value>enrolments</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <!-- Query 5 -->
+ <row>
+ <value>[course1_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>enrolments</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <!-- Query 7 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>enrolments</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <!-- Query 9 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>[frontpage_roleid]</value>
+ <value>enrolments</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <!-- Query 11 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>activity</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <!-- Query 16 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>[guest_roleid]</value>
+ <value>activity</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="stats_user_daily">
+ <column>courseid</column>
+ <column>userid</column>
+ <column>roleid</column>
+ <column>timeend</column>
+ <column>statsreads</column>
+ <column>statswrites</column>
+ <column>stattype</column>
+ <!-- Query 10 - read -->
+ <row>
+ <value>[site_id]</value>
+ <value>[guest_id]</value>
+ <value>0</value>
+ <value>[end]</value>
+ <value>1</value>
+ <value>0</value>
+ <value>activity</value>
+ </row>
+ <!-- Query 10 - default record -->
+ <row>
+ <value>[site_id]</value>
+ <value>0</value>
+ <value>0</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>0</value>
+ <value>activity</value>
+ </row>
+ </table>
+</dataset>
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Single login - Tests queries 1, 2 (with logins), 4 -->
+<dataset>
+ <table name="log">
+ <column>time</column>
+ <column>userid</column>
+ <column>course</column>
+ <column>action</column>
+ <row>
+ <value>[start_1]</value>
+ <value>[user1_id]</value>
+ <value>[site_id]</value>
+ <value>login</value>
+ </row>
+ </table>
+ <table name="stats_daily">
+ <column>courseid</column>
+ <column>timeend</column>
+ <column>roleid</column>
+ <column>stattype</column>
+ <column>stat1</column>
+ <column>stat2</column>
+ <!-- Query 2 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>logins</value>
+ <value>1</value>
+ <value>1</value>
+ </row>
+ <!-- Query 3 -->
+ <row>
+ <value>[course1_id]</value>
+ <value>[end]</value>
+ <value>[student_roleid]</value>
+ <value>enrolments</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <!-- Query 5 -->
+ <row>
+ <value>[course1_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>enrolments</value>
+ <value>1</value>
+ <value>0</value>
+ </row>
+ <!-- Query 7 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>enrolments</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <!-- Query 9 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>[frontpage_roleid]</value>
+ <value>enrolments</value>
+ <value>4</value>
+ <value>1</value>
+ </row>
+ <!-- Query 11 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>activity</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ </table>
+ <table name="stats_user_daily">
+ <column>courseid</column>
+ <column>userid</column>
+ <column>roleid</column>
+ <column>timeend</column>
+ <column>statsreads</column>
+ <column>statswrites</column>
+ <column>stattype</column>
+ <!-- Query 1 -->
+ <row>
+ <value>[site_id]</value>
+ <value>[user1_id]</value>
+ <value>0</value>
+ <value>[end]</value>
+ <value>1</value>
+ <value>0</value>
+ <value>logins</value>
+ </row>
+ <!-- Query 10 - read -->
+ <row>
+ <value>[site_id]</value>
+ <value>[user1_id]</value>
+ <value>0</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>0</value>
+ <value>activity</value>
+ </row>
+ <!-- Query 10 - default record -->
+ <row>
+ <value>[site_id]</value>
+ <value>0</value>
+ <value>0</value>
+ <value>[end]</value>
+ <value>0</value>
+ <value>0</value>
+ <value>activity</value>
+ </row>
+ </table>
+</dataset>
Oops, something went wrong. Retry.

0 comments on commit c0f00c5

Please sign in to comment.