class AverageNumberOfTenderersController extends GenericOCDSController {

    @ApiOperation(value = "Calculate average number of tenderers. The endpoint can be filtered"
            + "by year read from tender.tenderPeriod.startDate. "
            + "The number of tenderers are read from tender.numberOfTenderers")

    @RequestMapping(value = "/api/averageNumberOfTenderers",
            method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
    public List<Document> averageNumberOfTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {

        DBObject project = new BasicDBObject();
        addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
        project.put(MongoConstants.FieldNames.TENDER_NO_TENDERERS, 1);

        Aggregation agg = newAggregation(
                match(where(MongoConstants.FieldNames.TENDER_NO_TENDERERS).gt(0)
                        .and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true)
                        .andOperator(getYearDefaultFilterCriteria(filter,
                                MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))),
                new CustomProjectionOperation(project),
                group().avg(MongoConstants.FieldNames.TENDER_NO_TENDERERS)
                        .as(Keys.AVERAGE_NO_OF_TENDERERS));


       return releaseAgg(agg);
    }

}