use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class LocationInfowindowController method planningByLocation.
@ApiOperation(value = "Displays the planning items, filtered by location. See the location filter " + "for the options to filter by")
@RequestMapping(value = "/api/planningByLocation", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<DBObject> planningByLocation(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
Aggregation agg = newAggregation(match(where("planning.budget").exists(true).orOperator(where("tender.items.deliveryLocation._id").exists(true), where("planning.budget.projectLocation._id").exists(true)).andOperator(getYearDefaultFilterCriteria(filter, "planning.bidPlanProjectDateApprove"))), project("planning").andExclude(Fields.UNDERSCORE_ID), skip(filter.getSkip()), limit(filter.getPageSize()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class AverageNumberOfTenderersController method averageNumberOfTenderers.
@ApiOperation(value = "Calculate average number of tenderers, by year. 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<DBObject> averageNumberOfTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
addYearlyMonthlyProjection(filter, project, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project.put("tender.numberOfTenderers", 1);
Aggregation agg = newAggregation(match(where("tender.numberOfTenderers").gt(0).and(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), group(getYearlyMonthlyGroupingFields(filter)).avg("tender.numberOfTenderers").as(Keys.AVERAGE_NO_OF_TENDERERS), transformYearlyGrouping(filter).andInclude(Keys.AVERAGE_NO_OF_TENDERERS), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class AverageTenderAndAwardPeriodsController method qualityAverageAwardPeriod.
@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<DBObject> qualityAverageAwardPeriod(@ModelAttribute @Valid final DefaultFilterPagingRequest filter) {
DBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
project.put("awardWithStartEndDates", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$and", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$awards.date", null)), new BasicDBObject("$gt", Arrays.asList(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE_REF, null)))), 1, 0)));
DBObject project1 = new BasicDBObject();
project1.put(Fields.UNDERSCORE_ID, 0);
project1.put(Keys.TOTAL_AWARD_WITH_START_END_DATES, 1);
project1.put(Keys.TOTAL_AWARDS, 1);
project1.put(Keys.PERCENTAGE_AWARD_WITH_START_END_DATES, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalAwardWithStartEndDates", "$totalAwards")), 100)));
Aggregation agg = newAggregation(match(where("awards.0").exists(true).andOperator(getDefaultFilterCriteria(filter))), unwind("$awards"), new CustomProjectionOperation(project), group().sum("awardWithStartEndDates").as(Keys.TOTAL_AWARD_WITH_START_END_DATES).count().as(Keys.TOTAL_AWARDS), new CustomProjectionOperation(project1));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class AverageTenderAndAwardPeriodsController method averageAwardPeriod.
@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<DBObject> averageAwardPeriod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject awardLengthDays = new BasicDBObject("$divide", Arrays.asList(new BasicDBObject("$subtract", Arrays.asList("$awards.date", MongoConstants.FieldNames.TENDER_PERIOD_END_DATE_REF)), MongoConstants.DAY_MS));
DBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
addYearlyMonthlyProjection(filter, project, "$awards.date");
project.put("awardLengthDays", awardLengthDays);
project.put("awards.date", 1);
project.put("awards.status", 1);
project.put(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, 1);
Aggregation agg = newAggregation(// unwind
match(where(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE).exists(true).and("awards.date").exists(true).and("awards.status").is("active")), unwind("$awards"), // we need to filter the awards again after unwind
match(where("awards.date").exists(true).and("awards.status").is("active").andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), new CustomOperation(new BasicDBObject("$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()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class PercentageAwardsNarrowPublicationDates method percentageAwardsNarrowPublicationDates.
@ApiOperation(value = "Percentage of awards where award publication date - award.date is less than 7 days." + " Percentage should be by year. The denominator for the percentage is the " + "number of awards that have both awards.date and awards.publishedDate")
@RequestMapping(value = "/api/percentageAwardsNarrowPublicationDates", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentageAwardsNarrowPublicationDates(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
BasicDBObject project = new BasicDBObject();
project.put("year", new BasicDBObject("$year", "$awards.date"));
project.put("narrowAwardPublicationDates", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$and", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$awards.date", null)), new BasicDBObject("$gt", Arrays.asList("$awards.publishedDate", null)), new BasicDBObject("$lt", Arrays.asList(new BasicDBObject("$divide", Arrays.asList(new BasicDBObject("$subtract", Arrays.asList("$awards.publishedDate", "$awards.date")), MongoConstants.DAY_MS)), 7)))), 1, 0)));
DBObject project2 = new BasicDBObject();
project2.put(Keys.YEAR, Fields.UNDERSCORE_ID_REF);
project2.put(Fields.UNDERSCORE_ID, 0);
project2.put(Keys.TOTAL_AWARDS, 1);
project2.put(Keys.TOTAL_AWARDS_NARROW_PUBLICATION_DATES, 1);
project2.put(Keys.PERCENT_NARROW_AWARD_PUBLICATION_DATES, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalAwardsNarrowPublicationDates", "$totalAwards")), 100)));
Aggregation agg = Aggregation.newAggregation(match(where("awards.0").exists(true)), unwind("$awards"), match(where("awards.date").exists(true).and("awards.publishedDate").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "awards.date"))), new CustomProjectionOperation(project), group("$year").count().as(Keys.TOTAL_AWARDS).sum("narrowAwardPublicationDates").as(Keys.TOTAL_AWARDS_NARROW_PUBLICATION_DATES), new CustomProjectionOperation(project2), sort(Direction.ASC, Fields.UNDERSCORE_ID), skip(filter.getSkip()), limit(filter.getPageSize()));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
Aggregations