aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vk/utils/tracking/online_streaks.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-06-18 05:07:03 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-06-18 05:07:03 +0300
commit1b2a23964748366b14c5d5538d881bdb6d160ef7 (patch)
tree2de336ba438f1ea963f264a1657f4905c38f3d21 /vk/utils/tracking/online_streaks.py
parent"online periods" are called "online streaks" now (diff)
downloadvk-scripts-1b2a23964748366b14c5d5538d881bdb6d160ef7.tar.gz
vk-scripts-1b2a23964748366b14c5d5538d881bdb6d160ef7.zip
online_streak_duration.py: grouping by date/wday
Diffstat (limited to '')
-rw-r--r--vk/utils/tracking/online_streaks.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/vk/utils/tracking/online_streaks.py b/vk/utils/tracking/online_streaks.py
index 7523750..dfac0be 100644
--- a/vk/utils/tracking/online_streaks.py
+++ b/vk/utils/tracking/online_streaks.py
@@ -5,9 +5,22 @@
from collections import OrderedDict
from collections.abc import MutableMapping
from datetime import timedelta
+from enum import Enum
from vk.user import User
+class Weekday(Enum):
+ MONDAY = 0
+ TUESDAY = 1
+ WEDNESDAY = 2
+ THURSDAY = 3
+ FRIDAY = 4
+ SATURDAY = 5
+ SUNDAY = 6
+
+ def __str__(self):
+ return self.name[0] + self.name[1:].lower()
+
class OnlineStreakEnumerator(MutableMapping):
def __init__(self):
self._records = {}
@@ -52,11 +65,11 @@ class OnlineStreakEnumerator(MutableMapping):
def group_by_weekday(self, db_reader):
by_weekday = OrderedDict()
- for weekday in range(7):
+ for weekday in Weekday:
by_weekday[weekday] = timedelta()
for _, time_from, time_to in self.enum(db_reader):
for date, duration in self._enum_dates_and_durations(time_from, time_to):
- by_weekday[date.weekday()] += duration
+ by_weekday[Weekday(date.weekday())] += duration
return by_weekday
@staticmethod
@@ -81,7 +94,6 @@ class OnlineStreakEnumerator(MutableMapping):
self[user] = user
return None
if user.is_online():
- print(user._fields)
return None
period = user, self[user].get_last_seen_time(), user.get_last_seen_time()
self[user] = user