def _get_green_percent(self, project, start_period, end_period):
        build_counts = dict(db.session.query(
            Build.result, func.count()
        ).join(
            Source, Build.source_id == Source.id,
        ).filter(
            Build.project_id == project.id,
            Build.date_created >= start_period,
            Build.date_created < end_period,
            Build.status == Status.finished,
            Build.result.in_([Result.passed, Result.failed]),
            *build_type.get_any_commit_build_filters()
        ).group_by(
            Build.result,
        ))

        failed_builds = build_counts.get(Result.failed) or 0
        passed_builds = build_counts.get(Result.passed) or 0
        if passed_builds:
            green_percent = int((passed_builds / (failed_builds + passed_builds)) * 100)
        elif failed_builds:
            green_percent = 0
        else:
            green_percent = None

        return green_percent
dataset/ETHPy150Open dropbox/changes/changes/api/project_details.py/ProjectDetailsAPIView._get_green_percent/original