<commit_before>// for node module

// create constructor
var filtr = function() {
    this.config = {
        limitCount: 3,
        limitTime: 1000, 
        queueTimer: 1000
    };
    this.dataStore = {};
    this.lastQueue = {};
    this.qRunning = {}; 
};

// simple function to add an item to a dataStore object where id = obj.key and opts = json options
filtr.prototype.addStore = function(id, opts) {
    (this.dataStore[id] = this.dataStore[id] || []).push(opts); 
};

// basic filter function, takes an id, opts, and callbacks for success and fail
filtr.prototype.limit = function(id, opts, success, fail) {
    
    //TODO: err check user inputs
    
    opts = opts || {};
    opts.limitCount = opts.limitCount || this.config.limitCount;
    opts.limitTime = opts.limitTime || this.config.limitTime;
    
    var now = Date.now();

    this.addStore(id, {ts:now});
    
    for (var i = this.dataStore[id].length - 1; i >=0; i--) {
        if ((this.dataStore[id][i].ts + opts.limitTime) < now) {
            this.dataStore[id].splice(i, 1);
        }
    }
    
    if (this.dataStore[id].length > opts.limitCount) {
        return fail();
    }
    else {
        return success();
    }
            
};

// basic queue function, takes id, opts, function callback and queue ended callback
filtr.prototype.queue = function(id, opts, callback, end) {

    //TODO: err check user inputs
    
    this.qRunning[id] = this.qRunning[id] || false;

    opts = opts || {};
    opts.queueTimer = opts.queueTimer || this.config.queueTimer;
    
    var now = Date.now();
    
    // just add to the array 
    this.addStore(id, {ts:now, action:callback, stop:end});

    // check the queue now to see if we need to kick start it
    if (!(this.qRunning[id])) {
        this.runQueue(id);
    }

};

// function run by queue to actually execute the queue
filtr.prototype.runQueue = function(id) {

    var self = this;
    // if anything is in dataStore, run the queue
    if (this.dataStore[id].length > 0) {
        this.qRunning[id] = true;
        setTimeout(function() { 
            // run the first item in the array
            self.dataStore[id][0].action();
            self.lastQueue[id] = self.dataStore[id][0];
            // shift it out
            self.dataStore[id].shift();
            // run this function again 
            self.runQueue(id);
        }, self.config.queueTimer);
    }
    else {
        this.qRunning[id] = false; 
        this.lastQueue[id].stop();
    }
 
};

module.exports = filtr;<commit_msg>rename the main function module exports qfiltr now to match the project name<commit_after>// for node module

// create constructor
var qfilter = function() {
    this.config = {
        limitCount: 3,
        limitTime: 1000, 
        queueTimer: 1000
    };
    this.dataStore = {};
    this.lastQueue = {};
    this.qRunning = {}; 
};

// simple function to add an item to a dataStore object where id = obj.key and opts = json options
qfilter.prototype.addStore = function(id, opts) {
    (this.dataStore[id] = this.dataStore[id] || []).push(opts); 
};

// basic filter function, takes an id, opts, and callbacks for success and fail
qfilter.prototype.limit = function(id, opts, success, fail) {
    
    //TODO: err check user inputs
    
    opts = opts || {};
    opts.limitCount = opts.limitCount || this.config.limitCount;
    opts.limitTime = opts.limitTime || this.config.limitTime;
    
    var now = Date.now();

    this.addStore(id, {ts:now});
    
    for (var i = this.dataStore[id].length - 1; i >=0; i--) {
        if ((this.dataStore[id][i].ts + opts.limitTime) < now) {
            this.dataStore[id].splice(i, 1);
        }
    }
    
    if (this.dataStore[id].length > opts.limitCount) {
        return fail();
    }
    else {
        return success();
    }
            
};

// basic queue function, takes id, opts, function callback and queue ended callback
qfilter.prototype.queue = function(id, opts, callback, end) {

    //TODO: err check user inputs
    
    this.qRunning[id] = this.qRunning[id] || false;

    opts = opts || {};
    opts.queueTimer = opts.queueTimer || this.config.queueTimer;
    
    var now = Date.now();
    
    // just add to the array 
    this.addStore(id, {ts:now, action:callback, stop:end});

    // check the queue now to see if we need to kick start it
    if (!(this.qRunning[id])) {
        this.runQueue(id);
    }

};

// function run by queue to actually execute the queue
qfilter.prototype.runQueue = function(id) {

    var self = this;
    // if anything is in dataStore, run the queue
    if (this.dataStore[id].length > 0) {
        this.qRunning[id] = true;
        setTimeout(function() { 
            // run the first item in the array
            self.dataStore[id][0].action();
            self.lastQueue[id] = self.dataStore[id][0];
            // shift it out
            self.dataStore[id].shift();
            // run this function again 
            self.runQueue(id);
        }, self.config.queueTimer);
    }
    else {
        this.qRunning[id] = false; 
        this.lastQueue[id].stop();
    }
 
};

module.exports = qfilter;
{'fraction_non_alphanumeric': 0.1359487279083317, 'fraction_numerical': 0.0058263740532142165, 'mean_word_length': 2.208722741433022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5717805', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1586, 'n_words': 435}