<commit_before>// ##################################################
// ############## public ############################
// ##################################################

function runTests() {
    var devLogSheet = "1CTqDO_-F1tIuZrEBWe16bN65x52cV86eo2HlHfFl_aA";
    // https://docs.google.com/spreadsheets/d/1CTqDO_-F1tIuZrEBWe16bN65x52cV86eo2HlHfFl_aA/edit#gid=1854668337
    gasc.logger.useBetterLogOnExternalSpreadsheet(devLogSheet);

    gasc.test.runAllTests();
}


/**
 * Creates the menu item.
 */
function onOpen() {

    gasc.logger.useBetterLogOnOpenSpreadsheet();

    var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();

    var ui = SpreadsheetApp.getUi();
    // Or DocumentApp or FormApp.
    ui.createMenu('Analytics')
        .addItem('Run query in active range', 'directQuery')
        .addSeparator()
        .addSubMenu(ui.createMenu('debug')
            .addItem('Schedule queries in active range to queue', 'scheduleActiveRange'))
        .addToUi();
}

function directQuery() {
    gasc.env.setupSpreadsheetEnvironment();
    gasc.env.setEnvironmentToProduction();
    gasc.workflow.directQuery.initAndRun();
}

function scheduleActiveRange() {
    gasc.env.setupSpreadsheetEnvironment();
    gasc.env.setEnvironmentToProduction();
    gasc.workflow.scheduleActiveRange.initAndRun();
}


/**
 * Runs a request against the Google Analytics API and writes result to the below the formula cell.
 * In this debug mode, the log is shown in a modalwindow after the function was executed.
 * Definitions: https://developers.google.com/analytics/devguides/reporting/core/dimsmets
 *
 * example call:
 * =ANALYTICSB("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions")
 * =ANALYTICSB("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions";"sessions::conditions::ga:pagePath==/";"";"";"";0,1,true,true)
 *
 * @param {string} analyticsId The Google Analytics API Key. It can be retrieved via the menu: Google Analytics -> Find Profile / Ids
 * @param {string} startDate The first day starting at 00:00:00 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} endDate The last day ending at 23:59:59 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} metrics The metric of the analysis like ga:pagePath
 * @param {string} [segment] the segment as a string which shall be applied
 * @param {string} [filter] the filter as a string which shall be applied
 * @param {string} [dimension] The dimension according to which the result is split upon.
 * @param {string} [sort] the sorting order as a string which shall be applied
 * @param {int} [startIndex] the offset of the resultset starting at 0
 * @param {int} [maxResults] the maximum number of results. WARNING >1 overwrites the columns below and on the right
 * @param {boolean} [showHeadersInResult] if true the description of the data is added to the result numbers
 * @param {string} [samplingLevel] the sample level of analytics. Options: DEFAULT or FASTER or HIGHER_PRECISION
 * @param {string} [fields] Selector specifying a subset of fields to include in the response.
 * @return The resulting array of the request.
 * @customfunction
 */

function ANALYTICSB(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults, showHeadersInResult,  samplingLevel, fields) {
    var config =  gasc.customFunction.baseFunction(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields);
    config.presParam.positionOfResults = gasc.model.PresParam.PositionOfResults.BELOW;
    return JSON.stringify(config);
}

/**
 * Runs a request against the Google Analytics API and writes result to the below the formula cell.
 * In this debug mode, the log is shown in a modalwindow after the function was executed.
 * Definitions: https://developers.google.com/analytics/devguides/reporting/core/dimsmets
 *
 * example call:
 * =ANALYTICSR("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions")
 * =ANALYTICSR("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions";"sessions::conditions::ga:pagePath==/";"";"";"";0,1,true,true)
 *
 * @param {string} analyticsId The Google Analytics API Key. It can be retrieved via the menu: Google Analytics -> Find Profile / Ids
 * @param {string} startDate The first day starting at 00:00:00 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} endDate The last day ending at 23:59:59 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} metrics The metric of the analysis like ga:pagePath
 * @param {string} [segment] the segment as a string which shall be applied
 * @param {string} [filter] the filter as a string which shall be applied
 * @param {string} [dimension] The dimension according to which the result is split upon.
 * @param {string} [sort] the sorting order as a string which shall be applied
 * @param {int} [startIndex] the offset of the resultset starting at 0
 * @param {int} [maxResults] the maximum number of results. WARNING >1 overwrites the columns below and on the right
 * @param {boolean} [showHeadersInResult] if true the description of the data is added to the result numbers
 * @param {string} [samplingLevel] the sample level of analytics. Options: DEFAULT or FASTER or HIGHER_PRECISION
 * @param {string} [fields] Selector specifying a subset of fields to include in the response.
 * @return The resulting array of the request.
 * @customfunction
 */

function ANALYTICSR(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields) {
    var config =  gasc.customFunction.baseFunction(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields);
    config.presParam.positionOfResults = gasc.model.PresParam.PositionOfResults.RIGHT;
    return JSON.stringify(config);
}

// ##########################################
// ##############  gasc.namespace ###########
// ##########################################

var gasc = gasc || {};
gasc.namespace = gasc.namespace || {};

/**
 * Based up Kenneth Truyers' Work
 * http://www.kenneth-truyers.net/2013/04/27/javascript-namespaces-and-modules/
 */
gasc.namespace.createNs = function (namespace) {
    var nsparts = namespace.split(".");
    var parent = gasc;

    // we want to be able to include or exclude the root namespace so we strip
    // it if it's in the namespace
    if (nsparts[0] === "gasc") {
        nsparts = nsparts.slice(1);
    }

    // loop through the parts and create a nested namespace if necessary
    for (var i = 0; i < nsparts.length; i++) {
        var partname = nsparts[i];
        // check if the current parent already has the namespace declared
        // if it isn't, then create it
        if (typeof parent[partname] === "undefined") {
            parent[partname] = {};
        }
        // get a reference to the deepest element in the hierarchy so far
        parent = parent[partname];
    }
    // the parent is now constructed with empty namespaces and can be used.
    // we return the outermost namespace
    return parent;
};

// ##########################################
// ##############  gasc.env  ################
// ##########################################

gasc.env = function () {

    var currentEnvironment; // [production, testing]

    this.setEnvironmentToTesting = function() {
        currentEnvironment = 'testing';
    };

    this.setEnvironmentToProduction = function() {
        currentEnvironment = 'production';
    };

    this.environmentIsTesting = function() {
        return currentEnvironment === 'testing';
    };

    this.environmentIsProduction = function() {
        return currentEnvironment === 'production';
    };

    this.setupSpreadsheetEnvironment = function() {
        gasc.logger.useBetterLogOnOpenSpreadsheet();
    };
};

// ##########################################
// ##############  gasc.logger ##############
// ##########################################

(function(undefined ){

    var logFine = true;
    var logInfo = true;
    var logSevere = true;


    this.useBetterLogOnExternalSpreadsheet = function (loggingSpreadsheetId) {
        this.logInterface = BetterLog.useSpreadsheet(loggingSpreadsheetId); // for BetterLog https://sites.google.com/site/scriptsexamples/custom-methods/betterlog
    };

    this.useBetterLogOnOpenSpreadsheet = function () {
        this.logInterface = BetterLog.useSpreadsheet();
    };


    this.useGasConsole = function () {
        this.logInterface = console; // for GAS Console https://github.com/tyskdm/gas-console<commit_msg>environment are correctly put into namespace<commit_after>// ##################################################
// ############## public ############################
// ##################################################

function runTests() {
    var devLogSheet = "<KEY>";
    // https://docs.google.com/spreadsheets/d/1CTqDO_-F1tIuZrEBWe16bN65x52cV86eo2HlHfFl_aA/edit#gid=1854668337
    gasc.logger.useBetterLogOnExternalSpreadsheet(devLogSheet);

    gasc.test.runAllTests();
}


/**
 * Creates the menu item.
 */
function onOpen() {

    gasc.logger.useBetterLogOnOpenSpreadsheet();

    var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();

    var ui = SpreadsheetApp.getUi();
    // Or DocumentApp or FormApp.
    ui.createMenu('Analytics')
        .addItem('Run query in active range', 'directQuery')
        .addSeparator()
        .addSubMenu(ui.createMenu('debug')
            .addItem('Schedule queries in active range to queue', 'scheduleActiveRange'))
        .addToUi();
}

function directQuery() {
    gasc.env.setupSpreadsheetEnvironment();
    gasc.env.setEnvironmentToProduction();
    gasc.workflow.directQuery.initAndRun();
}

function scheduleActiveRange() {
    gasc.env.setupSpreadsheetEnvironment();
    gasc.env.setEnvironmentToProduction();
    gasc.workflow.scheduleActiveRange.initAndRun();
}


/**
 * Runs a request against the Google Analytics API and writes result to the below the formula cell.
 * In this debug mode, the log is shown in a modalwindow after the function was executed.
 * Definitions: https://developers.google.com/analytics/devguides/reporting/core/dimsmets
 *
 * example call:
 * =ANALYTICSB("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions")
 * =ANALYTICSB("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions";"sessions::conditions::ga:pagePath==/";"";"";"";0,1,true,true)
 *
 * @param {string} analyticsId The Google Analytics API Key. It can be retrieved via the menu: Google Analytics -> Find Profile / Ids
 * @param {string} startDate The first day starting at 00:00:00 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} endDate The last day ending at 23:59:59 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} metrics The metric of the analysis like ga:pagePath
 * @param {string} [segment] the segment as a string which shall be applied
 * @param {string} [filter] the filter as a string which shall be applied
 * @param {string} [dimension] The dimension according to which the result is split upon.
 * @param {string} [sort] the sorting order as a string which shall be applied
 * @param {int} [startIndex] the offset of the resultset starting at 0
 * @param {int} [maxResults] the maximum number of results. WARNING >1 overwrites the columns below and on the right
 * @param {boolean} [showHeadersInResult] if true the description of the data is added to the result numbers
 * @param {string} [samplingLevel] the sample level of analytics. Options: DEFAULT or FASTER or HIGHER_PRECISION
 * @param {string} [fields] Selector specifying a subset of fields to include in the response.
 * @return The resulting array of the request.
 * @customfunction
 */

function ANALYTICSB(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults, showHeadersInResult,  samplingLevel, fields) {
    var config =  gasc.customFunction.baseFunction(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields);
    config.presParam.positionOfResults = gasc.model.PresParam.PositionOfResults.BELOW;
    return JSON.stringify(config);
}

/**
 * Runs a request against the Google Analytics API and writes result to the below the formula cell.
 * In this debug mode, the log is shown in a modalwindow after the function was executed.
 * Definitions: https://developers.google.com/analytics/devguides/reporting/core/dimsmets
 *
 * example call:
 * =ANALYTICSR("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions")
 * =ANALYTICSR("ga:53113218";"2015-01-01";"2015-01-31";"ga:sessions";"sessions::conditions::ga:pagePath==/";"";"";"";0,1,true,true)
 *
 * @param {string} analyticsId The Google Analytics API Key. It can be retrieved via the menu: Google Analytics -> Find Profile / Ids
 * @param {string} startDate The first day starting at 00:00:00 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} endDate The last day ending at 23:59:59 which shall be included in the analysis. Value has to be a constant, so references to now() are not accepted.
 * @param {string} metrics The metric of the analysis like ga:pagePath
 * @param {string} [segment] the segment as a string which shall be applied
 * @param {string} [filter] the filter as a string which shall be applied
 * @param {string} [dimension] The dimension according to which the result is split upon.
 * @param {string} [sort] the sorting order as a string which shall be applied
 * @param {int} [startIndex] the offset of the resultset starting at 0
 * @param {int} [maxResults] the maximum number of results. WARNING >1 overwrites the columns below and on the right
 * @param {boolean} [showHeadersInResult] if true the description of the data is added to the result numbers
 * @param {string} [samplingLevel] the sample level of analytics. Options: DEFAULT or FASTER or HIGHER_PRECISION
 * @param {string} [fields] Selector specifying a subset of fields to include in the response.
 * @return The resulting array of the request.
 * @customfunction
 */

function ANALYTICSR(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields) {
    var config =  gasc.customFunction.baseFunction(analyticsId, startDate, endDate, metrics, segment, filter, dimension, sort, startIndex, maxResults,showHeadersInResult,  samplingLevel, fields);
    config.presParam.positionOfResults = gasc.model.PresParam.PositionOfResults.RIGHT;
    return JSON.stringify(config);
}

// ##########################################
// ##############  gasc.namespace ###########
// ##########################################

var gasc = gasc || {};
gasc.namespace = gasc.namespace || {};

/**
 * Based up Kenneth Truyers' Work
 * http://www.kenneth-truyers.net/2013/04/27/javascript-namespaces-and-modules/
 */
gasc.namespace.createNs = function (namespace) {
    var nsparts = namespace.split(".");
    var parent = gasc;

    // we want to be able to include or exclude the root namespace so we strip
    // it if it's in the namespace
    if (nsparts[0] === "gasc") {
        nsparts = nsparts.slice(1);
    }

    // loop through the parts and create a nested namespace if necessary
    for (var i = 0; i < nsparts.length; i++) {
        var partname = nsparts[i];
        // check if the current parent already has the namespace declared
        // if it isn't, then create it
        if (typeof parent[partname] === "undefined") {
            parent[partname] = {};
        }
        // get a reference to the deepest element in the hierarchy so far
        parent = parent[partname];
    }
    // the parent is now constructed with empty namespaces and can be used.
    // we return the outermost namespace
    return parent;
};

// ##########################################
// ##############  gasc.env  ################
// ##########################################

(function(undefined ){

    var currentEnvironment; // [production, testing]

    this.setEnvironmentToTesting = function() {
        currentEnvironment = 'testing';
    };

    this.setEnvironmentToProduction = function() {
        currentEnvironment = 'production';
    };

    this.environmentIsTesting = function() {
        return currentEnvironment === 'testing';
    };

    this.environmentIsProduction = function() {
        return currentEnvironment === 'production';
    };

    this.setupSpreadsheetEnvironment = function() {
        gasc.logger.useBetterLogOnOpenSpreadsheet();
    };
}).apply(gasc.namespace.createNs("gasc.env"));

// ##########################################
// ##############  gasc.logger ##############
// ##########################################

(function(undefined ){

    var logFine = true;
    var logInfo = true;
    var logSevere = true;


    this.useBetterLogOnExternalSpreadsheet = function (loggingSpreadsheetId) {
        this.logInterface = BetterLog.useSpreadsheet(loggingSpreadsheetId); // for BetterLog https://sites.google.com/site/scriptsexamples/custom-methods/betterlog
    };

    this.useBetterLogOnOpenSpreadsheet = function () {
        this.logInterface = BetterLog.useSpreadsheet();
    };


    this.useGasConsole = function () {
        this.logInterface = console; // for GAS Console https://github.com/tyskdm/gas-console
{'fraction_non_alphanumeric': 0.15529923102641258, 'fraction_numerical': 0.018444221553549536, 'mean_word_length': 4.188493784330731, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, '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': '3542649', 'n_tokens_mistral': 5327, 'n_tokens_neox': 4990, 'n_words': 1634}