Esempio n. 1
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]
   )
Esempio n. 3
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))))
Esempio n. 4
0
 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
         ])
Esempio n. 5
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
   )
Esempio n. 6
0
 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
Esempio n. 7
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)
Esempio n. 8
0
 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)
   )
Esempio n. 9
0
 def is_moderately_relevant(self):
   return _memoize_attr(
       self,
       '_is_moderately_relevant',
       lambda: self.relevance_level == 1
   )
Esempio n. 10
0
 def is_highly_relevant(self):
   return _memoize_attr(
       self,
       '_is_highly_relevant',
       lambda: self.relevance_level == 2
   )
Esempio n. 11
0
 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)
   )
Esempio n. 12
0
 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)
   )
Esempio n. 14
0
 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))
Esempio n. 15
0
 def sorted_queries(self):
   return _memoize_attr(
       self,
       '_sorted_queries',
       lambda: sorted(self.queries.values(), key=lambda q: q.get_start_timestamp())
   )
Esempio n. 16
0
 def last_rank_reached(self):
   return _memoize_attr(
       self,
       '_last_rank_reached',
       lambda: self._calculate_last_rank_reached()
   )
Esempio n. 17
0
 def is_moderately_relevant(self):
     return _memoize_attr(self, '_is_moderately_relevant',
                          lambda: self.relevance_level == 1)
Esempio n. 18
0
 def is_highly_relevant(self):
     return _memoize_attr(self, '_is_highly_relevant',
                          lambda: self.relevance_level == 2)
Esempio n. 19
0
 def seconds_elapsed_at(self, timestamp):
     return _memoize_attr(
         self, '_seconds_elapsed_at_' + str(timestamp), lambda:
         (timestamp - self.get_start_timestamp()).total_seconds())
Esempio n. 20
0
 def seconds_elapsed_at(self, timestamp):
   return _memoize_attr(
       self,
       '_seconds_elapsed_at_' + str(timestamp),
       lambda: (timestamp - self.get_start_timestamp()).total_seconds()
   )
Esempio n. 21
0
 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)]))
   )