zeeguu/core/model/word_knowledge/word_interaction_history.py
def insert_event(self, event_type, timestamp, timedelta = TIMEDELTA):
        """
            inserts the event in the sorted list

            add a new event, compares to previous events in order to only store most recent events

            and avoid duplicate events
        :param event_type:
        :param timestamp:
        :return:
        """

        # json can't serialize timestamps, so we simply
        if platform == "win32":
            seconds_since_epoch = int(timestamp.timestamp())
        else:
            seconds_since_epoch = int(timestamp.strftime("%s"))

        # Don't add event if it already occurs
        if self.time_exists(timestamp):
            return

        if len(self.interaction_history) == 0:
            self.interaction_history.append(WordInteractionEvent(event_type, seconds_since_epoch))

        # change event if latest event was already recorded within the timedelta
        elif self.interaction_history[-1].seconds_since_epoch + timedelta >= seconds_since_epoch and\
                (event_type == WIH_READ_CLICKED or event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE):
            self.interaction_history[-1].seconds_since_epoch = seconds_since_epoch
            if event_type == WIH_READ_CLICKED:
                self.interaction_history[-1].event_type = event_type

        # append if less than 50 events recorded
        elif len(self.interaction_history) < MAX_EVENT_HISTORY_LENGTH:
            self.interaction_history.append(WordInteractionEvent(event_type, seconds_since_epoch))
            self.interaction_history.sort(key=lambda x: x.seconds_since_epoch)

        # otherwise only insert if oldest event is older than new event
        elif seconds_since_epoch > self.interaction_history[0].seconds_since_epoch:
            self.interaction_history[0] = WordInteractionEvent(event_type, seconds_since_epoch)
            self.interaction_history.sort(key=lambda x: x.seconds_since_epoch)

            inserts the event in the sorted list

            add a new event, compares to previous events in order to only store most recent events

            and avoid duplicate events
        :param event_type:
        :param timestamp:
        :return:
        
inserts the event in the sorted list
add a new event, compares to previous events in order to only store most recent events

and avoid duplicate events
inserts the event in the sorted list add a new event compares to previous events in order to only store most recent events and avoid duplicate events
def insert_event(self, event_type, timestamp, timedelta = TIMEDELTA):
        if platform == "win32":
            seconds_since_epoch = int(timestamp.timestamp())
        else:
            seconds_since_epoch = int(timestamp.strftime("%s"))
        if self.time_exists(timestamp):
            return
        if len(self.interaction_history) == 0:
            self.interaction_history.append(WordInteractionEvent(event_type, seconds_since_epoch))
        elif self.interaction_history[-1].seconds_since_epoch + timedelta >= seconds_since_epoch and\
                (event_type == WIH_READ_CLICKED or event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE):
            self.interaction_history[-1].seconds_since_epoch = seconds_since_epoch
            if event_type == WIH_READ_CLICKED:
                self.interaction_history[-1].event_type = event_type
        elif len(self.interaction_history) < MAX_EVENT_HISTORY_LENGTH:
            self.interaction_history.append(WordInteractionEvent(event_type, seconds_since_epoch))
            self.interaction_history.sort(key=lambda x: x.seconds_since_epoch)
        elif seconds_since_epoch > self.interaction_history[0].seconds_since_epoch:
            self.interaction_history[0] = WordInteractionEvent(event_type, seconds_since_epoch)
            self.interaction_history.sort(key=lambda x: x.seconds_since_epoch)
def insert_event ( self , event_type , timestamp , timedelta = TIMEDELTA ) : if platform == "win32" : seconds_since_epoch = int ( timestamp . timestamp ( ) ) else : seconds_since_epoch = int ( timestamp . strftime ( "%s" ) ) if self . time_exists ( timestamp ) : return if len ( self . interaction_history ) == 0 : self . interaction_history . append ( WordInteractionEvent ( event_type , seconds_since_epoch ) ) elif self . interaction_history [ - 1 ] . seconds_since_epoch + timedelta >= seconds_since_epoch and ( event_type == WIH_READ_CLICKED or event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE ) : self . interaction_history [ - 1 ] . seconds_since_epoch = seconds_since_epoch if event_type == WIH_READ_CLICKED : self . interaction_history [ - 1 ] . event_type = event_type elif len ( self . interaction_history ) < MAX_EVENT_HISTORY_LENGTH : self . interaction_history . append ( WordInteractionEvent ( event_type , seconds_since_epoch ) ) self . interaction_history . sort ( key = lambda x : x . seconds_since_epoch ) elif seconds_since_epoch > self . interaction_history [ 0 ] . seconds_since_epoch : self . interaction_history [ 0 ] = WordInteractionEvent ( event_type , seconds_since_epoch ) self . interaction_history . sort ( key = lambda x : x . seconds_since_epoch )
inserts the event in the sorted list
add a new event, compares to previous events in order to only store most recent events
inserts the event in the sorted list add a new event compares to previous events in order to only store most recent events
"""
            inserts the event in the sorted list

            add a new event, compares to previous events in order to only store most recent events

            and avoid duplicate events
        :param event_type:
        :param timestamp:
        :return:
        """ # json can't serialize timestamps, so we simply # Don't add event if it already occurs # change event if latest event was already recorded within the timedelta # append if less than 50 events recorded # otherwise only insert if oldest event is older than new event
None
self
event_type
None
timestamp
None
timedelta