<commit_before>/*
 *
 * CODENVY CONFIDENTIAL
 * ________________
 *
 * [2012] - [2014] Codenvy, S.A.
 * All Rights Reserved.
 * NOTICE: All information contained herein is, and remains
 * the property of Codenvy S.A. and its suppliers,
 * if any. The intellectual and technical concepts contained
 * herein are proprietary to Codenvy S.A.
 * and its suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Codenvy S.A..
 */
package com.codenvy.analytics.metrics.top;

import com.codenvy.analytics.metrics.MetricType;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/** @author <NAME> */
public abstract class AbstractTopFactories extends AbstractTopMetrics {

    public static final String FACTORY_COUNT                      = "factory_count";
    public static final String BUILD_RATE                         = "build_rate";
    public static final String RUN_RATE                           = "run_rate";
    public static final String DEPLOY_RATE                        = "deploy_rate";
    public static final String ANONYMOUS_FACTORY_SESSION_RATE     = "anonymous_factory_session_rate";
    public static final String AUTHENTICATED_FACTORY_SESSION_RATE = "authenticated_factory_session_rate";
    public static final String ABANDON_FACTORY_SESSION_RATE       = "abandon_factory_session_rate";
    public static final String CONVERTED_FACTORY_SESSION_RATE     = "converted_factory_session_rate";

    public AbstractTopFactories(MetricType factoryMetricType, int dayCount) {
        super(factoryMetricType, dayCount);
    }

    @Override
    public String[] getTrackedFields() {
        return new String[]{FACTORY,
                            WS_CREATED,
                            USER_CREATED,
                            TIME,
                            BUILD_RATE,
                            RUN_RATE,
                            DEPLOY_RATE,
                            ANONYMOUS_FACTORY_SESSION_RATE,
                            AUTHENTICATED_FACTORY_SESSION_RATE,
                            ABANDON_FACTORY_SESSION_RATE,
                            CONVERTED_FACTORY_SESSION_RATE};
    }

    @Override
    public DBObject[] getSpecificDBOperations(Map<String, String> clauses) {
        List<DBObject> dbOperations = new ArrayList<>();

        dbOperations.add(
                new BasicDBObject("$match", new BasicDBObject(FACTORY, new BasicDBObject("$ne", null))));

        dbOperations.add(
                new BasicDBObject(
                        "$group",
                        new BasicDBObject(ID, "$" + FACTORY)
                                .append(WS_CREATED, new BasicDBObject("$sum", "$" + WS_CREATED))
                                .append(USER_CREATED, new BasicDBObject("$sum", "$" + USER_CREATED))
                                .append(FACTORY_COUNT, new BasicDBObject("$sum", 1))<commit_msg>DASHB-395: There are blank factories in top factories report<commit_after>/*
 *
 * CODENVY CONFIDENTIAL
 * ________________
 *
 * [2012] - [2014] Codenvy, S.A.
 * All Rights Reserved.
 * NOTICE: All information contained herein is, and remains
 * the property of Codenvy S.A. and its suppliers,
 * if any. The intellectual and technical concepts contained
 * herein are proprietary to Codenvy S.A.
 * and its suppliers and may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Codenvy S.A..
 */
package com.codenvy.analytics.metrics.top;

import com.codenvy.analytics.metrics.MetricType;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/** @author <NAME> */
public abstract class AbstractTopFactories extends AbstractTopMetrics {

    public static final String FACTORY_COUNT                      = "factory_count";
    public static final String BUILD_RATE                         = "build_rate";
    public static final String RUN_RATE                           = "run_rate";
    public static final String DEPLOY_RATE                        = "deploy_rate";
    public static final String ANONYMOUS_FACTORY_SESSION_RATE     = "anonymous_factory_session_rate";
    public static final String AUTHENTICATED_FACTORY_SESSION_RATE = "authenticated_factory_session_rate";
    public static final String ABANDON_FACTORY_SESSION_RATE       = "abandon_factory_session_rate";
    public static final String CONVERTED_FACTORY_SESSION_RATE     = "converted_factory_session_rate";

    public AbstractTopFactories(MetricType factoryMetricType, int dayCount) {
        super(factoryMetricType, dayCount);
    }

    @Override
    public String[] getTrackedFields() {
        return new String[]{FACTORY,
                            WS_CREATED,
                            USER_CREATED,
                            TIME,
                            BUILD_RATE,
                            RUN_RATE,
                            DEPLOY_RATE,
                            ANONYMOUS_FACTORY_SESSION_RATE,
                            AUTHENTICATED_FACTORY_SESSION_RATE,
                            ABANDON_FACTORY_SESSION_RATE,
                            CONVERTED_FACTORY_SESSION_RATE};
    }

    @Override
    public DBObject[] getSpecificDBOperations(Map<String, String> clauses) {
        List<DBObject> dbOperations = new ArrayList<>();

        dbOperations.add(
                new BasicDBObject("$match", new BasicDBObject(FACTORY, new BasicDBObject("$ne", ""))));

        dbOperations.add(
                new BasicDBObject(
                        "$group",
                        new BasicDBObject(ID, "$" + FACTORY)
                                .append(WS_CREATED, new BasicDBObject("$sum", "$" + WS_CREATED))
                                .append(USER_CREATED, new BasicDBObject("$sum", "$" + USER_CREATED))
                                .append(FACTORY_COUNT, new BasicDBObject("$sum", 1))
{'fraction_non_alphanumeric': 0.0736659845742169, 'fraction_numerical': 0.0033055249488430664, 'mean_word_length': 2.199395770392749, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263612', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1647, 'n_words': 438}