test_class.declarator: costEffectivenessVisualsController
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private CostEffectivenessVisualsController costEffectivenessVisualsController;
test_class.type: CostEffectivenessVisualsController
test_class.var_name: costEffectivenessVisualsController
test_class.file: web/src/test/java/org/devgateway/ocds/web/rest/controller/CostEffectivenessVisualsControllerTest.java
test_class.identifier: CostEffectivenessVisualsControllerTest
test_class.superclass: extends AbstractEndPointControllerTest
test_case.body: @Test
      public void costEffectivenessTenderAmount() throws Exception {
          final List<Document> costEffectivenessTenderAmount = costEffectivenessVisualsController
                  .costEffectivenessTenderAmount(new GroupingFilterPagingRequest());
  
          final Document first = costEffectivenessTenderAmount.get(0);
          int year = (int) first.get(CostEffectivenessVisualsController.Keys.YEAR);
          double totalTenderAmount = (double) first.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDER_AMOUNT);
          int totalTenders = (int) first.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDERS);
          int totalTenderWithAwards = (int) first.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDER_WITH_AWARDS);
          double percentageTendersWithAwards = (double) first.
                  get(CostEffectivenessVisualsController.Keys.PERCENTAGE_TENDERS_WITH_AWARDS);
          Assert.assertEquals(2014, year);
          Assert.assertEquals(600000.0, totalTenderAmount, 0);
          Assert.assertEquals(1, totalTenders);
          Assert.assertEquals(1, totalTenderWithAwards);
          Assert.assertEquals(100.0, percentageTendersWithAwards, 0);
  
          final Document second = costEffectivenessTenderAmount.get(1);
          year = (int) second.get(CostEffectivenessVisualsController.Keys.YEAR);
          totalTenderAmount = (double) second.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDER_AMOUNT);
          totalTenders = (int) second.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDERS);
          totalTenderWithAwards = (int) second.get(CostEffectivenessVisualsController.Keys.TOTAL_TENDER_WITH_AWARDS);
          percentageTendersWithAwards = (double) second
                  .get(CostEffectivenessVisualsController.Keys.PERCENTAGE_TENDERS_WITH_AWARDS);
          Assert.assertEquals(2015, year);
          Assert.assertEquals(9000.0, totalTenderAmount, 0);
          Assert.assertEquals(2, totalTenders);
          Assert.assertEquals(1, totalTenderWithAwards);
          Assert.assertEquals(50.0, percentageTendersWithAwards, 0);
      }
test_case.class_method_signature: CostEffectivenessVisualsControllerTest.costEffectivenessTenderAmount()
test_case.full_signature: @Test public void costEffectivenessTenderAmount()
test_case.identifier: costEffectivenessTenderAmount
test_case.invocations: costEffectivenessTenderAmount get get get get get get assertEquals assertEquals assertEquals assertEquals assertEquals get get get get get get assertEquals assertEquals assertEquals assertEquals assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void costEffectivenessTenderAmount()
focal_class.declarator: controllerLookupService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private AsyncControllerLookupService controllerLookupService;
focal_class.type: AsyncControllerLookupService
focal_class.var_name: controllerLookupService
focal_class.file: web/src/main/java/org/devgateway/ocds/web/rest/controller/CostEffectivenessVisualsController.java
focal_class.identifier: CostEffectivenessVisualsController
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Cost effectiveness of Awards: Displays the total amount of active awards grouped by year." + "The tender entity, for each award, has to have amount value. The year is calculated from " + MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) @RequestMapping(value = "/api/costEffectivenessAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.identifier: costEffectivenessAwardAmount
focal_class.modifiers: @ApiOperation(value = "Cost effectiveness of Awards: Displays the total amount of active awards grouped by year." + "The tender entity, for each award, has to have amount value. The year is calculated from " + MongoConstants.FieldNames.TENDER_PERIOD_START_DATE) @RequestMapping(value = "/api/costEffectivenessAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> costEffectivenessAwardAmount(
              @ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.identifier: costEffectivenessTenderAmount
focal_class.modifiers: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.class_method_signature: CostEffectivenessVisualsController.getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.full_signature: private String getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.identifier: getYearMonthlyKey
focal_class.modifiers: private
focal_class.parameters: (GroupingFilterPagingRequest filter, Document db)
focal_class.return: String
focal_class.signature: String getYearMonthlyKey(GroupingFilterPagingRequest filter, Document db)
focal_class.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.identifier: costEffectivenessTenderAwardAmount
focal_class.modifiers: @ApiOperation(value = "Aggregated version of /api/costEffectivenessTenderAmount and " + "/api/costEffectivenessAwardAmount." + "This endpoint aggregates the responses from the specified endpoints, per year. " + "Responds to the same filters.") @RequestMapping(value = "/api/costEffectivenessTenderAwardAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.return: ArrayList<Document>
focal_class.signature: ArrayList<Document> costEffectivenessTenderAwardAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_class.superclass: extends GenericOCDSController
focal_method.body: @ApiOperation(value = "Cost effectiveness of Tenders:"
              + " Displays the total amount of the active tenders that have active awards, "
              + "grouped by year. Only tenders.status=active"
              + "are taken into account. The year is calculated from tenderPeriod.startDate")
      @RequestMapping(value = "/api/costEffectivenessTenderAmount",
              method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
      public List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter) {
  
          DBObject project = new BasicDBObject();
          project.put("year", new BasicDBObject("$year", ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)));
          addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE));
          project.put(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, 1);
          project.put(Fields.UNDERSCORE_ID, "$tender._id");
          project.put(
                  "tenderWithAwards",
                  new BasicDBObject("$cond", Arrays.asList(
                          new BasicDBObject(
                                  "$eq", Arrays.asList(
                                  ref(MongoConstants.FieldNames.AWARDS_STATUS),
                                  Award.Status.active.toString()
                          )), 1,
                          0
                  ))
          );
          project.put("tenderWithAwardsValue", new BasicDBObject(
                  "$cond",
                  Arrays.asList(new BasicDBObject(
                                  "$eq", Arrays.asList(ref(MongoConstants.FieldNames.AWARDS_STATUS),
                          Award.Status.active.toString()
                          )),
                          ref(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT), 0
                  )
          ));
          project.putAll(filterProjectMap);
  
          DBObject group1 = new BasicDBObject();
          group1.put(
                  Fields.UNDERSCORE_ID, Fields.UNDERSCORE_ID_REF);
          addYearlyMonthlyGroupingOperationFirst(filter, group1);
          group1.put("tenderWithAwards", new BasicDBObject("$max", "$tenderWithAwards"));
          group1.put("tenderWithAwardsValue", new BasicDBObject("$max", "$tenderWithAwardsValue"));
          group1.put("tenderAmount", new BasicDBObject("$first", ref(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT)));
          filterProjectMap.forEach((k, v) ->
                  group1.put(
                          k.replace(".", ""),
                          k.equals("tender.items.classification._id")
                                  ? new BasicDBObject("$first", new BasicDBObject(
                                  "$arrayElemAt",
                                  Arrays.asList("$" + k, 0)
                          ))
                                  :
                                  new BasicDBObject("$first", "$" + k)
                  ));
  
          Aggregation agg = Aggregation.newAggregation(
                  match(where(MongoConstants.FieldNames.TENDER_STATUS).is(Tender.Status.active.toString()).
                          and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)
                          .exists(true)
                          .andOperator(getYearDefaultFilterCriteria(
                                  filter,
                                  MongoConstants.FieldNames.TENDER_PERIOD_START_DATE
                          ))),
                  getMatchDefaultFilterOperation(filter),
                  new CustomUnwindOperation("$awards", true),
                  new CustomProjectionOperation(project),
                  new CustomGroupingOperation(group1),
                  getTopXFilterOperation(filter, getYearlyMonthlyGroupingFields(filter)).sum("tenderWithAwardsValue")
                          .as(Keys.TOTAL_TENDER_AMOUNT).count().as(Keys.TOTAL_TENDERS).sum("tenderWithAwards")
                          .as(Keys.TOTAL_TENDER_WITH_AWARDS),
                  project(Keys.TOTAL_TENDER_AMOUNT, Keys.TOTAL_TENDERS, Keys.TOTAL_TENDER_WITH_AWARDS)
                          .andInclude(Fields.from(
                                  Fields.field(
                                          Fields.UNDERSCORE_ID, Fields.UNDERSCORE_ID_REF)))
                          .and(Keys.TOTAL_TENDER_WITH_AWARDS).divide(Keys.TOTAL_TENDERS)
                          .as(Keys.FRACTION_TENDERS_WITH_AWARDS),
                  project(Keys.TOTAL_TENDER_AMOUNT, Keys.TOTAL_TENDERS, Keys.TOTAL_TENDER_WITH_AWARDS,
                          Fields.UNDERSCORE_ID
                  ).and(Keys.FRACTION_TENDERS_WITH_AWARDS).multiply(100)
                          .as(Keys.PERCENTAGE_TENDERS_WITH_AWARDS),
                  (filter.getGroupByCategory() == null
                          ? transformYearlyGrouping(filter) : project()).andInclude(Keys.TOTAL_TENDER_AMOUNT,
                          Keys.TOTAL_TENDERS,
                          Keys.TOTAL_TENDER_WITH_AWARDS, Keys.PERCENTAGE_TENDERS_WITH_AWARDS
                  ),
                  filter.getGroupByCategory() == null
                          ? getSortByYearMonth(filter) : sort(Sort.Direction.DESC, Keys.TOTAL_TENDER_AMOUNT),
                  skip(filter.getSkip()), limit(filter.getPageSize())
          )
                  .withOptions(Aggregation.newAggregationOptions().allowDiskUse(true).build());
  
          return releaseAgg(agg);
      }
focal_method.class_method_signature: CostEffectivenessVisualsController.costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.full_signature: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.identifier: costEffectivenessTenderAmount
focal_method.invocations: put ref addYearlyMonthlyProjection ref put put put asList asList ref toString put asList asList ref toString ref putAll put addYearlyMonthlyGroupingOperationFirst put put put ref forEach put replace equals asList withOptions newAggregation match andOperator exists and is where toString getYearDefaultFilterCriteria getMatchDefaultFilterOperation as sum as count as sum getTopXFilterOperation getYearlyMonthlyGroupingFields as divide and andInclude project from field as multiply and project andInclude getGroupByCategory transformYearlyGrouping project getGroupByCategory getSortByYearMonth sort skip getSkip limit getPageSize build allowDiskUse newAggregationOptions releaseAgg
focal_method.modifiers: @ApiOperation(value = "Cost effectiveness of Tenders:" + " Displays the total amount of the active tenders that have active awards, " + "grouped by year. Only tenders.status=active" + "are taken into account. The year is calculated from tenderPeriod.startDate") @RequestMapping(value = "/api/costEffectivenessTenderAmount", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_method.parameters: (
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)
focal_method.return: List<Document>
focal_method.signature: List<Document> costEffectivenessTenderAmount(
              @ModelAttribute @Valid final GroupingFilterPagingRequest filter)