<commit_before>/**
 * Copyright reelyActive 2015
 * We believe in an open Internet of Things
 */


var util = require('util');
var events = require('events');
var time = require('./common/util/time');

var DEFAULT_TRANSMITTERS = [ "001bc50940100000" ];
var DEFAULT_RECEIVERS = [ "001bc50940800000",
                          "001bc50940800001",
                          "001bc50940800002", ];
var DEFAULT_TIMING = { minVisibleMilliseconds: 60000,
                       maxVisibleMilliseconds: 300000,
                       minInvisibleMilliseconds: 60000,
                       maxInvisibleMilliseconds: 300000 };
var DEFAULT_ZONES = [ { receivers: DEFAULT_RECEIVERS,
                        timing: DEFAULT_TIMING } ];
var DEFAULT_PARAMETERS = { transmitters: DEFAULT_TRANSMITTERS,
                           zones: DEFAULT_ZONES }; 
var DEFAULT_MIN_BLINK_MILLISECONDS = 1000;
var DEFAULT_MAX_BLINK_MILLISECONDS = 3000;


/**
 * SequenceGenerator Class
 * Generates a sequence of events based on the given parameters.
 * @param {Object} params The parameters as a JSON object.
 * @constructor
 */
function SequenceGenerator(params) {
  var self = this;
  params = params || DEFAULT_PARAMETERS;

  prepareZones(self, params.zones, function() {
    prepareTransmitters(self, params.transmitters);
  });

  events.EventEmitter.call(this);
};
util.inherits(SequenceGenerator, events.EventEmitter);


/**
 * Prepare the array of zones.
 * @param {SequenceGenerator} instance The given SequenceGenerator instance.
 * @param {Array} zones The given zones.
 * @param {function} callback Function to call on completion.
 */
function prepareZones(instance, zones, callback) {
  instance.zones = [];

  for(var cZone = 0; cZone < zones.length; cZone++) {
    var zone = {};
    zone.receivers = [];
    for(var cReceiver = 0; cReceiver < zones[cZone].receivers.length; cReceiver++) {
      var receiver = {};
      receiver.identifier = {};
      receiver.identifier.value = zones[cZone].receivers[cReceiver]; // Assume string
      receiver.identifier.type = "Undefined";
      zone.receivers.push(receiver);
    }
    zone.timing = zones[cZone].timing;
    instance.zones.push(zone);
  }

  callback();
}


/**
 * Prepare the array of transmitters.
 * @param {SequenceGenerator} instance The given SequenceGenerator instance.<commit_msg>Added RSSI field<commit_after>/**
 * Copyright reelyActive 2015
 * We believe in an open Internet of Things
 */


var util = require('util');
var events = require('events');
var time = require('./common/util/time');

var DEFAULT_TRANSMITTERS = [ "001bc50940100000" ];
var DEFAULT_RECEIVERS = [ "001bc50940800000",
                          "001bc50940800001",
                          "001bc50940800002", ];
var DEFAULT_TIMING = { minVisibleMilliseconds: 60000,
                       maxVisibleMilliseconds: 300000,
                       minInvisibleMilliseconds: 60000,
                       maxInvisibleMilliseconds: 300000 };
var DEFAULT_ZONES = [ { receivers: DEFAULT_RECEIVERS,
                        timing: DEFAULT_TIMING } ];
var DEFAULT_PARAMETERS = { transmitters: DEFAULT_TRANSMITTERS,
                           zones: DEFAULT_ZONES }; 
var DEFAULT_MIN_BLINK_MILLISECONDS = 1000;
var DEFAULT_MAX_BLINK_MILLISECONDS = 3000;
var DEFAULT_RSSI = 128;


/**
 * SequenceGenerator Class
 * Generates a sequence of events based on the given parameters.
 * @param {Object} params The parameters as a JSON object.
 * @constructor
 */
function SequenceGenerator(params) {
  var self = this;
  params = params || DEFAULT_PARAMETERS;

  prepareZones(self, params.zones, function() {
    prepareTransmitters(self, params.transmitters);
  });

  events.EventEmitter.call(this);
};
util.inherits(SequenceGenerator, events.EventEmitter);


/**
 * Prepare the array of zones.
 * @param {SequenceGenerator} instance The given SequenceGenerator instance.
 * @param {Array} zones The given zones.
 * @param {function} callback Function to call on completion.
 */
function prepareZones(instance, zones, callback) {
  instance.zones = [];

  for(var cZone = 0; cZone < zones.length; cZone++) {
    var zone = {};
    zone.receivers = [];
    for(var cReceiver = 0; cReceiver < zones[cZone].receivers.length; cReceiver++) {
      var receiver = {};
      receiver.rssi = DEFAULT_RSSI;
      receiver.identifier = {};
      receiver.identifier.value = zones[cZone].receivers[cReceiver]; // Assume string
      receiver.identifier.type = "Undefined";
      zone.receivers.push(receiver);
    }
    zone.timing = zones[cZone].timing;
    instance.zones.push(zone);
  }

  callback();
}


/**
 * Prepare the array of transmitters.
 * @param {SequenceGenerator} instance The given SequenceGenerator instance.
{'fraction_non_alphanumeric': 0.1093254387819835, 'fraction_numerical': 0.039543243814759994, 'mean_word_length': 3.174757281553398, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3361202', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1360, 'n_words': 340}