Ejemplo n.º 1
0
    def boost_model(self, obj, indexed_data):
        """ We boost a combined measure of 2 added factors: newness (50%) and like count (50%).
            This means that a new idea with lots of likes will rank highest and an old idea with no likes lowest.
            But it also means that new ideas with no likes will still rank quite high, as will old ideas with lots
            of likes.
            
            Factors:
            - 50%: the idea's like count, normalized over the mean/stddev of the like count of all other ideas, 
                in a range of [0.0..1.0]
            - 50%: the idea's created date, highest being now() and lowest >= 3 months
            """
        def qs_func():
            return CosinnusIdea.objects.all_in_portal().annotate_likes()

        mean, stddev = self.get_mean_and_stddev(qs_func,
                                                'like_count',
                                                non_annotated_property=True)
        current_like_count = obj.likes.filter(liked=True).count()
        members_rank_from_likes = normalize_within_stddev(current_like_count,
                                                          mean,
                                                          stddev,
                                                          stddev_factor=1.0)

        age_timedelta = now() - obj.created
        members_rank_from_date = max(1.0 - (age_timedelta.days / 90.0), 0)

        return (members_rank_from_likes / 2.0) + (members_rank_from_date / 2.0)
Ejemplo n.º 2
0
    def boost_model(self, obj, indexed_data):
        """ We boost a combined measure of 2 added factors: soonishnes (50%) and participant count (50%).
            This means that a soon happening event with lots of participants will rank highest and an far off event 
            with no participants lowest.
            But it also means that soon happening events with no participants will still rank quite high, 
            as will far off events with lots of participants.
            
            Factors:
            - 50%: the event's participant count, normalized over the mean/stddev of the participant count of all 
                other events, in a range of [0.0..1.0]
            - 50%: the event's date, highest being now() and lowest >= 12 months from now
            """
        def qs_func():
            return annotate_attendants_count(Event.get_current_for_portal())

        mean, stddev = self.get_mean_and_stddev(qs_func,
                                                'attendants_count',
                                                non_annotated_property=True)
        current_participant_count = self.prepare_participant_count(obj)
        rank_from_participants = normalize_within_stddev(
            current_participant_count, mean, stddev, stddev_factor=1.0)

        if obj.from_date:
            future_date_timedelta = obj.from_date - now()
            if future_date_timedelta.days < 0:
                rank_from_date = 0.0  # past events rank worst
            else:
                rank_from_date = max(
                    1.0 - (future_date_timedelta.days / 365.0), 0)
        else:
            rank_from_date = 0.0

        return (rank_from_participants / 2.0) + (rank_from_date / 2.0)
Ejemplo n.º 3
0
    def boost_model(self, obj, indexed_data):
        """ We boost a combined measure of 2 added factors: newness (50%) and group member rank (50%).
            This means that a new group with lots of members will rank highest and an old group with no members lowest.
            But it also means that new groups with no members will still rank quite high, as will old groups with lots
            of members.
            
            Factors:
            - 50%: number of members this group has, normalized over
            the mean/stddev of the member count of all groups in this portal (excluded the Forum!), 
            in a range of [0.0..1.0]
            - 50%: the group's created date, highest being now() and lowest >= 3 months
            """
        group = obj
        forum_slug = getattr(settings, 'NEWW_FORUM_GROUP_SLUG', None)

        def qs_func():
            qs = get_cosinnus_group_model().objects.all_in_portal()
            if forum_slug:
                qs = qs.exclude(slug=forum_slug)
            return qs

        mean, stddev = self.get_mean_and_stddev(qs_func, 'memberships')
        group_member_count = group.actual_members.count()
        members_rank = normalize_within_stddev(group_member_count,
                                               mean,
                                               stddev,
                                               stddev_factor=1.0)

        age_timedelta = now() - obj.created
        group_newness = max(1.0 - (age_timedelta.days / 90.0), 0)

        return (members_rank / 2.0) + (group_newness / 2.0)
Ejemplo n.º 4
0
    def boost_model(self, obj, indexed_data):
        """ We boost by number of groups the user is a member of, normalized over
            the mean/stddev of the count of groups each portal user is a members of, 
            in a range of [0.0..1.0] """
        def qs_func():
            return filter_portal_users(
                filter_active_users(get_user_model().objects.all()))

        mean, stddev = self.get_mean_and_stddev(qs_func,
                                                'cosinnus_memberships')
        user_memberships_count = self._get_memberships_count(obj)
        memberships_rank = normalize_within_stddev(user_memberships_count,
                                                   mean,
                                                   stddev,
                                                   stddev_factor=2.0)
        return memberships_rank
Ejemplo n.º 5
0
 def boost_model(self, obj, indexed_data):
     """ We boost by number of members the tagged objects's group has, normalized over
         the mean/stddev of the member count of all groups in this portal (excluded the Forum!), 
         in a range of [0.0..1.0].
         Special case: Events in the Forum always return 0.5! (Because everyone is in the Forum
         so it should be average. """
     group = obj.group
     forum_slug = getattr(settings, 'NEWW_FORUM_GROUP_SLUG', None)
     if group.slug == forum_slug:
         return 0.5
     
     def qs_func():
         qs = get_cosinnus_group_model().objects.all_in_portal()
         if forum_slug:
             qs = qs.exclude(slug=forum_slug)
         return qs
     
     mean, stddev = self.get_mean_and_stddev(qs_func, 'memberships')
     group_member_count = group.actual_members.count()
     members_rank = normalize_within_stddev(group_member_count, mean, stddev, stddev_factor=1.0)
     return members_rank