def get_last_open_session(self, dtime, uid): dt = day_serialize(dtime) try: return self.data_per_days[dt][uid][-1] except (KeyError, IndexError) as no_sessions: # session may break at midnight as we're looking on daily basis prev_dt = day_serialize(dtime - datetime.timedelta(days=1)) try: return self.data_per_days[prev_dt][uid][-1] except (KeyError, IndexError) as no_prev_day_sessions: # we assume we have no sessions # with more than a 24-hour duration return
def create_broken_session(self, dtime, uid): dt = day_serialize(dtime) session = Session(start=dtime, mode=self._users2modes.get(uid, None), is_broken=True) self.data_per_days[dt].setdefault(uid, []).append(session) return session
def create_broken_session(self, dtime, uid): dt = day_serialize(dtime) session = Session( start=dtime, mode=self._users2modes.get(uid, None), is_broken=True ) self.data_per_days[dt].setdefault(uid, []).append(session) return session
def process_unspecified(self, event): dte = day_serialize(event.event_time.dtime.date()) if event.event_time.is_accurate: self.dates[dte]['users'].add(event.user_info.uid) self.dates[dte]['events'] += 1
def get_session_history(self, dtime, uid): return self.data_per_days[day_serialize(dtime)].setdefault(uid, [])
def process_unspecified(self, event): dte = day_serialize(event.event_time.dtime.date()) if event.event_time.is_accurate: self.dates[dte]["users"].add(event.user_info.uid) self.dates[dte]["events"] += 1