How to Create a a User Activity Report (log) by Category

How to Create a a User Activity Report (log) by Category

by Juan F -
Number of replies: 4

Greetings Moodle Members,

I have a simple request that has been driving me crazy.  I am in need of a user activity report by category.  We have each terms courses in a category.  This term is category 277.  I can run a user activity report (log) by course id and by user but this is taking a very long time.  Is there a way to run a user activity report (log) by category through the Dashboard with SQL code?

I've tried downloading our campus log from the administrator view but it stops after trying to run for a few minutes.  23927082 records is just too many and is more than I need for my report.

Please help!

Average of ratings: -
In reply to Juan F

Re: How to Create a a User Activity Report (log) by Category

by Alan Ball -

I needed the same report - and I needed all the sub categories too. Here's the SQL i used:

#active users in a category, including its sub categores
SELECT COUNT(DISTINCT l.userid) as active
FROM mdl_course as c
JOIN mdl_context AS ctx ON ctx.instanceid=c.id
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid
JOIN mdl_course_categories AS cats ON c.category = cats.id
WHERE c.category=cats.id AND (
cats.path LIKE '%/$NUM/%'
OR cats.path LIKE '%/$NUM'
)
AND ra.roleid=5 AND ctx.contextlevel=50 #change role to 3 for teachers, 4 for non editing teachers and 5 for students
AND l.timeaccess > (unix_timestamp() - ((60*60*24)*$NUM_OF_DAYS))

Replace '$NUM' with the id of your category
Replace '$NUM_OF_DAYS with a figure (eg: 28) to see how many users have been active over that time.

You cna also change: 

ra.roleid=

To another number - 3 is TEACHERS, 4 is NON-EDITING TEACHERS & 5 is STUDENTS

In reply to Juan F

Re: How to Create a a User Activity Report (log) by Category

by Eric Strom -

 

 

Your filter will need to incorporate courses just in your course category. Something along these lines:

mdl_course AS c

.

.

.

JOIN mdl_category AS cat ON cat.id=c.category

WHERE cat.id=277

 

In reply to Eric Strom

Re: How to Create a a User Activity Report (log) by Category

by Juan F -

Hmm...I tried the following in the Dashboard SQL section:

SELECT COUNT(DISTINCT l.userid) as active
FROM mdl_course as c
JOIN mdl_context AS ctx ON ctx.instanceid=c.id
JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id
JOIN mdl_user_lastaccess as l ON ra.userid = l.userid
JOIN mdl_course_categories AS cats ON c.category = cats.id
WHERE c.category=cats.id AND (
cats.path LIKE '%/277/%'
OR cats.path LIKE '%/277'
)
AND ra.roleid=3 AND ctx.contextlevel=50

It returned a number (88).  Not sure what this means.

I noticed changed the category to 277 and the roleid to 3.  I removed the time part since no user had access to this category or the subcategories before Jan 1st.

Any thoughts?  I really appreciate your prompt help!

In reply to Juan F

Re: How to Create a a User Activity Report (log) by Category

by Alan Ball -

Hi Chris,

The returned result is the number of unique active users during the specified time.