Skip to content

Instantly share code, notes, and snippets.

@mikebuchanon
Created January 14, 2013 21:11
Show Gist options
  • Save mikebuchanon/4533553 to your computer and use it in GitHub Desktop.
Save mikebuchanon/4533553 to your computer and use it in GitHub Desktop.
student vs faculty course views in Moodle by date, day of week, and hour
select to_timestamp(ml.time)::date as date,
extract(dow from to_timestamp(ml.time)) as dow,
extract(hour from to_timestamp(ml.time)) as hour,
sum(case when mr.name='Student' then 1 else 0 end) as student_logins,
sum(case when mr.name='Teacher' then 1 else 0 end) as fac_staff_logins
from mdl_log ml
join mdl_context mcon on mcon.contextlevel=50 and mcon.instanceid=ml.course
join mdl_role_assignments mra on mra.contextid=mcon.id
join mdl_role mr on mr.id=mra.roleid
where to_timestamp(ml.time) > '1/14/2013'
and ml.action='view' and ml.module='course'
group by to_timestamp(ml.time)::date,
extract(dow from to_timestamp(ml.time)),
extract(hour from to_timestamp(ml.time))
order by 1,3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment