<commit_before>/*
 * macwatch
 * https://github.com/goliatone/macwatch
 *
 * Copyright (c) 2015 goliatone
 * Licensed under the MIT license.
 */

// 'use strict';
var extend = require('gextend');
var arpscan = require('arpscan');

var DEFAULTS = {
    mac: [],
    interval: 100,
    goneAfter: 5 * 60 * 1000,
    command: onStateChanged
};

var macTargets = {};

var MAC = '';
var GONE = 0;
var INTERVAL = 0;

var lapse = 0;
var unseen = 0;
var lastFound = 0;
var INDEX = 0;
var FINDEX=0;

var active = {
    cache: {},
    items: []
};

function interval(){

    arpscan(onResult);
    INDEX++;
}


function onResult(err, data){
    if(err) { throw new Error(err); }

    var seen = [];
    var now = Date.now();
    // var oldActive = active.items.concat();

    //Iterate over all found items:
    data.forEach(function(item){
        item.mac = item.mac.toUpperCase();
        //is the current item on our list of targeted MACs?
        if(macTargets.hasOwnProperty(item.mac)) {

            //item haven't been cached cached?
            if(!active.cache[item.mac]){
                item.lastseen = 0;
                active.items.push(item);
                active.cache[item.mac] = item;
            }

            //refresh timestamp to last seen
            active.cache[item.mac].lastseen = now;

            seen.push(item.mac);
        }
    });

    //We need to go over all targets
    // (macTargets.length !== seen.length) &&
    var remove = [];
    active.items.forEach(function(item, i){
        if(seen.indexOf() !== -1) return
        if((now - item.lastseen) > GONE){
            delete active.cache[item.mac];
            remove.push(i);
        }
    });

    var aryWithoutSeven = ary.filter(function(value) { return value != 'seven' });


    //has the state changed? if so, trigger command

    setTimeout(interval, INTERVAL);
}


function onStateChanged(data){

}

process.on('SIGINT', function() {
    // console.log('Got SIGINT.  Press Control-D to exit.');
    // clean up!
    process.kill();
});


module.exports = function start(options){
    options = extend({}, DEFAULTS, options);

    options.mac.forEach(function(item){
        macTargets[item.toUpperCase()] = true;
    });


    GONE = options.goneAfter;
    INTERVAL = options.interval;

    interval();

    // emiter = new events.EventEmitter();
    // return emiter;
};<commit_msg>LIB: clean up<commit_after>/*
 * macwatch
 * https://github.com/goliatone/macwatch
 *
 * Copyright (c) 2015 goliatone
 * Licensed under the MIT license.
 */

// 'use strict';
var extend = require('gextend');
var arpscan = require('arpscan');

var DEFAULTS = {
    mac: [],
    interval: 100,
    goneAfter: 30 * 1000,
    // goneAfter: 5 * 60 * 1000,
    command: onStateChanged
};

var macTargets = {};

var MAC = '';
var GONE = 0;
var INTERVAL = 0;
var CALLBACK;

var active = {
    cache: {},
    items: []
};

function interval(){

    arpscan(onResult);
}


function onResult(err, data){
    if(err) { throw new Error(err); }

    var now = Date.now();
    var changes = false;

    //Iterate over all found items:
    data.forEach(function(item){
        item.mac = item.mac.toUpperCase();
        //is the current item on our list of targeted MACs?
        if(!macTargets.hasOwnProperty(item.mac)) return;

        //item haven't been cached cached?
        if(!active.cache[item.mac]){
            changes = true;
            active.items.push(item);
            active.cache[item.mac] = item;
        }

        //refresh TTL
        active.cache[item.mac].lastseen = now;
    });

    //We need to go over all targets
    active.items = active.items.filter(function(item){
        //Is the time elapsed since last sight greater than threshold?
        if((now - item.lastseen) > GONE){
            changes = true;
            delete active.cache[item.mac];
            return false; //filter out
        }
        return true;
    });

    if(changes){
        CALLBACK(active.items);
    }



    //has the state changed? if so, trigger command

    setTimeout(interval, INTERVAL);
}


function onStateChanged(data){

}

process.on('SIGINT', function() {
    // console.log('Got SIGINT.  Press Control-D to exit.');
    // clean up!
    process.kill();
});


module.exports = function start(options){
    options = extend({}, DEFAULTS, options);

    options.mac.forEach(function(item){
        macTargets[item.toUpperCase()] = true;
    });


    GONE = options.goneAfter;
    INTERVAL = options.interval;
    CALLBACK = options.command;

    interval();

    // emiter = new events.EventEmitter();
    // return emiter;
};
{'fraction_non_alphanumeric': 0.14397224631396358, 'fraction_numerical': 0.009757155247181267, 'mean_word_length': 2.304441260744986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '6294326', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1422, 'n_words': 369}