Files
zulip/zerver/lib/statistics.py
Greg Price 9e5d814610 statistics: Delete a bunch of dead code.
Some of this code was only used by the `active_user_stats`
management command deleted in the previous commit.  Other
code appears to have already been dead.  Remove it all.
2017-07-31 17:06:15 -07:00

23 lines
808 B
Python

# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from zerver.models import UserProfile, UserActivity, UserActivityInterval, Message
from django.utils.timezone import utc
from typing import Any, Dict, List, Sequence, Set
from datetime import datetime, timedelta
# Return the amount of Zulip usage for this user between the two
# given dates
def seconds_usage_between(user_profile, begin, end):
# type: (UserProfile, datetime, datetime) -> timedelta
intervals = UserActivityInterval.objects.filter(user_profile=user_profile, end__gte=begin, start__lte=end)
duration = timedelta(0)
for interval in intervals:
start = max(begin, interval.start)
finish = min(end, interval.end)
duration += finish-start
return duration