def get_failure_stats(self, start_period, end_period):
        failure_stats = {
            'total': 0,
            'reasons': defaultdict(int),
        }
        for project in self.projects:
            for stat, value in self.get_failure_stats_for_project(
                    project, start_period, end_period).iteritems():
                failure_stats['reasons'][stat] += value

        failure_stats['total'] = Build.query.join(
            Source, Source.id == Build.source_id,
        ).filter(
            Build.project_id.in_(p.id for p in self.projects),
            Build.status == Status.finished,
            Build.result == Result.failed,
            Build.date_created >= start_period,
            Build.date_created < end_period,
            *build_type.get_any_commit_build_filters()
        ).count()

        return failure_stats
dataset/ETHPy150Open dropbox/changes/changes/reports/build.py/BuildReport.get_failure_stats/original