code: def get_bug_stats(self, startday, endday):
          
          # Min required failures per bug in order to post a comment
          threshold = 1 if self.weekly_mode else 15
          bug_ids = (BugJobMap.failures.by_date(startday, endday)
                                       .values('bug_id')
                                       .annotate(total=Count('bug_id'))
                                       .filter(total__gte=threshold)
                                       .values_list('bug_id', flat=True))
  
          bugs = (BugJobMap.failures.by_date(startday, endday)
                                    .filter(bug_id__in=bug_ids)
                                    .values('job__repository__name', 'job__machine_platform__platform',
                                            'bug_id'))
  
          bug_map = dict()
          for bug in bugs:
              platform = bug['job__machine_platform__platform']
              repo = bug['job__repository__name']
              bug_id = bug['bug_id']
              if bug_id in bug_map:
                  bug_map[bug_id]['total'] += 1
                  bug_map[bug_id]['per_platform'][platform] += 1
                  bug_map[bug_id]['per_repository'][repo] += 1
              else:
                  bug_map[bug_id] = {}
                  bug_map[bug_id]['total'] = 1
                  bug_map[bug_id]['per_platform'] = Counter([platform])
                  bug_map[bug_id]['per_repository'] = Counter([repo])
  
          return bug_map, bug_ids
docs: Get all intermittent failures per specified date range and repository,
             returning a dict of bug_id's with total, repository and platform totals
             if totals are greater than or equal to the threshold.
          eg:
          {
              "1206327": {
                  "total": 5,
                  "per_repository": {
                      "fx-team": 2,
                      "mozilla-inbound": 3
                  },
                  "per_platform": {
                      "osx-10-10": 4,
                      "b2g-emu-ics": 1
                  }
              },
              ...
          }