def actions_in_continuous_rank_order(self): # FIXME: multiplying query order nr by 1M is just a silly hack return _memoize_attr( self, '_actions_in_continuous_rank_order', lambda: sorted( self.actions, key=lambda action: action.query.order_number() * 1000000 + int( getattr(action, 'rank', sys.maxsize))))
def gain_events(self, gain_levels): possible_gain_actions = self.document_marked_relevant_actions() return _memoize_attr( self, '_gain_events', lambda: [self.create_gain_pair(action, gain_levels) for (idx, action) in possible_gain_actions if action.gain(gain_levels) > 0] )
def actions_in_continuous_rank_order(self): # FIXME: multiplying query order nr by 1M is just a silly hack return _memoize_attr(self, '_actions_in_continuous_rank_order', lambda: sorted(self.actions, key=lambda action: action.query.order_number() * 1000000 + int(getattr( action, 'rank', sys.maxsize))))
def gain_events(self, gain_levels): possible_gain_actions = self.document_marked_relevant_actions() return _memoize_attr( self, '_gain_events', lambda: [ self.create_gain_pair(action, gain_levels) for (idx, action) in possible_gain_actions if action.gain(gain_levels) > 0 ])
def get_start_timestamp(self): # No actions? if len(self.actions) == 0: return None return _memoize_attr( self, '_start_timestamp', lambda: self.actions[0].timestamp )
def get_relevance_for_topic_id(self, topic_id): rel = _memoize_attr( self, '_relevance_for_topic_id_' + str(topic_id), lambda: self.relevances.get(str(topic_id)) ) if rel is None: raise RuntimeError("ERROR: document ID %s, topic ID %s relevance cannot be determined!" % (self.record_id, topic_id)) return rel
def get_start_timestamp(self): # No actions? if len(self.actions) == 0: return None return _memoize_attr(self, '_start_timestamp', lambda: self.actions[0].timestamp)
def queries_prior_to(self, test_query): return _memoize_attr( self, '_queries_prior_to_' + str(test_query.record_id), lambda: self._calculate_queries_prior_to(test_query) )
def is_moderately_relevant(self): return _memoize_attr( self, '_is_moderately_relevant', lambda: self.relevance_level == 1 )
def is_highly_relevant(self): return _memoize_attr( self, '_is_highly_relevant', lambda: self.relevance_level == 2 )
def actions_by_type_before_rank(self, action_type, rank): return _memoize_attr( self, '_actions_by_' + str(action_type) + '_type_before_rank_' + str(rank), lambda: self._calculate_actions_by_type_before_rank(action_type, rank) )
def actions_by_type_until(self, action_type, seconds): return _memoize_attr( self, '_actions_by_' + str(action_type) + '_type_until_' + str(seconds), lambda: self._calculate_actions_by_type_until(action_type, seconds) )
def rank_of(self, document): return _memoize_attr( self, '_rank_of_' + str(document.record_id), lambda: self._calculate_rank_of(document) )
def actions_by_type_until(self, action_type, seconds): return _memoize_attr( self, '_actions_by_' + str(action_type) + '_type_until_' + str(seconds), lambda: self._calculate_actions_by_type_until( action_type, seconds))
def sorted_queries(self): return _memoize_attr( self, '_sorted_queries', lambda: sorted(self.queries.values(), key=lambda q: q.get_start_timestamp()) )
def last_rank_reached(self): return _memoize_attr( self, '_last_rank_reached', lambda: self._calculate_last_rank_reached() )
def is_moderately_relevant(self): return _memoize_attr(self, '_is_moderately_relevant', lambda: self.relevance_level == 1)
def is_highly_relevant(self): return _memoize_attr(self, '_is_highly_relevant', lambda: self.relevance_level == 2)
def seconds_elapsed_at(self, timestamp): return _memoize_attr( self, '_seconds_elapsed_at_' + str(timestamp), lambda: (timestamp - self.get_start_timestamp()).total_seconds())
def seconds_elapsed_at(self, timestamp): return _memoize_attr( self, '_seconds_elapsed_at_' + str(timestamp), lambda: (timestamp - self.get_start_timestamp()).total_seconds() )
def actions_by_type_before_rank(self, action_type, rank): return _memoize_attr( self, '_actions_by_' + str(action_type) + '_type_before_rank_' + str(rank), lambda: self._calculate_actions_by_type_before_rank( action_type, rank))
def highly_relevant_results_up_to_rank(self, rank): return _memoize_attr( self, '_highly_relevant_results_up_to_rank_' + str(rank), lambda: list(filter(lambda result_document: result_document.is_highly_relevant_for_topic(self.query.topic), self.result_documents[:int(rank)])) )