Пример #1
0
def aggregate_coverage_data(pk, pks):
    from covmanager.models import Collection, CollectionFile  # noqa
    from FTB import CoverageHelper  # noqa

    # Fetch our existing, but incomplete destination collection
    mergedCollection = Collection.objects.get(pk=pk)

    # Fetch all source collections
    collections = Collection.objects.filter(pk__in=pks)

    # Merge the coverage of all other collections into the first one
    first_collection = collections[0]
    first_collection.loadCoverage()
    newCoverage = first_collection.content
    total_stats = None

    for collection in collections[1:]:
        # Load coverage, perform the merge, then release reference to the JSON blob again
        collection.loadCoverage()
        stats = CoverageHelper.merge_coverage_data(newCoverage,
                                                   collection.content)
        collection.content = None

        # Merge stats appropriately
        if total_stats is None:
            total_stats = stats
        else:
            for x in total_stats:
                total_stats[x] += stats[x]

    # Save the new coverage blob to disk and database
    newCoverage = json.dumps(newCoverage, separators=(',', ':'))
    h = hashlib.new('sha1')
    h.update(newCoverage.encode('utf-8'))
    dbobj = CollectionFile()
    dbobj.file.save("%s.coverage" % h.hexdigest(), ContentFile(newCoverage))
    dbobj.save()

    mergedCollection.description += " (NC %s, LM %s, CM %s)" % (
        stats['null_coverable_count'], stats['length_mismatch_count'],
        stats['coverable_mismatch_count'])

    # Save the collection
    mergedCollection.coverage = dbobj
    mergedCollection.save()

    return
Пример #2
0
def aggregate_coverage_data(pk, pks):
    from covmanager.models import Collection, CollectionFile  # noqa
    from FTB import CoverageHelper # noqa

    # Fetch our existing, but incomplete destination collection
    mergedCollection = Collection.objects.get(pk=pk)

    # Fetch all source collections
    collections = Collection.objects.filter(pk__in=pks)

    # Merge the coverage of all other collections into the first one
    first_collection = collections[0]
    first_collection.loadCoverage()
    newCoverage = first_collection.content
    total_stats = None

    for collection in collections[1:]:
        # Load coverage, perform the merge, then release reference to the JSON blob again
        collection.loadCoverage()
        stats = CoverageHelper.merge_coverage_data(newCoverage, collection.content)
        collection.content = None

        # Merge stats appropriately
        if total_stats is None:
            total_stats = stats
        else:
            for x in total_stats:
                total_stats[x] += stats[x]

    # Save the new coverage blob to disk and database
    newCoverage = json.dumps(newCoverage, separators=(',', ':'))
    h = hashlib.new('sha1')
    h.update(newCoverage.encode('utf-8'))
    dbobj = CollectionFile()
    dbobj.file.save("%s.coverage" % h.hexdigest(), ContentFile(newCoverage))
    dbobj.save()

    mergedCollection.description += " (NC %s, LM %s, CM %s)" % (stats['null_coverable_count'],
                                                                stats['length_mismatch_count'],
                                                                stats['coverable_mismatch_count'])

    # Save the collection
    mergedCollection.coverage = dbobj
    mergedCollection.save()

    return
Пример #3
0
    def create_combined_coverage(coverage_files):
        '''
        Read coverage data from multiple files and return a single dictionary
        containing the merged data (already preprocessed).

        @type coverage_files: list
        @param coverage_files: List of filenames containing coverage data

        @return Dictionary with combined coverage data, version information and debug statistics
        @rtype tuple(dict,dict,dict)
        '''
        ret = None
        version = None
        stats = None

        for coverage_file in coverage_files:
            with open(coverage_file) as f:
                coverage = json.load(f)

                if version is None:
                    version = CovReporter.version_info_from_coverage_data(
                        coverage)

                coverage = CovReporter.preprocess_coverage_data(coverage)

                if ret is None:
                    ret = coverage
                else:
                    merge_stats = CoverageHelper.merge_coverage_data(
                        ret, coverage)
                    if stats is None:
                        stats = merge_stats
                    else:
                        for k in merge_stats:
                            if k in stats:
                                stats[k] += merge_stats[k]

        return (ret, version, stats)
Пример #4
0
    def create_combined_coverage(coverage_files):
        '''
        Read coverage data from multiple files and return a single dictionary
        containing the merged data (already preprocessed).

        @type coverage_files: list
        @param coverage_files: List of filenames containing coverage data

        @return Dictionary with combined coverage data, version information and debug statistics
        @rtype tuple(dict,dict,dict)
        '''
        ret = None
        version = None
        stats = None

        for coverage_file in coverage_files:
            with open(coverage_file) as f:
                coverage = json.load(f)

                if version is None:
                    version = CovReporter.version_info_from_coverage_data(coverage)

                coverage = CovReporter.preprocess_coverage_data(coverage)

                if ret is None:
                    ret = coverage
                else:
                    merge_stats = CoverageHelper.merge_coverage_data(ret, coverage)
                    if stats is None:
                        stats = merge_stats
                    else:
                        for k in merge_stats:
                            if k in stats:
                                stats[k] += merge_stats[k]

        return (ret, version, stats)