test_class.declarator: averageTenderAndAwardPeriodsController
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private AverageTenderAndAwardPeriodsController averageTenderAndAwardPeriodsController;
test_class.type: AverageTenderAndAwardPeriodsController
test_class.var_name: averageTenderAndAwardPeriodsController
test_class.file: web/src/test/java/org/devgateway/ocds/web/rest/controller/AverageTenderAndAwardPeriodsControllerTest.java
test_class.identifier: AverageTenderAndAwardPeriodsControllerTest
test_class.superclass: extends AbstractEndPointControllerTest
test_case.body: @Test
      public void averageAwardPeriod() throws Exception {
          final List<Document> averageAwardPeriod = averageTenderAndAwardPeriodsController
                  .averageAwardPeriod(new YearFilterPagingRequest());
  
          final Document first = averageAwardPeriod.get(0);
          int year = (int) first.get(AverageTenderAndAwardPeriodsController.Keys.YEAR);
          double averageAwardDays = (double) first.get(AverageTenderAndAwardPeriodsController.Keys.AVERAGE_AWARD_DAYS);
          Assert.assertEquals(2015, year);
          Assert.assertEquals(365.0, averageAwardDays, 0);
  
          final Document second = averageAwardPeriod.get(1);
          year = (int) second.get(AverageTenderAndAwardPeriodsController.Keys.YEAR);
          averageAwardDays = (double) second.get(AverageTenderAndAwardPeriodsController.Keys.AVERAGE_AWARD_DAYS);
          Assert.assertEquals(2016, year);
          Assert.assertEquals(405.0, averageAwardDays, 0);
      }
test_case.class_method_signature: AverageTenderAndAwardPeriodsControllerTest.averageAwardPeriod()
test_case.full_signature: @Test public void averageAwardPeriod()
test_case.identifier: averageAwardPeriod
test_case.invocations: averageAwardPeriod get get get assertEquals assertEquals get get get assertEquals assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void averageAwardPeriod()
focal_class.file: web/src/main/java/org/devgateway/ocds/web/rest/controller/AverageTenderAndAwardPeriodsController.java
focal_class.identifier: AverageTenderAndAwardPeriodsController
focal_class.class_method_signature: AverageTenderAndAwardPeriodsController.averageTenderPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Calculates the average tender period, per each year. The year is taken from " + "tender.tenderPeriod.startDate and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate") @RequestMapping(value = "/api/averageTenderPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> averageTenderPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.identifier: averageTenderPeriod
focal_class.modifiers: @ApiOperation(value = "Calculates the average tender period, per each year. The year is taken from " + "tender.tenderPeriod.startDate and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate") @RequestMapping(value = "/api/averageTenderPeriod", 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> averageTenderPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.class_method_signature: AverageTenderAndAwardPeriodsController.qualityAverageTenderPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Quality indicator for averageTenderPeriod endpoint, " + "showing the percentage of tenders that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageTenderPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> qualityAverageTenderPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.identifier: qualityAverageTenderPeriod
focal_class.modifiers: @ApiOperation(value = "Quality indicator for averageTenderPeriod endpoint, " + "showing the percentage of tenders that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageTenderPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> qualityAverageTenderPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.class_method_signature: AverageTenderAndAwardPeriodsController.averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from " + "awards.date and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.") @RequestMapping(value = "/api/averageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.identifier: averageAwardPeriod
focal_class.modifiers: @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from " + "awards.date and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.") @RequestMapping(value = "/api/averageAwardPeriod", 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> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_class.class_method_signature: AverageTenderAndAwardPeriodsController.qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.full_signature: @ApiOperation(value = "Quality indicator for averageAwardPeriod endpoint, " + "showing the percentage of awards that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.identifier: qualityAverageAwardPeriod
focal_class.modifiers: @ApiOperation(value = "Quality indicator for averageAwardPeriod endpoint, " + "showing the percentage of awards that have start and end dates vs the total tenders in the system") @RequestMapping(value = "/api/qualityAverageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_class.parameters: (@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.return: List<Document>
focal_class.signature: List<Document> qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter)
focal_class.superclass: extends GenericOCDSController
focal_method.body: @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from "
              + "awards.date and the duration is taken by counting the days"
              + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.")
      @RequestMapping(value = "/api/averageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET},
              produces = "application/json")
      public List<Document> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
  
          DBObject awardLengthDays = new BasicDBObject("$divide", Arrays.asList(
                  new BasicDBObject("$subtract", Arrays.asList(
                          ref(MongoConstants.FieldNames.AWARDS_DATE),
                          ref(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE)
                  )), DAY_MS));
  
          DBObject project = new BasicDBObject();
          project.put(Fields.UNDERSCORE_ID, 0);
          addYearlyMonthlyProjection(filter, project, ref(MongoConstants.FieldNames.AWARDS_DATE));
          project.put("awardLengthDays", awardLengthDays);
          project.put(MongoConstants.FieldNames.AWARDS_DATE, 1);
          project.put(MongoConstants.FieldNames.AWARDS_STATUS, 1);
          project.put(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, 1);
  
          Aggregation agg = newAggregation(
                  // this is repeated so we gain speed by filtering items before
                  // unwind
                  match(where(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE)
                          .exists(true).and(MongoConstants.FieldNames.AWARDS_DATE).exists(true)
                          .and(MongoConstants.FieldNames.AWARDS_STATUS).is(Award.Status.active.toString())),
                  unwind("awards"),
                  // we need to filter the awards again after unwind
                  match(where(MongoConstants.FieldNames.AWARDS_DATE).exists(true)
                          .and(MongoConstants.FieldNames.AWARDS_STATUS)
                          .is(Award.Status.active.toString())
                          .andOperator(getYearDefaultFilterCriteria(
                                  filter.awardFiltering(),
                                  MongoConstants.FieldNames.AWARDS_DATE
                          ))),
                  new CustomOperation(new Document("$project", project)),
                  group(getYearlyMonthlyGroupingFields(filter)).avg("$awardLengthDays").as(Keys.AVERAGE_AWARD_DAYS),
                  transformYearlyGrouping(filter).andInclude(Keys.AVERAGE_AWARD_DAYS),
                  getSortByYearMonth(filter), skip(filter.getSkip()),
                  limit(filter.getPageSize())
          );
  
          return releaseAgg(agg);
      }
focal_method.class_method_signature: AverageTenderAndAwardPeriodsController.averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_method.full_signature: @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from " + "awards.date and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.") @RequestMapping(value = "/api/averageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public List<Document> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_method.identifier: averageAwardPeriod
focal_method.invocations: asList asList ref ref put addYearlyMonthlyProjection ref put put put put newAggregation match is and exists and exists where toString unwind match andOperator is and exists where toString getYearDefaultFilterCriteria awardFiltering as avg group getYearlyMonthlyGroupingFields andInclude transformYearlyGrouping getSortByYearMonth skip getSkip limit getPageSize releaseAgg
focal_method.modifiers: @ApiOperation(value = "Calculates the average award period, per each year. The year is taken from " + "awards.date and the duration is taken by counting the days" + "between tender.tenderPeriod.endDate and tender.tenderPeriod.startDate. The award has to be active.") @RequestMapping(value = "/api/averageAwardPeriod", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json") public
focal_method.parameters: (@ModelAttribute @Valid final YearFilterPagingRequest filter)
focal_method.return: List<Document>
focal_method.signature: List<Document> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter)