def create_from_post_data(cls, session, data, user): _time = data['time'] time = datetime.strptime(_time, JSON_TIME_FORMAT) event = data['event'] value = data['value'] extra_data = data['extra_data'] if extra_data == '{}': extra_data = '' article_id = None has_article_id = False if data['article_id'] != '': article_id = int(data['article_id']) has_article_id = True zeeguu.log( f'{event} value[:42]: {value[:42]} extra_data[:42]: {extra_data[:42]} art_id: {article_id}' ) new_entry = UserActivityData(user, time, event, value, extra_data, has_article_id, article_id) session.add(new_entry) session.commit() if has_article_id: UserReadingSession.update_reading_session(session, event, user.id, article_id, current_time=time)
def test__update_reading_session_scenario3(self): event = UMR_OPEN_ARTICLE_ACTION self.read_session.last_action_time = self.TWICE_TIMEOUT_MINUTES_IN_THE_PAST resulting_reading_session = UserReadingSession.update_reading_session( db_session, event, self.read_session.user_id, self.read_session.article_id) assert resulting_reading_session != self.read_session
def test__update_reading_session_scenario1(self): event = UMR_OPEN_ARTICLE_ACTION self.read_session.is_active = False resulting_reading_session = UserReadingSession.update_reading_session( db_session, event, self.read_session.user_id, self.read_session.article_id) assert resulting_reading_session != self.read_session
def test__update_reading_session_scenario4(self): event = UMR_ARTICLE_CLOSED_ACTION resulting_reading_session = UserReadingSession.update_reading_session( db_session, event, self.read_session.user_id, self.read_session.article_id) assert (resulting_reading_session == self.read_session) and (self.read_session.is_active == False)
def test_find_most_recent_session_with_empty_article(self): event = UMR_OPEN_ARTICLE_ACTION user_id = self.read_session.user_id article_id = None self.read_session.last_action_time = self.TIMEOUT_MINUTES_IN_THE_PAST resulting_reading_session = UserReadingSession.update_reading_session( db_session, event, user_id, article_id) assert resulting_reading_session == self.read_session
def test__update_reading_session_scenario5(self): event = UMR_ARTICLE_CLOSED_ACTION self.read_session.last_action_time = self.TWICE_TIMEOUT_MINUTES_IN_THE_PAST resulting_reading_session = UserReadingSession.update_reading_session( db_session, event, self.read_session.user_id, self.read_session.article_id) assert (resulting_reading_session == self.read_session and resulting_reading_session.is_active == False)
all_data = UserActivityData.find() data = [each for each in all_data if each.id > 77420] count = 0 for user_action in data: # Special case that causes a DB exception because of non supported symbols from the article if user_action.id not in EXCLUDED_IDS: # NOTE: Not all scenarios include the url user = user_action.user_id time = user_action.time try: UserReadingSession.update_reading_session( db_session, user_action.event, user, user_action.get_article_id(db_session), current_time=time) count += 1 print( str(count) + " " + str(datetime.now()) + " " + str(user_action.id)) except Exception as e: print(f"caught exception for {user_action.id} ...") import traceback print(traceback.format_exc()) db_session.rollback()