<commit_before>var _ = require('lodash'),
    socketio = require('socket.io');

module.exports = function (app, options) {
  'use strict';
  var
    io = socketio(app),
    config = options.config,
    nsApp = io.of('/devicewallapp'),
    nsCtrl = io.of('/devicewall'),
    devices = require('./devices'),
    instances = require('./instances');

  // Device
  nsApp.on('connection', function (socket) {
    console.log('Test device connected!');

    socket.on('update', function (data) {
      devices.update(data);
      nsCtrl.emit('update', devices.toJSON());
    });

    socket.on('started', function (label) {
      var device = devices.find(label);
      if (device) {
        device.set('status', 'running');
        nsCtrl.emit('update', devices.toJSON());
      }
    });

    socket.on('idling', function (label) {
      var device = devices.find(label);
      if (device) {
        device.set('status', 'idle');
        device.set('updated', +new Date());
        devices.update(device.toJSON());
        app.emit('update-devices');
        nsCtrl.emit('update', devices.toJSON());
      }
    });

    socket.on('disconnect', function () {
      console.log('DeviceWall device disconnected.');
    });

    socket.on('check-platform', function(data, fn) {
      var appPlatform = '';
      var device = devices.find(data.label);
      if (device) {
        appPlatform = device.appPlatform;
      }
      fn({appPlatform: appPlatform});
    });

  });

  // Control panel
  nsCtrl.on('connection', function (socket) {<commit_msg>change socket event listeners to more readable<commit_after>var _ = require('lodash'),
    socketio = require('socket.io');

module.exports = function (app, options) {
  'use strict';
  var
    io = socketio(app),
    config = options.config,
    nsApp = io.of('/devicewallapp'),
    nsCtrl = io.of('/devicewall'),
    devices = require('./devices'),
    instances = require('./instances');

  // Device
  nsApp.on('connection', function (socket) {
    console.log('Test device connected!');

    socket.on('update', update);
    socket.on('started', started);
    socket.on('idling', idling);
    socket.on('disconnect', disconnect);
    socket.on('check-platform', checkPlatform);

    function update(data) {
      devices.update(data);
      nsCtrl.emit('update', devices.toJSON());
    }

    function started(label) {
      var device = devices.find(label);
      if (device) {
        device.set('status', 'running');
        nsCtrl.emit('update', devices.toJSON());
      }
    }

    function idling(label) {
      var device = devices.find(label);
      if (device) {
        device.set('status', 'idle');
        device.set('updated', +new Date());
        devices.update(device.toJSON());
        app.emit('update-devices');
        nsCtrl.emit('update', devices.toJSON());
      }
    }

    function disconnect() {
      console.log('DeviceWall device disconnected.');
    }

    function checkPlatform(data, fn) {
      var appPlatform = '';
      var device = devices.find(data.label);
      if (device) {
        appPlatform = device.appPlatform;
      }
      fn({appPlatform: appPlatform});
    }

  });

  // Control panel
  nsCtrl.on('connection', function (socket) {
{'fraction_non_alphanumeric': 0.17017326732673269, 'fraction_numerical': 0.0, 'mean_word_length': 2.7418981481481484, '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': '300978', 'n_tokens_mistral': 964, 'n_tokens_neox': 943, 'n_words': 191}