Mercurial > public > sg101
comparison gpp/core/management/commands/max_users.py @ 519:f72ace06658a
For #194, rework the who's online and max users functions.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 17 Dec 2011 19:29:24 +0000 |
parents | 3fe60148f75c |
children |
comparison
equal
deleted
inserted
replaced
518:5171a5e9353b | 519:f72ace06658a |
---|---|
5 """ | 5 """ |
6 import datetime | 6 import datetime |
7 | 7 |
8 from django.core.management.base import NoArgsCommand | 8 from django.core.management.base import NoArgsCommand |
9 | 9 |
10 from core.models import Statistic | 10 from core.whos_online import max_users |
11 from core.whos_online import get_users_online, get_visitors_online, tick | |
12 | 11 |
13 | 12 |
14 class Command(NoArgsCommand): | 13 class Command(NoArgsCommand): |
15 help = "Run periodically to compute the max users online statistic." | 14 help = "Run periodically to compute the max users online statistic." |
16 | 15 |
17 def handle_noargs(self, **options): | 16 def handle_noargs(self, **options): |
18 | 17 max_users() |
19 now = datetime.datetime.now() | |
20 | |
21 users = len(get_users_online()) | |
22 guests = len(get_visitors_online()) | |
23 | |
24 updated = False | |
25 try: | |
26 stat = Statistic.objects.get(pk=1) | |
27 except Statistic.DoesNotExist: | |
28 stat = Statistic(max_users=users, | |
29 max_users_date=now, | |
30 max_anon_users=guests, | |
31 max_anon_users_date=now) | |
32 updated=True | |
33 else: | |
34 if users > stat.max_users: | |
35 stat.max_users = users | |
36 stat.max_users_date = now | |
37 updated=True | |
38 if guests > stat.max_anon_users: | |
39 stat.max_anon_users = guests | |
40 stat.max_anon_users_date = now | |
41 updated=True | |
42 | |
43 if updated: | |
44 stat.save() | |
45 | |
46 # "tick" the who's online data collector | |
47 tick() |