<commit_before>const zmq = require('zmq')
const subscriber = zmq.socket('sub')
const moment = require('moment')
const sample = require('lodash/sample')
const random = require('lodash/random')
const dispatcher = require('./event-dispatcher')

const ports = [9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009, 9010, 9011, 9012]

const init = (app) => {

    subscriber.subscribe('event')

    ports.map(port => subscriber.connect('tcp://localhost:' + port))

    // subscriber.monitor(500, 0)

    subscriber.on('subscribe', (fd, ep) => console.log('-- connected to publisher'))

    subscriber.on('message', (channel, message) => {
        let m = JSON.parse(message.toString())

        m.id_mote = m.source
        m.fake_value = getTemperature()

        dispatcher.dispatchEvent(m)

        console.log(' [New Message]: ', channel.toString(), message.toString())
    })

}

const initSimulation = (app) => {

    const interval = 2000
    let counter = 0

    setInterval(() => {
        const fake_event = {
            port: random(9002, 9005),
            source: random(10, 34), // should match ids from config file
            gateway_time: new Date().getTime() - random(400, 500),
            d8: [counter++, 0, 0, 0],
            d16: [random(400, 470), 0, 0, 0],
            target: 30
        }

        dispatcher.dispatchEvent(fake_event)
    }, interval)


}

module.exports.init = init
module.exports.initSimulation = initSimulation<commit_msg>randomize event interval<commit_after>const zmq = require('zmq')
const subscriber = zmq.socket('sub')
const moment = require('moment')
const sample = require('lodash/sample')
const random = require('lodash/random')
const dispatcher = require('./event-dispatcher')

const ports = [9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009, 9010, 9011, 9012]

const init = (app) => {

    subscriber.subscribe('event')

    ports.map(port => subscriber.connect('tcp://localhost:' + port))

    // subscriber.monitor(500, 0)

    subscriber.on('subscribe', (fd, ep) => console.log('-- connected to publisher'))

    subscriber.on('message', (channel, message) => {
        let m = JSON.parse(message.toString())

        m.id_mote = m.source
        m.fake_value = getTemperature()

        dispatcher.dispatchEvent(m)

        console.log(' [New Message]: ', channel.toString(), message.toString())
    })

}

const initSimulation = (app) => {

    const max_interval = 1000
    let counter = 0

    setInterval(() => {
        const fake_event = {
            port: random(9002, 9005),
            source: random(10, 34), // should match ids from config file
            gateway_time: new Date().getTime() - random(400, 500),
            d8: [counter++, 0, 0, 0],
            d16: [random(400, 470), 0, 0, 0],
            target: 30
        }

        dispatcher.dispatchEvent(fake_event)
    }, random(500, max_interval))


}

module.exports.init = init
module.exports.initSimulation = initSimulation
{'fraction_non_alphanumeric': 0.15173116089613034, 'fraction_numerical': 0.06076035302104549, 'mean_word_length': 2.8674540682414698, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '645177', 'n_tokens_mistral': 1062, 'n_tokens_neox': 889, 'n_words': 224}