stats package

stats package

by Penny Leach -
Number of replies: 42
I've just finished writing a stats package for moodle, I'm going to petition MD for it's inclusion in 1.5 big grin but here is an unofficial patch, a few screenshots. and a brief explanation.

patch: http://nzvle.eduforge.org/stats/stats.patch (this is against today's 1.5)

screenshots:




explanation:

Three new tables are created, to contain data that comes from processing moodle's log table, for daily, weekly and monthly statistics. Moodle's cronjob will populate these. There are a few new config settings, to enable stats collection at all, and how far back to process moodle's logs the first time the cronjob runs. If your site has a lot of traffic, and there are a lot of logs, processing these for the first time can be quite resource heavy, so if you're on shared hosting, it may be a good idea not to go back too far, You can set it to none, all, or a few time periods in between.

Once there's some statistics in there, each course has a new item in the menu next to logs, called statistics, which will let you view some basic data about the course, with a table and some pretty graphs. For the site course, in addition to the normal reports, you can see logins and unique logins over time.

So far, the reports I have done are:

Logins/Unique logins
Views - teachers vs students
Posts - teachers vs students
All activity - teachers vs students
Student activity - views vs posts
Teacher activity - views vs posts

In this contents, 'vs' means that the two datasets are both graphed.

Views/posts - views means anything that doesn't save back to the database, posts means anything that does (forum posts, assessment uploads etc etc)

Here is a list of all the data that gets saved in the three tables:

* id
* courseid
* date period ended
* number enrolments
* number teachers assigned
* number active students
* number active teachers
* total course reads by students (views)
* total course writes by students(everything else - excludes errors)
* total course reads by teachers
* total course writes by teachers
* logins - 'site' course only
* unique logins - 'site' course only

Some other reports could be added really, like number of teachers to number of students, number active teachers to number active students etc.

Also , all these reports are course centric right now. Going forward it might be useful to do some sort of ranking of different reports across courses. Like, top 10 participatory courses (based on views/posts or enrolled students/active students)

-- Penny

Edit! To force the db upgrade, manually bump version.php to 2005031000
Average of ratings: -
In reply to Penny Leach

Re: stats package

by Genner Cerna -
Very impressive indeed, can you include in stats the browser they are using?

For us to track what type of brwser usually get errors...
In reply to Genner Cerna

Re: stats package

by Penny Leach -
Thanks!

Currently, the user agent isn't stored even in moodle's log table, and my stats are like a less granular version of those, so your short answer is no.

I guess the normal log table could start to store the user agent, or at least parse the user agent string and store the browser and version number, although that can be pretty hard... and then if that were there, my stats could figure out the most common browser per course.
In reply to Penny Leach

Re: stats package

by shane luffman -
hi penny, im running moodle on iis6, windows 2003 server, please could you tell me how i can use the stats patch? i would be very greatful if you could shed some light on how to get stats patch to work...thanks shane
In reply to shane luffman

Re: stats package

by Penny Leach -
The answer is wait for moodle 1.6 to be released, stats is included in 1.6 standard and is much more feature rich and stable.

In reply to Penny Leach

Re: stats package

by shane luffman -
hi penny, there seems to be an error in moodle 1.6 stats page, the link in admin points to course/stats.php, however file is lost or missing, is this a bug and will it be fixed in the production version? thanks shane
In reply to Genner Cerna

Re: stats package

by Dirk Herr-Hoyman -
A better way to get the types of browser used is to run some web log analyzer.
This data in is the http server logs.
We have done this with Analog, you can see what comes out
at http://atsosxdev.doit.wisc.edu/moodle/statistics

We haven't tuned this report and didn't put the browser report in there.
It's the "out of the box" report. Updates once/day, our httpd logs are cummulative. We also now are adding in Report Magic
(does better graphs), but haven't gotten around to that here.

At some point, I'll have someone do analysis on how to get some better reports
out. Daily, Weekly, Monthly. These would complement what Penny has done. It would be quite possible to share the Analog setup to generate specific reports.

Analog is a very common web stats analyzer and is often provided by web hosting services. Actually, it would be not-so-hard to add it into a "standard install" for Moodle or as an added feature.
In reply to Dirk Herr-Hoyman

Re: stats package

by Martín Langhoff -
"A better way to get the types of browser used is to run some web log analyzer."

To clarify -- the stats package is complementary to the web log analyzer. Server log analysis is useful to gauge traffic and server usage, but useless to see what courses are being used, how active users are, etc. The stats package provides application level usage, much more useful to actual Moodle users (admins and teachers).

We aren't looking into integrating analog... Any hosting company worth its salt is running analog or something comparable for you already.
In reply to Martín Langhoff

Re: stats package

by Michael Penney -
For one, I'd love to see browser/OS in the Moodle logs, at least for admins it would help much with support (most of our support problems are of the O yeah, you're using IE on a Mac sort--with some XP sp2/IE 6 with popup blocking on mixed in for funsmile.
In reply to Penny Leach

Re: stats package

by Julian Ridden -

I feel as if I am about to ask a really stupid question,so please bear with me as Im new big grin

How is your patch implemented. It came through as a text file. Am I to assume I make these changes to my files manually or is this file part of an automated process?

Sorry again for asking the obvious as I think I know the answer. But please confirm it for me.

In reply to Julian Ridden

Re: stats package

by Martín Langhoff -
While the patch is human-readable (*), the way to apply it is to use the "patch" program. If you are using linux/unix/macosx you probably have it or it's trivial to install. If you use Windows, there are many, many options. You can get cygwin which has a lot of unix utilities for Windows. Or one of the many bundles like this one http://users.ncrvnet.nl/gmvdijk/utilities.html



* - For those wondering how to read it... it tells you the file being changed, then the range of lines, then shows a bit of context, and then removed lines (start with "-") and added lines (start with "+").
In reply to Penny Leach

Re: stats package

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
That looks very nice, Penny!!

I think this addition will be welcome in the corporate world. I read more and more about Enterprises and Corporations that use Moodle as a tool for internal communication and training. They usually ask for this kind of reporting feature.

Last days we have discussed in Spanish forums about how to measure the time spent by each user on Moodle. This is useless from a teaching point of view, but Corporations have their own administrative rules. Accountants want to know how much of a working day the employee has been in Moodle vs. attending his job (and employees can use moodle as an excuse for laziness, too. At least, that's  what employers fear) .

I will have a look into your work. I am sure there will be a lot of good ideas there.

- Enrique -
In reply to Enrique Castro

Re: stats package

by Penny Leach -
We talked about doing amount of time spent on moodle type reporting, that will be a later stage of the stats package, see this discussion:

http://moodle.org/mod/forum/discuss.php?d=16384#82397


It's pretty complicated actually, we had a big whiteboarding session about it and decided on a sort of sliding window approach, between a user's login time and the last record in the log table for that user up until the next login time is the amount of time you have to play with total, but when you're actually processing it if they're in the middle of a session you have to discard it and then do it in the next run...

And for each session you need to know how long they spend in each course, and what to do if they flick between one course and the next.. so we made it stage 2.

Sorry that probably made no sense. I have a picture in my mind though :p
In reply to Penny Leach

Re: stats package

by Penny Leach -
I just updated the patch with some better handling of locking for cronjobs. I'm also running the process over about 6 months of data for a big site (30k users, 6k courses) and it's going to take probably about 10 hours for the initial run over the historic data. (Just to give you some idea)

Anyway, if you're interested in the patch, get the latest one from http://nzvle.eduforge.org/stats/stats.patch
In reply to Penny Leach

Re: stats package

by Penny Leach -
Just updated it again to be a bit easier for performance, amongst other things.

And ! I should probably have pointed out that if you want to apply the patch, you'll probably also want the icon:


(Going to stop talking to myself now tongueout)
In reply to Penny Leach

Re: stats package

by Penny Leach -
OK, I lied, I'm still talking to myself.

This time I have updated the patch For The Last Time (tm).
In reply to Penny Leach

Re: stats package

by Julian Ridden -

Penny,

I have installe your stats patch and am having issues getting the data to generate. I run my cron.php and get the following results

Starting activity modules
Finished activity modules
Running backups if required...
    Checking backup status...INACTIVE
Backup tasks finished.
Running rssfeeds if required...
    Generating rssfeeds...
        assignment: ...NOT SUPPORTED (file)
        choice: ...NOT SUPPORTED (file)
        forum: generating ...OK
        chat: ...NOT SUPPORTED (file)
        journal: ...NOT SUPPORTED (file)
        label: ...NOT SUPPORTED (file)
        lesson: ...NOT SUPPORTED (file)
        quiz: ...NOT SUPPORTED (file)
        resource: ...NOT SUPPORTED (file)
        scorm: ...NOT SUPPORTED (file)
        survey: ...NOT SUPPORTED (file)
        wiki: ...NOT SUPPORTED (file)
        workshop: ...NOT SUPPORTED (file)
        scheduler: ...NOT SUPPORTED (file)
        hotpot: ...NOT SUPPORTED (file)
        glossary: generating ...OK
        mail: ...NOT SUPPORTED (file)
    Ending  rssfeeds......OK
Rssfeeds finished
Cron script completed correctly
Execution took 0.101779 seconds

Obviously stats data has not come through. I have attatched my cron file in case I have missed something.

The tables do exist in my sql for the data to reside in. Any ideas what has happened?

In reply to Julian Ridden

Re: stats package

by Penny Leach -
Hi Julian,

Are you running this against 1.5 or 1.4.x?

Did you change the two config settings? Stats will NOT RUN at all until you've changed them. You need to set enablestats to 'yes' and pick a value for statsfirstrun. If you've patched 1.5 then you should find them in your config -> variables page. If you've patched 1.4.x you can put them into your moodle config table manually, or set them in config.php.
In reply to Penny Leach

Re: stats package

by Julian Ridden -
I am running 1.5 and have set both the fields in config -> variables
In reply to Julian Ridden

Re: stats package

by Penny Leach -
Julian,

What did you set the first time run to be? Did you set it to none? Thinking about it, there may be a bug with 'none', but I don't want to investigate until you confirm that is indeed your config.

In reply to Penny Leach

Re: stats package

by Julian Ridden -

Here are my setting Penny

Statistics

enablestats: No Yes
 If you choose 'yes' here, Moodle's cronjob will process the logs and gather some statistics. Depending on the amount of traffic on your site, this can take awhile. If you enable this, you will be able to see some interesting graphs and statistics about each of your courses, or on a sitewide basis.
statsfirstrun: None 1 weeks 2 weeks 3 weeks 1 months 2 months 3 months 4 months 5 months 6 months All
 This specifies how far back the logs should be processed the first time the cronjob wants to process statistics. If you have a lot of traffic and are on shared hosting, it's probably not a good idea to go too far back, as it could take a long time to run and be quite resource intensive. (Note that for this setting, 1 month = 28 days. In the graphs and reports generated, 1 month = 1 calendar month.)
In reply to Penny Leach

Re: stats package

by Julian Ridden -

Here are my settings:

enablestats: yes

statsfirstrun: 1 month

I have tried different first run durations but none have made any impact

In reply to Julian Ridden

Re: stats package

by Penny Leach -
We sorted this out via email. Julian had half installed a module the first time cron had run and cron.php died because of it.

The stats cron can take quite some time to run the first time around, so it creates a 'lockfile' in the form of a record in prefix_config. Because cron.php died the first time, the lockfile was never deleted, so every time he tried to run it after that, it thought there was another process already running and wouldn't start.

In this case, it was a simple matter of running the following query:

select * from prefix_config where name like '%stats%';

if there are any results with obvious lockfile titles (if it dies on the first time there could be two - firstrun lock & normal lock) then just delete them and run again. That sorted out the problem for Julian.

Edit: it's worth mentioning that the normal run lock is time sensitive. That is, it has a duration (3 hours), and after that, the lock will get clobbered and things will run normally again.

The first run lock, because the length of the first run is hugely dependent on your config settings and how much data you have, gets set to not be clobbered, because it could take a very long time before it should actually be considered stale. Our first run over a busy site with 6 months of data took 10 hours, for example. At any rate, these locks can always be deleted manually.
In reply to Penny Leach

Re: stats package

by Umar Akram -

Hi Penny,

I seem to be getting the same problem in that my stats package will not run in cron.  You mentioned runing:   select * from prefix_config where name like '%stats%';     but i'm not sure how i run this and where from.  Consider me a newbie.  Any help will be appreciated.  i have followed this whole forum and got correct settings in place but nothing.

Any help will be greatly appreciated.  I just downloaded Moodle 1.6 two days ago and am trying to run the stats on that.

Thanks

Umar

In reply to Umar Akram

Re: stats package

by Christina Keing -
Umar, that is a SQL statement which you should run at your database and you.  Remember to change the "prefix" at prefix_config to the prefix at your site.  After that, you should see 4 entries from the query.  Set value of "statsfirstunlock" and "statsrunning" to null and run the cron job again.

Besides, did you see anything in related to the stats package when you run the cron job?
In reply to Christina Keing

Re: stats package

by Umar Akram -

Thanks for the reply.  I realised it was an SQL statement and had already tried running it in PhpMyAdmin but it gave an error. My mistake was that i didn't know what you originally meant by changing my "prefix".  Change "prefix" at prefix_config to the prefix at your site.  I now figured this means change "prefix_config" to the original "mdl_config" and then run the SQL statement.

Now when i ran the statement it gave me 9 entries from the query as below;

 
Edit Delete 296statsfirstrunlocknull
Edit Delete 272enablestats1
Edit Delete 283statsfirstrun604800
Edit Delete 284statsmaxruntime10800
Edit Delete 285statsuserthreshold0
Edit Delete 288statsruntimestarthour13
Edit Delete 289statsruntimestartminute30
Edit Delete 297statsrunningnull
Edit Delete 298statslastdaily1141041114

The 1st and 9th row was initally set to "0" and as you have stated i changed this to "null" and ran the Cron Job again (no mention of stats in the job) and then upon clicking the stats icon in moodle i still get no luck.  It just says "0 days done and 7 pending".

And yes when i initially last ran the cron job i did see a some kind of note regarding the stats package.  It mentioned something about the lockfile.

In reply to Umar Akram

Re: stats package

by Penny Leach -
I can't see why it wouldn't be running. Can you capture the output of the cronjob at the first run after 1330 and paste it here? It should say something about stats in there.
In reply to Penny Leach

Re: stats package

by Mark Berthelemy -
Hi Penny,

Any news on whether this will be in 1.5?

Cheers,

Mark
In reply to Mark Berthelemy

Re: stats package

by Penny Leach -
Not in 1.5, no - I left it too late. Martin has given me the goahead to merge it in after 1.5 though, so you can expect it in 1.6
In reply to Penny Leach

Re: stats package

by Dirk Herr-Hoyman -
This is good, I like the approach.

Allow me to give you some feedback based on requirements from
the University of Wisconsin. I was the lead for this requirements gathering.
I'm attaching a spreadsheet that is breaking this down into "feature requests".
This has been going around to the "site admins" of Learn@UW (http://learnuw.wisconsin.edu), and you see the relative priorities that they have set
by mutual agreement.

I should add that the term "org" here stands for "org unit" or "organizational unit".
In the system we are currently running, D2L, you can organize things hierarchically by "org unit". Not that I'm lobbying for Moodle to do this same thing (please don't wink, which I've posted about elsewhere).

At a high level, here's what the reporting needs look like as questions to
be answered.

Initial Breakdown
Reports of -

Courses:
Number of Active Courses
Number of Total Courses
Number of Inactive courses?
Courses by file space used
Courses by creation date

User:
Logons and log outs, Usage reports per hour, day, week, term, arbitrary time intervals.
report of users by roles (including custom roles). At Org level, and role enrollment at department and course levels.
Complete course enrollment per student/instructor

At Org level and per course enrollment:
Number of active users
Number of total users
Number of inactive users?

Tools:
Logging actions per tool. Use per user, per tool. Usage reports per hour, day, week, term, arbitrary time intervals. At Org and Course level.
In reply to Dirk Herr-Hoyman

Re: stats package

by Martín Langhoff -
The stats package can already answer most of your questions -- at least the ones I see as most relevant. And it provides a useful framework for you to add the stuff you may want to add. Give the patch a spin, run the log processing over the database of a heavily used website (it'll take hours) and you'll get an interesting view of your Moodle usage.
In reply to Penny Leach

Re: stats package

by Just H -
Hi Penny

This looks excellent, good work smile


Has there been any movement on this or are the links you provided still valid?

Regards
H
In reply to Just H

Re: stats package

by Penny Leach -
Hi Harry! Thanks for your interest.

First, stats has changed quite a bit since those patches, but it is in CVS HEAD, which means it will be in moodle 1.6!

Cheers
Penny
In reply to Penny Leach

Re: stats package

by Julian Ridden -

I (being brave or stupid) am running moodle 1.6 at our school now..and have to say I love the stats package and how you have integrated it with logs.

Trust me when I say that 1.6 is shaping up to be one hell of a release big grin

Great work Penny

In reply to Julian Ridden

Re: stats package

by Penny Leach -
Hey that's fantastic! I've pushed stats out to our largest deployment and we're currently catching up on processing a year of logs..

Thanks! smile
In reply to Penny Leach

Re: stats package

by Just H -
Thanks for the info Penny

Might have to pluck up the courage to dive in there and give it a try!

Regards
H


In reply to Penny Leach

Re: stats package

by Mark Davies -

Hi Penny,

This looks pretty impressive, are there installation instructions somewhere?

Regards,

Mark

In reply to Penny Leach

Re: stats package

by Kunal Kapoor -

I too would be interested in some installation instructions for this. It looks fantastic.

With my best regards,

Kunal

In reply to Kunal Kapoor

Re: stats package

by Penny Leach -
wow, I'm sorry I missed the last request for instructions.

Ok. As of around now I would NOT recommend running it from the patch I posted earlier as it's changed a lot since then.

It WILL be in moodle 1.6, if you're brave you can run it now but bear in mind it is the development version and there will be bugs and things have a habit of changing before they stabilise ;)

So, I say, wait for 1.6 to be out and then just follow the instructions in the admin config variables screen.
In reply to Penny Leach

Re: stats package

by Peter Campbell -
The stats package sounds fantastic! When is Moodle 1.6 scheduled for release? Can someome please direct me to a list of new features and functions that it contains?

Thanks.

Peter