Ejemplo n.º 1
0
    def most_popular_carriers(self,
                              start_date=None,
                              end_date=None,
                              offset=0,
                              limit=25):
        """
        Get a list of the most popular ``Carrier``, optionally
        within a specific date range.

        ``start_date`` and ``end_date`` should be ``datetime`` objects.
        """
        from sms.util import format_date_range

        cursor = connection.cursor()

        query = """
            select 
                count(*) `carrier_weight`,
                `carrier_id`
            from 
                `sms_outboundmessage`
        """

        query += format_date_range(start_date, end_date)

        query += """
            group by 
                `carrier_id`
            order by
                `carrier_weight` desc
            limit %(offset)s,%(limit)s;
        """

        query = query % {'offset': offset, 'limit': limit}

        cursor.execute(query)
        results = cursor.fetchall()

        pks = [result[1] for result in results]
        bulk_dict = Carrier.objects.in_bulk(pks)

        return [bulk_dict[pk] for pk in pks]
Ejemplo n.º 2
0
    def most_popular_carriers(self, start_date=None, end_date=None, offset=0, limit=25):
        """
        Get a list of the most popular ``Carrier``, optionally
        within a specific date range.

        ``start_date`` and ``end_date`` should be ``datetime`` objects.
        """
        from sms.util import format_date_range

        cursor = connection.cursor()

        query = """
            select 
                count(*) `carrier_weight`,
                `carrier_id`
            from 
                `sms_outboundmessage`
        """
            
        query += format_date_range(start_date, end_date)
        
        query += """
            group by 
                `carrier_id`
            order by
                `carrier_weight` desc
            limit %(offset)s,%(limit)s;
        """
        
        query = query % {
            'offset': offset,
            'limit': limit
        }
        
        cursor.execute(query)
        results = cursor.fetchall()

        pks = [result[1] for result in results]
        bulk_dict = Carrier.objects.in_bulk(pks)

        return [bulk_dict[pk] for pk in pks]
Ejemplo n.º 3
0
    def most_contacted_numbers(self,
                               start_date=None,
                               end_date=None,
                               offset=0,
                               limit=25):
        """
        Get a list of the most active ``ContentTypePhoneNumber``s
        """
        from sms.util import format_date_range

        cursor = connection.cursor()

        query = """
            select 
                count(*) `recipient_weight`,
                `phone_number_id`
            from 
                `sms_outboundmessage`
        """

        query += format_date_range(start_date, end_date)

        query += """
            group by 
                `phone_number_id`
            order by
                `recipient_weight` desc
            limit %(offset)s,%(limit)s;
        """

        query = query % {'offset': offset, 'limit': limit}

        cursor.execute(query)
        results = cursor.fetchall()

        pks = [result[1] for result in results]
        bulk_dict = ContentTypePhoneNumber.objects.select_related(
            'content_type').in_bulk(pks)

        return [bulk_dict[pk] for pk in pks]
Ejemplo n.º 4
0
    def most_contacted_numbers(self, start_date=None, end_date=None, offset=0, limit=25):
        """
        Get a list of the most active ``ContentTypePhoneNumber``s
        """
        from sms.util import format_date_range
        
        cursor = connection.cursor()

        query = """
            select 
                count(*) `recipient_weight`,
                `phone_number_id`
            from 
                `sms_outboundmessage`
        """
            
        query += format_date_range(start_date, end_date)
        
        query += """
            group by 
                `phone_number_id`
            order by
                `recipient_weight` desc
            limit %(offset)s,%(limit)s;
        """
        
        query = query % {
            'offset': offset,
            'limit': limit
        }
        
        cursor.execute(query)
        results = cursor.fetchall()

        pks = [result[1] for result in results]
        bulk_dict = ContentTypePhoneNumber.objects.select_related('content_type').in_bulk(pks)

        return [bulk_dict[pk] for pk in pks]