From 5d9f1fcc26d9090e2250fc39543dbff00abf8d3a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 17 Jun 2016 06:32:46 +0300 Subject: add basic "online periods" extraction --- vk/utils/tracking/db/record.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'vk/utils/tracking/db') diff --git a/vk/utils/tracking/db/record.py b/vk/utils/tracking/db/record.py index fd684cc..fd276fc 100644 --- a/vk/utils/tracking/db/record.py +++ b/vk/utils/tracking/db/record.py @@ -102,14 +102,23 @@ class Record(MutableMapping): assert False return record + def _update_last_seen_field(self, last_seen, field): + if field is LastSeenField.TIME: + last_seen[field] = self[field].dt + else: + last_seen[field] = self[field] + + def _update_user_field(self, user, field): + user[field] = self[field] + def to_user(self): user = User() last_seen = LastSeen() for field in self: if isinstance(field, LastSeenField): - last_seen[field] = self[field] + self._update_last_seen_field(last_seen, field) elif isinstance(field, UserField): - user[field] = self[field] + self._update_user_field(user, field) else: assert False if len(last_seen): -- cgit v1.2.3