code: def collect(since, to, top=DEFAULT_TOP):
      
      summary = CspReportSummary(since, to, top=top)
      queryset = CSPReport.objects.filter(created__range=(since, to))
      valid_queryset = queryset.filter(is_valid=True)
      invalid_queryset = queryset.filter(is_valid=False)
  
      summary.total_count = queryset.count()
      summary.valid_count = valid_queryset.count()
  
      # Collect sources
      sources = {}
      for report in valid_queryset:
          root_uri = get_root_uri(report.document_uri)
          info = sources.setdefault(root_uri, ViolationInfo(root_uri))
          info.append(report)
      summary.sources = sorted(sources.values(), key=attrgetter('count'), reverse=True)[:top]
  
      # Collect blocks
      blocks = {}
      for report in valid_queryset:
          root_uri = get_root_uri(report.blocked_uri)
          info = blocks.setdefault(root_uri, ViolationInfo(root_uri))
          info.append(report)
      summary.blocks = sorted(blocks.values(), key=attrgetter('count'), reverse=True)[:top]
  
      # Collect invalid reports
      summary.invalid_count = invalid_queryset.count()
      summary.invalid_reports = tuple(invalid_queryset[:top])
  
      return summary
docs: Collect the CSP report.
  
      @returntype: CspReportSummary