def get_failure_stats_for_project(self, project, start_period, end_period):
        base_query = db.session.query(
            FailureReason.reason, FailureReason.build_id
        ).join(
            Build, Build.id == FailureReason.build_id,
        ).join(
            Source, Source.id == Build.source_id,
        ).join(
            JobStep, JobStep.id == FailureReason.step_id,
        ).filter(
            Build.project_id == project.id,
            Build.date_created >= start_period,
            Build.date_created < end_period,
            JobStep.replacement_id.is_(None),
            *build_type.get_any_commit_build_filters()
        ).group_by(
            FailureReason.reason, FailureReason.build_id
        ).subquery()

        return dict(
            db.session.query(
                base_query.c.reason,
                func.count(),
            ).group_by(
                base_query.c.reason,
            )
        )
dataset/ETHPy150Open dropbox/changes/changes/reports/build.py/BuildReport.get_failure_stats_for_project/original