How to group logstore_standard_logs table results by day

How to group logstore_standard_logs table results by day

by Matthew Willis -
Number of replies: 2

Hi there,

I have this report that I *think* gets the correct # of unique logins grouped by day. However, when I compare this with manually checking the users list, the numbers are drastically different. For example: With my dataset and query below, the SQL reports that 1014 unique users logged into the LMS on 26th March 2019. However, admin/user.php > advanced filters > last access is after 26 March 2020 and before 27 March 2020 shows 866 users that logged in. Screenshot attached.

Why the difference?

select
from_unixtime(lsl.timecreated,"%D %M %Y") day,
count(lsl.userid)
from prefix_logstore_standard_log lsl
where lsl.action = 'loggedin'
and lsl.target = 'user'
group by from_unixtime(lsl.timecreated,"%D %M %Y")
order by lsl.timecreated desc

SQL Query data:

day count(distinct lsl.userid)
27th March 2020 534
26th March 2020 1014
25th March 2020 1119
24th March 2020 1243
23rd March 2020 1241
22nd March 2020 395
21st March 2020 301
20th March 2020 744
19th March 2020 915
18th March 2020 920

Average of ratings: Useful (1)
In reply to Matthew Willis

Re: How to group logstore_standard_logs table results by day

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hi Mattew,

You can have people that logged on 26 and on 27. For these, the last access is on 27, not 26 wink

HTH,
Séverin
Average of ratings: Useful (1)
In reply to Séverin Terrier

Re: How to group logstore_standard_logs table results by day

by Matthew Willis -
Hi Séverin,

Ahh, thanks for the reminder. For those that are potentially lurking this thread, The /admin/user.php page looks at the mdl_user_lastaccess table to get the user's last accessed date, which is always live data. My query looks at historical data only, so it is looking at the mdl_logstore_standard_log table to get the login information.

I'm glad to know it was just my logic that was broken and my SQL was correct ! :P

Thanks Séverin :D
Average of ratings: Useful (1)