<commit_before>var http = require('http');
var dispatcher = require('httpdispatcher');
var execFile = require('child_process').execFile;

const PORT = process.argv[2] || 54321;
const CLEWARE_CONTROL = './clewarecontrol';
const DEVICE_MAPPING = {
  'dev': 'abcd',
  'qa': '3456'
};

dispatcher.setStatic('static');
dispatcher.setStaticDirname('static');

dispatcher.onGet('/dev/red', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 0));
});

dispatcher.onGet('/dev/yellow', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 1));
});

dispatcher.onGet('/dev/green', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 2));
});


dispatcher.onGet('/qa/red', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 0));
});

dispatcher.onGet('/qa/yellow', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 1));
});

dispatcher.onGet('/qa/green', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 2));
});


function triggerBuildLights(deviceNumber, value) {
  execFile(CLEWARE_CONTROL, ['-c', '1', '-d', DEVICE_MAPPING[deviceNumber]], function(error, stdout, stderr) { 
    console.log('Executing...');
    
    console.log(stdout);
    if (error) {
      console.log(error);
    }
  });
    
  return "ok! device " + deviceNumber + " set to " + value;
}






var server = http.createServer(function(req, res) {
  console.log("Request: %s", req.url);
  try {
    dispatcher.dispatch(req, res);
  } catch(err) {
    console.log(err);
  }
});

server.listen(PORT, function() {
  console.log("Server started on port %s", PORT);
});<commit_msg>fixed a couple of things<commit_after>var http = require('http');
var dispatcher = require('httpdispatcher');
var execFile = require('child_process').execFile;

const PORT = process.argv[2] || 54321;
const CLEWARE_CONTROL = 'clewarecontrol';
const DEVICE_MAPPING = {
  'dev': '900221',
  'qa': '900220'
};

dispatcher.setStatic('static');
dispatcher.setStaticDirname('static');

dispatcher.onGet('/dev/red', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 0));
});

dispatcher.onGet('/dev/yellow', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 1));
});

dispatcher.onGet('/dev/green', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('dev', 2));
});


dispatcher.onGet('/qa/red', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 0));
});

dispatcher.onGet('/qa/yellow', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 1));
});

dispatcher.onGet('/qa/green', function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end(triggerBuildLights('qa', 2));
});


function triggerBuildLights(deviceNumber, value) {
  execFile('sudo', [CLEWARE_CONTROL, '-c', '1', '-d', DEVICE_MAPPING[deviceNumber], '-as', value, 1], function(error, stdout, stderr) { 
    console.log('Executing...');
    console.log(stderr); 	  
    console.log(stdout);
    if (error) {
      console.log(error);
    }
  });
    
  return "ok! device " + deviceNumber + " set to " + value;
}

var server = http.createServer(function(req, res) {
  console.log("Request: %s", req.url);
  try {
    dispatcher.dispatch(req, res);
  } catch(err) {
    console.log(err);
  }
});

server.listen(PORT, function() {
  console.log("Server started on port %s", PORT);
});
{'fraction_non_alphanumeric': 0.2093628088426528, 'fraction_numerical': 0.020546163849154746, 'mean_word_length': 4.898773006134969, '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': '279668', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1357, 'n_words': 239}