use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation in project ocvn by devgateway.
the class AbstractFlagCrosstabController method flagStats.
protected List<DBObject> flagStats(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject projectPrepare = getProjectPrepare(filter);
DBObject group = getGroup(filter);
DBObject projectPercentage = getProjectPercentage(filter);
Aggregation agg = newAggregation(match(getYearDefaultFilterCriteria(filter, getYearProperty()).and(getYearProperty()).exists(true).and(getFlagProperty()).is(true)), new CustomProjectionOperation(projectPrepare), new CustomGroupingOperation(group), new CustomProjectionOperation(projectPercentage));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation in project ocvn by devgateway.
the class TenderPercentagesController method percentTendersUsingEBid.
@ApiOperation("Returns the percent of tenders with active awards, " + "with tender.submissionMethod='electronicSubmission'." + "The endpoint also returns the total tenderds with active awards and the count of tenders with " + "tender.submissionMethod='electronicSubmission")
@RequestMapping(value = "/api/percentTendersUsingEBid", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersUsingEBid(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project1.put(Fields.UNDERSCORE_ID, "$tender._id");
project1.put("electronicSubmission", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$eq", Arrays.asList("$tender.submissionMethod", Tender.SubmissionMethod.electronicSubmission.toString())), 1, 0)));
DBObject group1 = new BasicDBObject();
group1.put(Fields.UNDERSCORE_ID, Fields.UNDERSCORE_ID_REF);
addYearlyMonthlyGroupingOperationFirst(filter, group1);
group1.put("electronicSubmission", new BasicDBObject("$max", "$electronicSubmission"));
DBObject group2 = new BasicDBObject();
addYearlyMonthlyReferenceToGroup(filter, group2);
group2.put(Keys.TOTAL_TENDERS, new BasicDBObject("$sum", 1));
group2.put(Keys.TOTAL_TENDERS_USING_EBID, new BasicDBObject("$sum", "$electronicSubmission"));
DBObject project2 = new BasicDBObject();
project2.put(Keys.TOTAL_TENDERS, 1);
project2.put(Keys.TOTAL_TENDERS_USING_EBID, 1);
project2.put(Keys.PERCENTAGE_TENDERS_USING_EBID, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalTendersUsingEbid", "$totalTenders")), 100)));
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).and("tender.submissionMethod.0").exists(true).and("awards.status").is("active").andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("$tender.submissionMethod"), new CustomProjectionOperation(project1), new CustomGroupingOperation(group1), new CustomGroupingOperation(group2), new CustomProjectionOperation(project2), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_TENDERS, Keys.TOTAL_TENDERS_USING_EBID, Keys.PERCENTAGE_TENDERS_USING_EBID), 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.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation in project ocvn by devgateway.
the class TenderPercentagesController method percentTendersUsingEgp.
@ApiOperation("Returns the percent of tenders that are using eProcurement." + " This is read from tender.publicationMethod='eGP'")
@RequestMapping(value = "/api/percentTendersUsingEgp", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersUsingEgp(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, "$tender.tenderPeriod.startDate");
project1.put("tender.publicationMethod", 1);
DBObject group = new BasicDBObject();
addYearlyMonthlyReferenceToGroup(filter, group);
group.put("totalTenders", new BasicDBObject("$sum", 1));
group.put(Keys.TOTAL_EGP, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$eq", Arrays.asList("$tender.publicationMethod", "eGP")), 1, 0))));
DBObject project2 = new BasicDBObject();
project2.put("totalTenders", 1);
project2.put(Keys.TOTAL_EGP, 1);
project2.put("year", 1);
project2.put("month", 1);
project2.put("percentEgp", new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalEgp", "$totalTenders")), 100)));
Aggregation agg = newAggregation(match(where("tender.tenderPeriod.startDate").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "tender.tenderPeriod.startDate"))), new CustomProjectionOperation(project1), new CustomGroupingOperation(group), transformYearlyGrouping(filter).andInclude("totalTenders", "percentEgp", Keys.TOTAL_EGP), new CustomProjectionOperation(project2), 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.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation in project ocvn by devgateway.
the class TenderPercentagesController method percentTendersCancelled.
@ApiOperation("Returns the percent of tenders that were cancelled, grouped by year." + " The year is taken from tender.tenderPeriod.startDate. The response also contains the" + " total number of tenders and total number of cancelled tenders for each year.")
@RequestMapping(value = "/api/percentTendersCancelled", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersCancelled(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project1.put("tender.status", 1);
DBObject group = new BasicDBObject();
addYearlyMonthlyReferenceToGroup(filter, group);
group.put(Keys.TOTAL_TENDERS, new BasicDBObject("$sum", 1));
group.put(Keys.TOTAL_CANCELLED, new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$eq", Arrays.asList("$tender.status", "cancelled")), 1, 0))));
DBObject project2 = new BasicDBObject();
project2.put(Keys.TOTAL_TENDERS, 1);
project2.put(Keys.TOTAL_CANCELLED, 1);
project2.put(Keys.PERCENT_CANCELLED, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalCancelled", "$totalTenders")), 100)));
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project1), new CustomGroupingOperation(group), new CustomProjectionOperation(project2), transformYearlyGrouping(filter).andInclude(Keys.TOTAL_TENDERS, Keys.TOTAL_CANCELLED, Keys.PERCENT_TENDERS, Keys.PERCENT_CANCELLED), 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.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation in project ocvn by devgateway.
the class TopTenController method topTenLargestSuppliers.
@ApiOperation(value = "This endpoint should return the following data for the Top 10 suppliers (by award value)." + "Returns supplier id, total awarded amount of all awarded contracts, count of awarded contracts," + "Ids of the procuring entities from which they have received an award, and their count. " + "All filters ally here, the year filter uses the awards.date field.")
@RequestMapping(value = "/api/topTenSuppliers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> topTenLargestSuppliers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
BasicDBObject project = new BasicDBObject();
project.put(Fields.UNDERSCORE_ID, 0);
project.put("awards.suppliers._id", 1);
project.put("awards.value.amount", 1);
project.put("tender.procuringEntity._id", 1);
BasicDBObject group = new BasicDBObject();
group.put(Fields.UNDERSCORE_ID, "$awards.suppliers._id");
group.put(Keys.TOTAL_AWARD_AMOUNT, new BasicDBObject("$sum", "$awards.value.amount"));
group.put(Keys.TOTAL_CONTRACTS, new BasicDBObject("$sum", 1));
group.put(Keys.PROCURING_ENTITY_IDS, new BasicDBObject("$addToSet", "$tender.procuringEntity._id"));
Aggregation agg = newAggregation(match(where("awards.value.amount").exists(true).and("awards.status").is("active").andOperator(getDefaultFilterCriteria(filter))), unwind("$awards"), match(where("awards.status").is("active")), unwind("$awards.suppliers"), match(getYearFilterCriteria(filter, "awards.date")), new CustomProjectionOperation(project), new CustomGroupingOperation(group), sort(Direction.DESC, Keys.TOTAL_AWARD_AMOUNT), limit(10), project().and(Fields.UNDERSCORE_ID).as(Keys.SUPPLIER_ID).andInclude(Keys.TOTAL_AWARD_AMOUNT, Keys.TOTAL_CONTRACTS, Keys.PROCURING_ENTITY_IDS).andExclude(Fields.UNDERSCORE_ID).and(Keys.PROCURING_ENTITY_IDS).size().as(Keys.PROCURING_ENTITY_IDS_COUNT));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> tagCount = results.getMappedResults();
return tagCount;
}
Aggregations