<commit_before>#!/usr/bin/node

/**
 * This script is meant to be used from root directory.
 */

const fs = require('fs')

const defaultExperimentGroupType = 'notAffected'
const groupTypeKey = 'EXPERIMENT_GROUP_TYPE'
const dotenvPath = '.env' // Warning: this will fail if used from somewhere else
const encoding = 'utf8'
const dotenvExperimentGroupDoc = '# Possible values: treatment, control or notAffected'
const experimentGroupTypes = ['treatment', 'control', defaultExperimentGroupType]

setExperimentGroupType(process.argv[2])

function setExperimentGroupType(experimentGroupType) {

    try {
        const data = fs.readFileSync(dotenvPath, encoding)
        const lines = splitLines(data.toString())
        const savedExperimentGroupIndex = lines.findIndex(l => l.startsWith(groupTypeKey))
    
        if(savedExperimentGroupIndex < 0) {
            lines.push(documentedExperimentLine(experimentGroupType))
        }
        else {
            const [, currentGroup] = lines[savedExperimentGroupIndex].split('=')
            lines[savedExperimentGroupIndex] = experimentGroupTypeLine(experimentGroupType, currentGroup)
        }
    
        fs.writeFileSync(dotenvPath, joinLines(lines))
    }
    catch {
        throw Error('.env file may not exist or its format could be wrong. Please check if it exists in root directory and its format is correct.')
    }
}

function splitLines(lines) {
    return lines.split('\n')
}

function joinLines(lines) {
    return lines.join('\n')
}

/**
 * This enables to start or build the app without specifying an experiment group type
 */
function selectedExperimentGroupType(experimentGroupType) {
    return experimentGroupTypes.includes(experimentGroupType) ? experimentGroupType : undefined
}

function experimentGroupTypeLine(experimentGroupType, currentGroup = false) {<commit_msg>Script creates env if it does not exist<commit_after>#!/usr/bin/node

/**
 * This script is meant to be used from root directory.
 */

const fs = require('fs')

const defaultExperimentGroupType = 'notAffected'
const groupTypeKey = 'EXPERIMENT_GROUP_TYPE'
const dotenvPath = '.env' // Warning: this will fail if used from somewhere else
const encoding = 'utf8'
const dotenvExperimentGroupDoc = '# Possible values: treatment, control or notAffected'
const experimentGroupTypes = ['treatment', 'control', defaultExperimentGroupType]

setExperimentGroupType(process.argv[2])

function setExperimentGroupType(experimentGroupType) {

    let lines

    try {
        const data = fs.readFileSync(dotenvPath, encoding)
        lines = splitLines(data.toString())
    }
    catch {
        // File does not exist
        lines = []
    }

    const savedExperimentGroupIndex = lines.findIndex(l => l.startsWith(groupTypeKey))

    if(savedExperimentGroupIndex < 0) {
        lines.push(documentedExperimentLine(experimentGroupType))
    }
    else {
        const [, currentGroup] = lines[savedExperimentGroupIndex].split('=')
        lines[savedExperimentGroupIndex] = experimentGroupTypeLine(experimentGroupType, currentGroup)
    }

    fs.writeFileSync(dotenvPath, joinLines(lines))
}

function splitLines(lines) {
    return lines.split('\n')
}

function joinLines(lines) {
    return lines.join('\n')
}

/**
 * This enables to start or build the app without specifying an experiment group type
 */
function selectedExperimentGroupType(experimentGroupType) {
    return experimentGroupTypes.includes(experimentGroupType) ? experimentGroupType : undefined
}

function experimentGroupTypeLine(experimentGroupType, currentGroup = false) {
{'fraction_non_alphanumeric': 0.09299719887955182, 'fraction_numerical': 0.0016806722689075631, 'mean_word_length': 4.213138686131387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4605662', 'n_tokens_mistral': 995, 'n_tokens_neox': 974, 'n_words': 254}