class CorruptionRiskDashboardIndicatorsStatsController extends GenericOCDSController {

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

        //get the total projects flagged by year
        List<Document> totalFlaggedProjects = totalFlaggedProjectsByIndicatorTypeByYear(filter);

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

        totalFlaggedProjects.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.FLAGGED_PROJECT_COUNT))
                                .setScale(BIGDECIMAL_SCALE)
                                .divide(BigDecimal.valueOf((Integer) f.get(Keys.PROJECT_COUNT)),
                                        BigDecimal.ROUND_HALF_UP).multiply(ONE_HUNDRED)));
                    });
        });

        return totalFlaggedProjects;
    }

}