Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Stats roles 1.7.

Development:Stats roles 1.7

From MoodleDocs
Revision as of 09:27, 19 September 2006 by Penny Leach (talk | contribs) (initial import of penn y's notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Statistics and reports need to be upgraded to use the new roles in 1.7 rather than user_students and user_teachers.

Penny (penny@catalyst.net.nz) is going to be working on this the week of 18 September. Here's the plan:

step 1. new database structure and migration

mdl_stats_user_* doesn't need changing structurally, although roleid needs to migrate to the id of the role to match the legacy role - first out of the returned array by:

  • get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW) and
  • get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)

mdl_stats_* needs changing to:

  • id
  • courseid
  • userid
  • roleid
  • timeend
  • stattype
  • stat1
  • stat2

the existing structure will migrate to:

  • students/teachers/activestudents/activeteachers:

two rows: (stattype = 'enrolments') 1. roleid - student (legacy), student = statreads, activestudents = statwrites 2. roleid - teacher (legacy), teacher = statreads, activeteachers = statwrites

  • studentreads/studentwrites/teacherreads/teacherwrites

two rows: (stattype = 'activity') 1. roleid - student (legacy), studentreads = statreads, studentwrites = statwrites 2. roleid - teacher (legacy), teacherreads = statreads, teacherwrites = statwrites

  • logins/uniquelogins

one row: (stattype = 'logins') 1. roleid - 0 (n/a) logins = statreads, uniquelogins = statwrites

step 2. new processing at cron.

add in an extra loop in the stats_cron_* functions: loop through roles used in context (course in this case) get_roles_used_in_context rather than join mdl_log on mdl_user_students and/or mdl_user_teachers, do something more like:


SELECT COUNT(l.id)

           FROM mdl_log l 
           JOIN mdl_role_assignments ra ON l.userid = ra.userid 
           JOIN mdl_context c ON ra.contextid = c.id 
           WHERE l.course = $course AND c.instanceid = $course 
           AND c.aggregatelevel = CONTEXT_COURSE AND ra.roleid = $roleid

AND $logfilterstuff


the calls to stats_do_<timeperiod>_user_cron just need to be changed to use the roles that we got from get_roles_used_in_context rather than 1 for student and 2 for teacher.

step 3. reports

some of these will need to change as we are currently just expecting ONE row returned, where now we will have many rows (one per role) for the same stattype.

  1. STATS_MODE_GENERAL
    1. STATS_REPORT_ACTIVITY - all reads vs all writes - add up for all roles (currently studentreads+studentwrites vs teacherreads+teacherwrites)
    2. STATS_REPORT_STUDENTACTIVITY - \
    3. STATS_REPORT_TEACHERACTIVITY - / these two get dropped and replaced by STATS_REPORT_BYROLE ($roleid)
    4. STATS_REPORT_READS - maybe we can pick two lines to graph here?
    5. STATS_REPORT_WRITES - maybe we can pick two lines to graph here?
    6. STATS_REPORT_LOGINS - doesn't need to change, roleid is already 0
  1. STATS_MODE_DETAILED - these don't need to change sql, but the ui will need to change. perhaps the best way to go is: select course /select role / select user, select time period, GO!
    1. STATS_REPORT_USER_ACTIVITY
    2. STATS_REPORT_USER_ALLACTIVITY
    3. STATS_REPORT_USER_LOGINS
    4. STATS_REPORT_USER_VIEW - this one is fine, it's not dynamic (user profile stats)
  1. STATS_MODE_RANKED - these all need to change to add up for all roles and deal with group/aggregate rather than just getting a list of fields to return.
    1. STATS_REPORT_ACTIVE_COURSES
    2. STATS_REPORT_ACTIVE_COURSES_WEIGHTED
    3. STATS_REPORT_PARTICIPATORY_COURSES
    4. STATS_REPORT_PARTICIPATORY_COURSES_RW