Ejemplo n.º 1
0
 def test_size_of_logs_in_cache(self):
     """
     [recommendation.cache.SimpleLogger] Test size of cache is 10 for all users in system
     """
     for user in USERS:
         user = User.get_user_by_external_id(user["external_id"])
         assert len(LogEntry.get_logs_for(user.pk)) == 10, \
             "logs size are bigger than predicted (%s != 10)" % len(LogEntry.get_logs_for(user.pk))
Ejemplo n.º 2
0
 def test_size_of_logs_in_cache(self):
     """
     [recommendation.cache.SimpleLogger] Test size of cache is 10 for all users in system
     """
     for user in USERS:
         user = User.get_user_by_external_id(user["external_id"])
         assert len(LogEntry.get_logs_for(user.pk)) == 10, \
             "logs size are bigger than predicted (%s != 10)" % len(LogEntry.get_logs_for(user.pk))
Ejemplo n.º 3
0
 def bulk_load(self, user, recommendation):
     try:
         new_logs = [
             LogEntry(user=user, item_id=iid, type=self.log_type, value=i)
             for i, iid in enumerate(recommendation, start=1)
         ]
         LogEntry.objects.bulk_create(new_logs)
         LogEntry.add_logs(user, new_logs)
     except Exception:
         logging.error(logging.error(traceback.format_exc()))
     else:
         logging.debug("Recommendation logged for user %s" %
                       user.external_id)
Ejemplo n.º 4
0
 def __call__(self, user, recommendation, size=4, **kwargs):
     """
     Calculate the new rank based on logs
     """
     logs = LogEntry.get_logs_for(user.pk)
     #m = recommendation.mean()
     #print m
     #rec = {v: k for k, v in enumerate(recommendation, start=1)}
     for log in logs:
         try:
             recommendation[log.item_id-1] += (self.evaluate(log, size) * 0.01)
         except IndexError:
             pass
     return recommendation
Ejemplo n.º 5
0
 def __call__(self, user, recommendation, size=4, **kwargs):
     """
     Calculate the new rank based on logs
     """
     logs = LogEntry.get_logs_for(user.pk)
     #m = recommendation.mean()
     #print m
     #rec = {v: k for k, v in enumerate(recommendation, start=1)}
     for log in logs:
         try:
             recommendation[log.item_id - 1] += (self.evaluate(log, size) *
                                                 0.01)
         except IndexError:
             pass
     return recommendation