<commit_before>var async = require('async'),
    dbUtils = require('utils/database'),
    listener = require('../index').listener,
    io,
    socket;

module.exports = {
  initialize : Initialize,
  allDbInfo : AllDbInfo,
  setIo : SetIO,
  broadCast : BroadCast,
  allCollectionInfo : AllCollectionInfo
};

function SetIO(io_connected){
  io = io_connected;
}

function Initialize(__socket) {
  
  var listeners = Listeners();
  socket = __socket;

  async.series(listeners.map(function(listObj) {
    return function(cb) {
      socket.on(listObj.event,listObj.handler);
      cb();
    }
  }),function(err,results) {
    console.log('Added listeners for new connection');
  }); 
  
};


function Listeners() {

  var listeners = [
    {
      'event' : 'db-info',
      'handler' : DbInfo
    }
  ];

  return listeners;

};

function DbInfo() {

  var funcArray = [],
      len;

  dbUtils.list()
  .then(function(response){

    len = response.length;

    while(len--){
      funcArray.push((function(db_name){
        return function(cb){
          var dbInfo;
          dbUtils.dbInfo(db_name)
          .then(function(data){
            dbInfo = data;
            dbInfo.name = db_name;
            return dbUtils.schemaVerified(db_name);
          })
          .then(function(verified){
            dbInfo.verified = verified;
            socket.emit('db-info',dbInfo);
            cb();
          })
          .catch(function(err){
            console.log(err)
            cb();
          })
        }
      })(response[len].db_name));
    }

    async.parallel(funcArray,function(err,results){
      console.log('Done broadcasting all db information')
    });
  });
}

function AllDbInfo(){

}

function AllCollectionInfo(db_name,collections){
  
  var funcArray = [],
      len = collections.length;

  while(len--) {
    funcArray.push((function(db_name,col_name){
      return function(cb){
        var info = {};
        dbUtils.collectionInfo(db_name,col_name)
               .then(function(count){
                info.count = count;
                return dbUtils.collectionSchemaVerified(db_name,col_name);
               })
               .then(function(verified){
                info.verified = verified;
                console.log(info);
                BroadCast('collection-info',info);
                cb();
               })<commit_msg>Send collection name too on broadcast<commit_after>var async = require('async'),
    dbUtils = require('utils/database'),
    listener = require('../index').listener,
    io,
    socket;

module.exports = {
  initialize : Initialize,
  allDbInfo : AllDbInfo,
  setIo : SetIO,
  broadCast : BroadCast,
  allCollectionInfo : AllCollectionInfo
};

function SetIO(io_connected){
  io = io_connected;
}

function Initialize(__socket) {
  
  var listeners = Listeners();
  socket = __socket;

  async.series(listeners.map(function(listObj) {
    return function(cb) {
      socket.on(listObj.event,listObj.handler);
      cb();
    }
  }),function(err,results) {
    console.log('Added listeners for new connection');
  }); 
  
};


function Listeners() {

  var listeners = [
    {
      'event' : 'db-info',
      'handler' : DbInfo
    }
  ];

  return listeners;

};

function DbInfo() {

  var funcArray = [],
      len;

  dbUtils.list()
  .then(function(response){

    len = response.length;

    while(len--){
      funcArray.push((function(db_name){
        return function(cb){
          var dbInfo;
          dbUtils.dbInfo(db_name)
          .then(function(data){
            dbInfo = data;
            dbInfo.name = db_name;
            return dbUtils.schemaVerified(db_name);
          })
          .then(function(verified){
            dbInfo.verified = verified;
            socket.emit('db-info',dbInfo);
            cb();
          })
          .catch(function(err){
            console.log(err)
            cb();
          })
        }
      })(response[len].db_name));
    }

    async.parallel(funcArray,function(err,results){
      console.log('Done broadcasting all db information')
    });
  });
}

function AllDbInfo(){

}

function AllCollectionInfo(db_name,collections){
  
  var funcArray = [],
      len = collections.length;

  while(len--) {
    funcArray.push((function(db_name,col_name){
      return function(cb){
        var info = {};
        dbUtils.collectionInfo(db_name,col_name)
               .then(function(count){
                info.count = count;
                return dbUtils.collectionSchemaVerified(db_name,col_name);
               })
               .then(function(verified){
                info.verified = verified;
                info.name = col_name;
                console.log(info);
                BroadCast('collection-info',info);
                cb();
               })
{'fraction_non_alphanumeric': 0.13078848560700876, 'fraction_numerical': 0.0, 'mean_word_length': 2.065856777493606, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1626671', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1399, 'n_words': 239}