Search in sources :

Example 11 with CustomProjectionOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation in project ocvn by devgateway.

the class TenderPercentagesController method avgTimeFromPlanToTenderPhase.

@ApiOperation("For all tenders that have both tender.tenderPeriod.startDate and planning.bidPlanProjectDateApprove" + "calculates the number o days from planning.bidPlanProjectDateApprove to tender.tenderPeriod.startDate" + "and creates the average. Groups results by tender year, calculatedfrom tender.tenderPeriod.startDate")
@RequestMapping(value = "/api/avgTimeFromPlanToTenderPhase", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> avgTimeFromPlanToTenderPhase(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject timeFromPlanToTenderPhase = new BasicDBObject("$divide", Arrays.asList(new BasicDBObject("$subtract", Arrays.asList("$tender.tenderPeriod.startDate", "$planning.bidPlanProjectDateApprove")), MongoConstants.DAY_MS));
    DBObject project1 = new BasicDBObject();
    addYearlyMonthlyProjection(filter, project1, "$tender.tenderPeriod.startDate");
    project1.put("timeFromPlanToTenderPhase", timeFromPlanToTenderPhase);
    Aggregation agg = newAggregation(match(where("tender.tenderPeriod.startDate").exists(true).and("planning.budget.amount").exists(true).and("planning.bidPlanProjectDateApprove").exists(true).andOperator(getYearDefaultFilterCriteria(filter, "tender.tenderPeriod.startDate"))), new CustomProjectionOperation(project1), getYearlyMonthlyGroupingOperation(filter).avg("timeFromPlanToTenderPhase").as(Keys.AVG_TIME_FROM_PLAN_TO_TENDER_PHASE), transformYearlyGrouping(filter).andInclude(Keys.AVG_TIME_FROM_PLAN_TO_TENDER_PHASE), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with CustomProjectionOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation in project ocvn by devgateway.

the class TenderPercentagesController method percentTendersWithTwoOrMoreTenderers.

@ApiOperation("Percentage of tenders with >1 tenderer/bidder): " + "Count of tenders with numberOfTenderers >1 divided by total count of tenders." + "This endpoint uses tender.tenderPeriod.startDate to calculate the tender year.")
@RequestMapping(value = "/api/percentTendersWithTwoOrMoreTenderers", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> percentTendersWithTwoOrMoreTenderers(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject project1 = new BasicDBObject();
    addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
    project1.put("tender.numberOfTenderers", 1);
    DBObject group = new BasicDBObject();
    addYearlyMonthlyReferenceToGroup(filter, group);
    group.put(Keys.TOTAL_TENDERS, new BasicDBObject("$sum", 1));
    group.put("totalTendersWithTwoOrMoreTenderers", new BasicDBObject("$sum", new BasicDBObject("$cond", Arrays.asList(new BasicDBObject("$gt", Arrays.asList("$tender.numberOfTenderers", 1)), 1, 0))));
    DBObject project2 = new BasicDBObject();
    project2.put(Keys.TOTAL_TENDERS, 1);
    project2.put(Keys.TOTAL_TENDERS_WITH_TWO_OR_MORE_TENDERERS, 1);
    project2.put(Keys.PERCENT_TENDERS, new BasicDBObject("$multiply", Arrays.asList(new BasicDBObject("$divide", Arrays.asList("$totalTendersWithTwoOrMoreTenderers", "$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_TENDERS_WITH_TWO_OR_MORE_TENDERERS, Keys.PERCENT_TENDERS), getSortByYearMonth(filter), skip(filter.getSkip()), limit(filter.getPageSize()));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomGroupingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with CustomProjectionOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation in project ocvn by devgateway.

the class TenderPriceByTypeYearController method tenderPriceByBidSelectionMethod.

@ApiOperation(value = "Returns the tender price by Vietnam type (procurementMethodDetails), by year. " + "The OCDS type is read from tender.procurementMethodDetails. The tender price is read from " + "tender.value.amount")
@RequestMapping(value = "/api/tenderPriceByBidSelectionMethod", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tenderPriceByBidSelectionMethod(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject project = new BasicDBObject();
    project.put("tender." + Keys.PROCUREMENT_METHOD_DETAILS, 1);
    project.put("tender.value", 1);
    Aggregation agg = newAggregation(match(where("awards").elemMatch(where("status").is("active")).and("tender.value").exists(true).andOperator(getYearFilterCriteria(filter, "tender.tenderPeriod.startDate"))), getMatchDefaultFilterOperation(filter), new CustomProjectionOperation(project), group("tender." + Keys.PROCUREMENT_METHOD_DETAILS).sum("$tender.value.amount").as(Keys.TOTAL_TENDER_AMOUNT), project().and(Fields.UNDERSCORE_ID).as(Keys.PROCUREMENT_METHOD_DETAILS).andInclude(Keys.TOTAL_TENDER_AMOUNT).andExclude(Fields.UNDERSCORE_ID), sort(Direction.DESC, Keys.TOTAL_TENDER_AMOUNT));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> tagCount = results.getMappedResults();
    return tagCount;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with CustomProjectionOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation in project ocvn by devgateway.

the class TendersByItemClassification method tendersByItemClassification.

@ApiOperation(value = "This should show the number of tenders per tender.items.classification." + "The tender date is taken from tender.tenderPeriod.startDate.")
@RequestMapping(value = "/api/tendersByItemClassification", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> tendersByItemClassification(@ModelAttribute @Valid final YearFilterPagingRequest filter) {
    DBObject project = new BasicDBObject();
    project.put(Fields.UNDERSCORE_ID, 0);
    project.put("tender." + Keys.ITEMS_CLASSIFICATION, 1);
    project.put("tender.value.amount", 1);
    Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project), unwind("tender.items"), group("$tender." + Keys.ITEMS_CLASSIFICATION).count().as(Keys.TOTAL_TENDERS).sum("tender.value.amount").as(Keys.TOTAL_TENDER_AMOUNT), sort(Direction.ASC, Fields.UNDERSCORE_ID));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) BasicDBObject(com.mongodb.BasicDBObject) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with CustomProjectionOperation

use of org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation in project ocvn by devgateway.

the class AbstractFlagStatsController method flagStats.

public 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)), new CustomProjectionOperation(projectPrepare), new CustomGroupingOperation(group), new CustomProjectionOperation(projectPercentage), transformYearlyGrouping(filter).andInclude(GenericKeys.TOTAL, GenericKeys.TOTAL_TRUE, GenericKeys.TOTAL_FALSE, GenericKeys.TOTAL_PRECOND_MET, GenericKeys.PERCENT_TRUE_PRECOND_MET, GenericKeys.PERCENT_FALSE_PRECOND_MET, GenericKeys.PERCENT_PRECOND_MET));
    AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
    List<DBObject> list = results.getMappedResults();
    return list;
}
Also used : Aggregation.newAggregation(org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation) Aggregation(org.springframework.data.mongodb.core.aggregation.Aggregation) CustomGroupingOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation) CustomProjectionOperation(org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)30 DBObject (com.mongodb.DBObject)30 CustomProjectionOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomProjectionOperation)30 Aggregation (org.springframework.data.mongodb.core.aggregation.Aggregation)30 ApiOperation (io.swagger.annotations.ApiOperation)26 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 Aggregation.newAggregation (org.springframework.data.mongodb.core.aggregation.Aggregation.newAggregation)25 CustomGroupingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomGroupingOperation)12 CustomUnwindOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomUnwindOperation)2 Date (java.util.Date)1 CustomSortingOperation (org.devgateway.toolkit.persistence.mongo.aggregate.CustomSortingOperation)1 Criteria (org.springframework.data.mongodb.core.query.Criteria)1