class CorruptionRiskDashboardIndicatorsStatsController extends GenericOCDSController {

    @ApiOperation(value = "Percent of total projects eligible (denominator is total projects)")
    @RequestMapping(value = "/api/percentTotalProjectsEligibleByYear",
            method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public List<Document> percentTotalProjectsEligibleByYear(final YearFilterPagingRequest filter) {

        //get the total projects eligible by year
        List<Document> totalEligibleProjects = totalEligibleProjectsByIndicatorTypeByYear(filter);

        //denominator total projects eligible by year
        List<Document> totalProjectsByYear = totalProjectsByYear(filter);

        totalEligibleProjects.forEach(e -> findByYearAndTypeAndMonth(totalProjectsByYear, (Integer) e.get(Keys.YEAR),
                null, (Integer) e.get(Keys.MONTH)).forEach(f -> {
                    e.put(Keys.PROJECT_COUNT, f.get(Keys.PROJECT_COUNT));
                    e.put(Keys.PERCENT, (BigDecimal.valueOf((Integer) e.get(Keys.ELIGIBLE_PROJECT_COUNT))
                            .setScale(BIGDECIMAL_SCALE)
                            .divide(BigDecimal.valueOf((Integer) f.get(Keys.PROJECT_COUNT)),
                                    BigDecimal.ROUND_HALF_UP).multiply(ONE_HUNDRED)));
                }));

        return totalEligibleProjects;
    }

}