def _page_view_stats(): if redis is None: return datetime.datetime.utcnow(), {}, 0 user_keys = redis.keys('gedgo_user_*_page_view_count') users = User.objects.filter( id__in=[int(k.split('_')[2]) for k in user_keys]) user_views = [] for user in users: last = redis.lrange('gedgo_user_%d_page_views' % user.id, 0, 0)[0] pvc = redis.get('gedgo_user_%d_page_view_count' % user.id) user_views.append({ 'user': user, 'last_view': _load_page_view(last)['timestamp'], 'count': pvc }) user_views = sorted(user_views, key=lambda x: x['last_view'], reverse=True) tracking_start = _timestamp_from_redis('gedgo_tracking_start') return tracking_start, user_views, redis.get('gedgo_page_view_count')
def _page_view_stats(): if redis is None: return datetime.datetime.utcnow(), {}, 0 user_keys = redis.keys('gedgo_user_*_page_view_count') users = User.objects.filter( id__in=[int(k.split('_')[2]) for k in user_keys] ) user_views = [] for user in users: last = redis.lrange('gedgo_user_%d_page_views' % user.id, 0, 0)[0] pvc = redis.get('gedgo_user_%d_page_view_count' % user.id) user_views.append({ 'user': user, 'last_view': _load_page_view(last)['timestamp'], 'count': pvc }) user_views = sorted(user_views, key=lambda x: x['last_view'], reverse=True) tracking_start = _timestamp_from_redis('gedgo_tracking_start') return tracking_start, user_views, redis.get('gedgo_page_view_count')
def _increment_key(key_name): try: pvc = int(redis.get(key_name)) except TypeError: pvc = 0 redis.set(key_name, pvc + 1)
def _timestamp_from_redis(key): try: timestamp = redis.get(key) return datetime.datetime.fromtimestamp(int(timestamp)) except Exception: pass