'Fills in missing months between earlier occurances and now.
Save format: [(\'YYYY-MM, #), ...]
Example output: [(2010-12, 123), (2011-01, 146)]'

def save_feed_story_history_statistics(self, current_counts=None):

    now = datetime.datetime.utcnow()
    min_year = now.year
    total = 0
    month_count = 0
    if (not current_counts):
        current_counts = (self.data.story_count_history and json.decode(self.data.story_count_history))
    if isinstance(current_counts, dict):
        current_counts = current_counts['months']
    if (not current_counts):
        current_counts = []
    map_f = '\n                                                function()    {\n                                                                var    date    =    (this.story_date.getFullYear())    +    "-"    +    (this.story_date.getMonth()+1);\n                                                                var    hour    =    this.story_date.getUTCHours();\n                                                                var    day    =    this.story_date.getDay();\n                                                                emit(this.story_hash,    {\'month\':    date,    \'hour\':    hour,    \'day\':    day});\n                                                }\n                                '
    reduce_f = '\n                                                function(key,    values)    {\n                                                                return    values;\n                                                }\n                                '
    dates = defaultdict(int)
    hours = defaultdict(int)
    days = defaultdict(int)
    results = MStory.objects(story_feed_id=self.pk).map_reduce(map_f, reduce_f, output='inline')
    for result in results:
        dates[result.value['month']] += 1
        hours[int(result.value['hour'])] += 1
        days[int(result.value['day'])] += 1
        year = int(re.findall('(\\d{4})-\\d{1,2}', result.value['month'])[0])
        if ((year < min_year) and (year > 2000)):
            min_year = year
    for (current_month, current_count) in current_counts:
        year = int(re.findall('(\\d{4})-\\d{1,2}', current_month)[0])
        if ((current_month not in dates) or (dates[current_month] < current_count)):
            dates[current_month] = current_count
        if ((year < min_year) and (year > 2000)):
            min_year = year
    months = []
    start = False
    for year in range(min_year, (now.year + 1)):
        for month in range(1, (12 + 1)):
            if (datetime.datetime(year, month, 1) < now):
                key = (u'%s-%s' % (year, month))
                if (dates.get(key) or start):
                    start = True
                    months.append((key, dates.get(key, 0)))
                    total += dates.get(key, 0)
                    month_count += 1
    original_story_count_history = self.data.story_count_history
    self.data.story_count_history = json.encode({'months': months, 'hours': hours, 'days': days})
    if (self.data.story_count_history != original_story_count_history):
        self.data.save(update_fields=['story_count_history'])
    original_average_stories_per_month = self.average_stories_per_month
    if ((not total) or (not month_count)):
        self.average_stories_per_month = 0
    else:
        self.average_stories_per_month = int(round((total / float(month_count))))
    if (self.average_stories_per_month != original_average_stories_per_month):
        self.save(update_fields=['average_stories_per_month'])
