(domain, start_date, end_date, time_zone)
Retrieves counts of SMS sent and received over the given date range
        for the given domain.

        :param domain: the domain
        :param start_date: the start date, as a date type
        :param end_date: the end date (inclusive), as a date type
        :param time_zone: the time zone to use when grouping counts by date,
        as a string type (e.g., 'America/New_York')

        :return: A list of (date, direction, count) named tuples
Retrieves counts of SMS sent and received over the given date range
        for the given domain.
Retrieves counts of SMS sent and received over the given date range for the given domain .
def get_counts_by_date(domain, start_date, end_date, time_zone):
        """
        Retrieves counts of SMS sent and received over the given date range
        for the given domain.

        :param domain: the domain
        :param start_date: the start date, as a date type
        :param end_date: the end date (inclusive), as a date type
        :param time_zone: the time zone to use when grouping counts by date,
        as a string type (e.g., 'America/New_York')

        :return: A list of (date, direction, count) named tuples
        """

        CountTuple = namedtuple('CountTuple', ['date', 'direction', 'sms_count'])

        query = """
        SELECT  (date AT TIME ZONE %s)::DATE AS date,
                direction,
                COUNT(*) AS sms_count
        FROM    sms_sms
        WHERE   domain = %s
        AND     date >= (%s + TIME '00:00') AT TIME ZONE %s
        AND     date < (%s + 1 + TIME '00:00') AT TIME ZONE %s
        AND     (direction = 'I' OR (direction = 'O' and processed))
        GROUP BY 1, 2
        """

        with connection.cursor() as cursor:
            cursor.execute(
                query,
                [time_zone, domain, start_date, time_zone, end_date, time_zone]
            )
            return [CountTuple(*row) for row in cursor.fetchall()]
def get_counts_by_date ( domain , start_date , end_date , time_zone ) : CountTuple = namedtuple ( 'CountTuple' , [ 'date' , 'direction' , 'sms_count' ] ) query = """
        SELECT  (date AT TIME ZONE %s)::DATE AS date,
                direction,
                COUNT(*) AS sms_count
        FROM    sms_sms
        WHERE   domain = %s
        AND     date >= (%s + TIME '00:00') AT TIME ZONE %s
        AND     date < (%s + 1 + TIME '00:00') AT TIME ZONE %s
        AND     (direction = 'I' OR (direction = 'O' and processed))
        GROUP BY 1, 2
        """ with connection . cursor ( ) as cursor : cursor . execute ( query , [ time_zone , domain , start_date , time_zone , end_date , time_zone ] ) return [ CountTuple ( * row ) for row in cursor . fetchall ( ) ]