<commit_before>var lr = require('./linear_regression.js');

var requestsHandledPerInterval = 10
var list = []

var prediction = false;

function calculateOptimalServers(redisClient, timeInterval, seriesTag, callback){
    redisClient.get(seriesTag + ":requests:" + timeInterval, function(err, value){
        list.push(Number(value));
        if(list.length == 100){
            var s = "";
            for(var i = 0; i < 100; i++){
                s += list[i] + ","
            }
            console.log(s);
        }

        var optimalServers = Math.ceil(value / requestsHandledPerInterval);
        callback(timeInterval, optimalServers);
    });
}


function createEmitOptimal(io, series){
    return function(timeInterval, optimalServers){
        io.emit('optimal-servers', JSON.stringify({"series": series, "timeInterval": timeInterval, "optimalServers": optimalServers}));
    }
}

function predictOptimal(average, redisClient, timeInterval, callback){
    calculateOptimalServers(redisClient, timeInterval, "training", function(intervalMinusOneYear, tMinusOneYear){
        calculateOptimalServers(redisClient, timeInterval - 10000, "testing", function(intervalMinusOneHour, tMinusOneHour){

            if(intervalMinusOneHour == 0){
                callback(tMinusOneYear);
            }
            else {
                callback(Math.ceil(lr.predict(tMinusOneYear,tMinusOneHour)));
            }
        });
    });
}

var currentScaling = 3;
function scaleBasedOnCurrentUsage(average, redisClient, timeInterval, callback){
    console.log(average);
    if(average < 30){
        currentScaling -= 1;
    }
    else if(average > 80){
        currentScaling += 1;
    }

    if(currentScaling < 1){
        currentScaling = 1;
    } else if(currentScaling > 10){
        currentScaling = 10;
    }

    callback(Math.ceil(currentScaling));
}

function createEmitMLData(io){<commit_msg>Modify scaling params<commit_after>var lr = require('./linear_regression.js');

var requestsHandledPerInterval = 10
var list = []

var prediction = false;

function calculateOptimalServers(redisClient, timeInterval, seriesTag, callback){
    redisClient.get(seriesTag + ":requests:" + timeInterval, function(err, value){
        list.push(Number(value));
        if(list.length == 100){
            var s = "";
            for(var i = 0; i < 100; i++){
                s += list[i] + ","
            }
            console.log(s);
        }

        var optimalServers = Math.ceil(value / requestsHandledPerInterval);
        callback(timeInterval, optimalServers);
    });
}


function createEmitOptimal(io, series){
    return function(timeInterval, optimalServers){
        io.emit('optimal-servers', JSON.stringify({"series": series, "timeInterval": timeInterval, "optimalServers": optimalServers}));
    }
}

function predictOptimal(average, redisClient, timeInterval, callback){
    calculateOptimalServers(redisClient, timeInterval, "training", function(intervalMinusOneYear, tMinusOneYear){
        calculateOptimalServers(redisClient, timeInterval - 10000, "testing", function(intervalMinusOneHour, tMinusOneHour){

            if(intervalMinusOneHour == 0){
                callback(tMinusOneYear);
            }
            else {
                callback(Math.ceil(lr.predict(tMinusOneYear,tMinusOneHour)));
            }
        });
    });
}

var currentScaling = 3;
function scaleBasedOnCurrentUsage(average, redisClient, timeInterval, callback){
    console.log(average);
    if(average < 30){
        currentScaling -= 1;
    }
    else if(average > 75){
        currentScaling += 1;
    }

    if(currentScaling < 1){
        currentScaling = 1;
    } else if(currentScaling > 10){
        currentScaling = 10;
    }

    callback(Math.ceil(currentScaling));
}

function createEmitMLData(io){
{'fraction_non_alphanumeric': 0.12125984251968504, 'fraction_numerical': 0.014698162729658792, 'mean_word_length': 2.9656607700312176, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 7, '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': '3587269', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1103, 'n_words': 211}