(self, db, link_id)
return dict(
            hits=self.link_hit_count(bind_param),
            country_hits=self.country_aggregate(bind_param),
            referrer_hits=self.referrer_aggregate(bind_param),
            timestamp_hits=self.date_aggregate(date_part, bind_param, base),
            time_base=base
        )
Function to get click aggregation data based on:
            1. Country
            2. Referrer
            3. Datetime: It can be based on minute, hour, or days depending
                on how old the link clickstats are.

        :param db:
        :param link_id:
        :return: dict
Function to get click aggregation data based on:
            1. Country
            2. Referrer
            3. Datetime: It can be based on minute, hour, or days depending
                on how old the link clickstats are.
Function to get click aggregation data based on : 1 . Country 2 . Referrer 3 . Datetime : It can be based on minute hour or days depending on how old the link clickstats are .
def click_stats(self, db, link_id):
        """Function to get click aggregation data based on:
            1. Country
            2. Referrer
            3. Datetime: It can be based on minute, hour, or days depending
                on how old the link clickstats are.

        :param db:
        :param link_id:
        :return: dict
        """
        bind_param = dict(link_id=link_id,
                          created_at=self.past_30th_date)
        assert db.bind.name in ['sqlite', 'mysql', 'postgresql']
        db_date_function_mapper = dict(sqlite='STRFTIME',
                                       postgresql='TO_CHAR',
                                       mysql='DATE_FORMAT')
        date_func = db_date_function_mapper.get(db.bind.name)
        # if None, it means no record found for the link
        oldest_link_date = self.oldest_click_date(bind_param)
        if oldest_link_date is None:
            return {}
        base = time_base(oldest_link_date)
        date_format = self._date_display_format(base)
        if db.bind.name == 'postgresql':
            date_format = self.psql_date_format(date_format)
            date_part = "{}(created_at, '{}')".format(date_func, date_format)
        elif db.bind.name == 'mysql':
            date_format = self.mysql_date_format(date_format)
            date_part = "{}(created_at, '{}')".format(date_func, date_format)
        else:
            date_part = "{}('{}', created_at)".format(date_func, date_format)
        return dict(
            hits=self.link_hit_count(bind_param),
            country_hits=self.country_aggregate(bind_param),
            referrer_hits=self.referrer_aggregate(bind_param),
            timestamp_hits=self.date_aggregate(date_part, bind_param, base),
            time_base=base
        )
def click_stats ( self , db , link_id ) : bind_param = dict ( link_id = link_id , created_at = self . past_30th_date ) assert db . bind . name in [ 'sqlite' , 'mysql' , 'postgresql' ] db_date_function_mapper = dict ( sqlite = 'STRFTIME' , postgresql = 'TO_CHAR' , mysql = 'DATE_FORMAT' ) date_func = db_date_function_mapper . get ( db . bind . name ) # if None, it means no record found for the link oldest_link_date = self . oldest_click_date ( bind_param ) if oldest_link_date is None : return { } base = time_base ( oldest_link_date ) date_format = self . _date_display_format ( base ) if db . bind . name == 'postgresql' : date_format = self . psql_date_format ( date_format ) date_part = "{}(created_at, '{}')" . format ( date_func , date_format ) elif db . bind . name == 'mysql' : date_format = self . mysql_date_format ( date_format ) date_part = "{}(created_at, '{}')" . format ( date_func , date_format ) else : date_part = "{}('{}', created_at)" . format ( date_func , date_format ) return dict ( hits = self . link_hit_count ( bind_param ) , country_hits = self . country_aggregate ( bind_param ) , referrer_hits = self . referrer_aggregate ( bind_param ) , timestamp_hits = self . date_aggregate ( date_part , bind_param , base ) , time_base = base )