List Info

Thread: User statistics.




User statistics.
user name
2007-12-27 11:16:16
Hi,

I need to know how long user was on the site, who's online
(user) and
how many guests are online. I was searching for some kind of
django-
module but didn't find anything. Has anyone already
completed module
for that?
(or) How to build that kind of functionality?

Regards.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: User statistics.
user name
2007-12-27 12:23:50
I'm in the process of building a 'session browser.'

1. The 'who is online' function basically asks 'who has
fetched a page
in the last N minutes.' The django_session table has an
expire_date
field which can be converted to a sort of 'time of last
click' by
subtracting the 'cookie lifetime' from the expire date to
get 'date of
last session save.' Something like:
           dateLastClick = session.expire_date -
datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)

2. But the session record is only saved (and, hence its
cookie expire
date is only updated) when there is a change in the values
saved in
the session. You can make it more current by setting
"SESSION_SAVE_EVERY_REQUEST = True" in
settings.py. This will add an
additional DB transaction to each page fetch, which is not a
huge deal
for most sites.

3. We also wanted to do full Click Path Analysis. It seemed
silly to
do more database work just to capture information that was
already in
our Apache logs, but we needed a way to tie specific log
entries to a
particular session. Fortunately there is a trivial way to do
this.
Apache comes with a few predefined log formats. Most people
opt for
the 'combined' format, which adds User-agent and Referer to
the
standard info. What I didn't realize (let's hear it for
TFM!) was that
you can put all kinds of stuff in a log entry.

We created a new log format by adding the Django 'sessionid'
cookie to
the end of the log and then redefined the log format:

     LogFormat "%h %l %u %t "%r" %>s %b
"%i" "%{User-
agent}i" %C" clickpath
     CustomLog logs/www.example.com-access_log clickpath

I don't know how (or if) you can do this on a site where you
can't
modify the server config files.

4. We have two views: one that shows sessions sorted in
various ways
(you can get the session info as a dict by calling
session.get_decoded()), and the other shows a particular
session,
including all of the non-media log entries. We get those
through the
extremely high tech method of grepping for the sessionid in
the log
file. We are still running at fairly low traffic rate (about
6,000
unique sessions per day), but I suspect we will have to
munch the log
into another DB to get decent performance as traffic grows.

   HTH,
   Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: User statistics.
user name
2007-12-27 12:28:57
I've already built this stuff, you have to build a database
model and
a middleware to track user visit and then calculate how long
user was
online.
For online users please have a look at the following posts:

http://gro
ups.google.it/group/django-users/browse_thread/thread/4ba565
2bcbd1f958/958c6e7733a26a9c?hl=it&lnk=gst&q=average+
time&rnum=3#958c6e7733a26a9c


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: User statistics.
user name
2007-12-27 19:11:03
> I've already built this stuff, you have to build a
database model and
> a middleware to track user visit and then calculate how
long user was
> online.

I think we are solving different problems. The code you
point to
creates data which is ephemeral and only addresses 'who is
online'.
The Apache log mod I suggested adds a few bytes to a disk
write that
was going to happen anyway. We are not continuously
analyzing user's
click paths so we prefer to defer processing until an admin
requests
it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )