def sync_month_metric(self, unique_identifier, metric, start_date, end_date):
        """
        Uses the count for each day in the date range to recalculate the counters for the months for
        the ``metric`` for ``unique_identifier``. Useful for updating the counters for week and month after using set_metric_by_day.

        The redis backend supports lists for both ``unique_identifier`` and ``metric`` allowing for the setting of 
        multiple metrics for multiple unique_identifiers efficiently. Not all backends may support this.

        :param unique_identifier: Unique string indetifying the object this metric is for
        :param metric: A unique name for the metric you want to track
        :param start_date: Date syncing starts
        :param end_date: Date syncing end
        """
        metric = [metric] if isinstance(metric, basestring) else metric
        unique_identifier = [unique_identifier] if not isinstance(unique_identifier, (types.ListType, types.TupleType, types.GeneratorType,)) else unique_identifier
        num_months = self._num_months(start_date, end_date)
        first_of_month = datetime.date(year=start_date.year, month=start_date.month, day=1)
        metric_key_date_range = self._get_weekly_date_range(
            first_of_month, relativedelta(months=num_months))

        month_date_generator = (first_of_month + relativedelta(months=i) for i in itertools.count())
        #generate a list of first_of_month's in between the start date and the end date
        months_to_update = list(itertools.islice(month_date_generator, num_months))
        for uid in unique_identifier:
            for single_metric in metric:
                for month in months_to_update:
                    _, series_results = self.get_metric_by_day(uid, single_metric, from_date=month, limit=monthrange(month.year, month.month)[1])
                    month_counter = sum([value for key, value in series_results.items()])

                    hash_key_monthly = self._get_weekly_metric_key(uid, month)
                    monthly_metric_name = self._get_monthly_metric_name(single_metric, month)
                    with self._analytics_backend.map() as conn:
                        conn.hset(hash_key_monthly, monthly_metric_name, month_counter)
def sync_month_metric ( self , unique_identifier , metric , start_date , end_date ) : metric = [ metric ] if isinstance ( metric , basestring ) else metric unique_identifier = [ unique_identifier ] if not isinstance ( unique_identifier , ( types . ListType , types . TupleType , types . GeneratorType , ) ) else unique_identifier num_months = self . _num_months ( start_date , end_date ) first_of_month = datetime . date ( year = start_date . year , month = start_date . month , day = 1 ) metric_key_date_range = self . _get_weekly_date_range ( first_of_month , relativedelta ( months = num_months ) ) month_date_generator = ( first_of_month + relativedelta ( months = i ) for i in itertools . count ( ) ) months_to_update = list ( itertools . islice ( month_date_generator , num_months ) ) for uid in unique_identifier : for single_metric in metric : for month in months_to_update : _ , series_results = self . get_metric_by_day ( uid , single_metric , from_date = month , limit = monthrange ( month . year , month . month ) [ 1 ] ) month_counter = sum ( [ value for key , value in series_results . items ( ) ] ) hash_key_monthly = self . _get_weekly_metric_key ( uid , month ) monthly_metric_name = self . _get_monthly_metric_name ( single_metric , month ) with self . _analytics_backend . map ( ) as conn : conn . hset ( hash_key_monthly , monthly_metric_name , month_counter )
Uses the count for each day in the date range to recalculate the counters for the months for
        the ``metric`` for ``unique_identifier``. Useful for updating the counters for week and month after using set_metric_by_day.

        The redis backend supports lists for both ``unique_identifier`` and ``metric`` allowing for the setting of 
        multiple metrics for multiple unique_identifiers efficiently. Not all backends may support this.

        :param unique_identifier: Unique string indetifying the object this metric is for
        :param metric: A unique name for the metric you want to track
        :param start_date: Date syncing starts
        :param end_date: Date syncing end