Search in sources :

Example 1 with IndicatorMongoImpl

use of org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl in project statistics by OPEN-ENT-NG.

the class IndicatorFactory method getActivationIndicator.

// 1) Indicators that are incremented every day
// UserAccount Activation
public static Indicator getActivationIndicator(Collection<IndicatorFilterMongoImpl> filters, Date pWriteDate) {
    Collection<IndicatorGroup> indicatorGroups = new ArrayList<>();
    indicatorGroups.add(new IndicatorGroup(TRACE_FIELD_STRUCTURES).setArray(true).addAndReturnChild(TRACE_FIELD_PROFILE));
    IndicatorMongoImpl indicator = new IndicatorMongoImpl(TRACE_TYPE_ACTIVATION, filters, indicatorGroups) {

        @Override
        protected void customizePipeline(JsonArray pipeline) {
            int triggerSize = 0;
            // Remove "count" from stage "$group" in pipeline, add userCount instead, and add "userId" to field _id
            for (int i = 0; i < pipeline.size(); i++) {
                JsonObject stage = pipeline.get(i);
                JsonObject group = stage.getObject("$group", null);
                if (group != null) {
                    group.removeField("count");
                    JsonObject id = group.getObject("_id", null);
                    if (id != null && id.size() == 0) {
                        id.putString(TRACE_FIELD_USER, "$" + TRACE_FIELD_USER);
                    } else if (id != null && id.size() > 0) {
                        // We are in a "structures" stats query
                        id.putString(TRACE_FIELD_STRUCTURES, "$" + TRACE_FIELD_STRUCTURES).putString(TRACE_FIELD_PROFILE, "$" + TRACE_FIELD_PROFILE).putString(TRACE_FIELD_USER, "$" + TRACE_FIELD_USER);
                        triggerSize = 1;
                    }
                    group.putObject("userCount", new JsonObject().putNumber("$min", 1));
                    break;
                }
            }
            // Add another "$group" stage in pipeline, to count unique activation per user
            JsonObject groupByActiv = new JsonObject();
            if (triggerSize == 0) {
                groupByActiv.putObject("$group", new JsonObject().putObject("_id", new JsonObject()).putObject("count", new JsonObject().putString("$sum", "$userCount")));
            } else {
                groupByActiv.putObject("$group", new JsonObject().putObject("_id", new JsonObject().putString(TRACE_FIELD_STRUCTURES, "$_id." + TRACE_FIELD_STRUCTURES).putString(TRACE_FIELD_PROFILE, "$_id." + TRACE_FIELD_PROFILE)).putObject("count", new JsonObject().putString("$sum", "$userCount")));
            }
            pipeline.addObject(groupByActiv);
        }
    };
    indicator.setWriteDate(pWriteDate);
    return indicator;
}
Also used : JsonArray(org.vertx.java.core.json.JsonArray) IndicatorGroup(org.entcore.common.aggregation.groups.IndicatorGroup) ArrayList(java.util.ArrayList) JsonObject(org.vertx.java.core.json.JsonObject) IndicatorMongoImpl(org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl)

Example 2 with IndicatorMongoImpl

use of org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl in project statistics by OPEN-ENT-NG.

the class IndicatorFactory method getAccessIndicator.

// Access to applications
public static Indicator getAccessIndicator(Collection<IndicatorFilterMongoImpl> filters, Date pWriteDate) {
    Collection<IndicatorGroup> indicatorGroups = new ArrayList<IndicatorGroup>();
    indicatorGroups.add(new IndicatorGroup(TRACE_FIELD_MODULE).addAndReturnChild(new IndicatorGroup(TRACE_FIELD_STRUCTURES).setArray(true)).addAndReturnChild(TRACE_FIELD_PROFILE));
    Indicator indicator = new IndicatorMongoImpl(TRACE_TYPE_SVC_ACCESS, filters, indicatorGroups);
    indicator.setWriteDate(pWriteDate);
    return indicator;
}
Also used : IndicatorGroup(org.entcore.common.aggregation.groups.IndicatorGroup) ArrayList(java.util.ArrayList) IndicatorMongoImpl(org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl) Indicator(org.entcore.common.aggregation.indicators.Indicator)

Example 3 with IndicatorMongoImpl

use of org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl in project statistics by OPEN-ENT-NG.

the class IndicatorFactory method getUniqueVisitorsIndicator.

// Unique visitors
public static Indicator getUniqueVisitorsIndicator(Collection<IndicatorFilterMongoImpl> filters, Date pWriteDate) {
    Collection<IndicatorGroup> indicatorGroups = new ArrayList<IndicatorGroup>();
    final IndicatorGroup profileIg = new IndicatorGroup(TRACE_FIELD_STRUCTURES).setArray(true).addAndReturnChild(TRACE_FIELD_PROFILE);
    indicatorGroups.add(profileIg);
    IndicatorMongoImpl indicator = new IndicatorMongoImpl(TRACE_TYPE_CONNEXION, filters, indicatorGroups) {

        @Override
        protected void customizePipeline(JsonArray pipeline) {
            // Remove "count" from stage "$group" in pipeline, and add "userId" to field _id
            for (int i = 0; i < pipeline.size(); i++) {
                JsonObject stage = pipeline.get(i);
                JsonObject group = stage.getObject("$group", null);
                if (group != null) {
                    group.removeField("count");
                    JsonObject id = group.getObject("_id", null);
                    if (id != null) {
                        id.putString(TRACE_FIELD_USER, "$" + TRACE_FIELD_USER);
                    }
                    break;
                }
            }
            // Add another "$group" stage in pipeline, to count unique visitors
            JsonObject groupBy = new JsonObject().putObject("$group", new JsonObject().putObject("_id", getGroupByObject(new JsonObject(), profileIg)).putObject("count", new JsonObject().putNumber("$sum", 1)));
            pipeline.addObject(groupBy);
        }

        @Override
        protected // Set the indicator's value (instead of incrementing it)
        void writeAction(MongoDBBuilder criteriaQuery, int resultsCount, Handler<Message<JsonObject>> handler) {
            mongo.update(COLLECTIONS.stats.name(), MongoQueryBuilder.build(criteriaQuery), new MongoUpdateBuilder().set(this.getWriteKey(), resultsCount).build(), true, true, handler);
        }
    };
    indicator.setWriteKey(STATS_FIELD_UNIQUE_VISITORS);
    indicator.setWriteDate(pWriteDate);
    return indicator;
}
Also used : JsonArray(org.vertx.java.core.json.JsonArray) IndicatorGroup(org.entcore.common.aggregation.groups.IndicatorGroup) MongoDBBuilder(org.entcore.common.aggregation.filters.dbbuilders.MongoDBBuilder) ArrayList(java.util.ArrayList) JsonObject(org.vertx.java.core.json.JsonObject) Handler(org.vertx.java.core.Handler) IndicatorMongoImpl(org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl) MongoUpdateBuilder(fr.wseduc.mongodb.MongoUpdateBuilder)

Example 4 with IndicatorMongoImpl

use of org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl in project statistics by OPEN-ENT-NG.

the class IndicatorFactory method getConnectionIndicator.

// Connections
public static Indicator getConnectionIndicator(Collection<IndicatorFilterMongoImpl> filters, Date pWriteDate) {
    Collection<IndicatorGroup> indicatorGroups = new ArrayList<IndicatorGroup>();
    indicatorGroups.add(new IndicatorGroup(TRACE_FIELD_STRUCTURES).setArray(true).addAndReturnChild(TRACE_FIELD_PROFILE));
    Indicator indicator = new IndicatorMongoImpl(TRACE_TYPE_CONNEXION, filters, indicatorGroups);
    indicator.setWriteDate(pWriteDate);
    return indicator;
}
Also used : IndicatorGroup(org.entcore.common.aggregation.groups.IndicatorGroup) ArrayList(java.util.ArrayList) IndicatorMongoImpl(org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl) Indicator(org.entcore.common.aggregation.indicators.Indicator)

Aggregations

ArrayList (java.util.ArrayList)4 IndicatorGroup (org.entcore.common.aggregation.groups.IndicatorGroup)4 IndicatorMongoImpl (org.entcore.common.aggregation.indicators.mongo.IndicatorMongoImpl)4 Indicator (org.entcore.common.aggregation.indicators.Indicator)2 JsonArray (org.vertx.java.core.json.JsonArray)2 JsonObject (org.vertx.java.core.json.JsonObject)2 MongoUpdateBuilder (fr.wseduc.mongodb.MongoUpdateBuilder)1 MongoDBBuilder (org.entcore.common.aggregation.filters.dbbuilders.MongoDBBuilder)1 Handler (org.vertx.java.core.Handler)1