<commit_before>// ################### dependencies #############################
var https = require('https');
var fs = require("fs");
var five = require("johnny-five");

// ################### init configuration #############################
var configJSON = fs.readFileSync("config.json");
var config = JSON.parse(configJSON);
var teamcityHost = config.teamcityHost;
var teamcityPort = config.teamcityPort;
var tcProject = config.tcProject;
var tcUser = config.teamcityUser;
var tcPW = config.teamcityPassword;
var tcPollingInterval = config.tcPollingIntervalInSeconds * 1000;

var runningBuildsEndpoint = "";
if (tcUser == "guest"){
  runningBuildsEndpoint = '/guestAuth/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'running:true';
} else {
  runningBuildsEndpoint = '/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'running:true';
}

var latestBuildEndpoint = "";
if (tcUser == "guest"){
  latestBuildEndpoint = '/guestAuth/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'count:1';
} else {
  latestBuildEndpoint = '/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'count:1';
}

// ################### STATES #############################
var FETCHING_BUILD_CONFIGURATIONS = false;
var BUILDSTATE = -1 // 0 = red/failure, 1 = yellow/running, 2 = green/success

// ################### johnny-five / Arduino Prep #############################
var board = new five.Board();
var greenLamp,yellowLamp,redLamp;
var state = 0x00;

var initLamps = function(){
  greenLamp = new five.Pin(13);
  yellowLamp = new five.Pin(12);
  redLamp = new five.Pin(11);
}

var switchOffAllLights = function(){
  greenLamp.low();
  yellowLamp.low();
  redLamp.low();
}

// ################### HTTP-Config #############################
var getHttpOptions = function(endpoint){
  if(tcUser == "guest"){
    return {
        host: teamcityHost,
        port: teamcityPort,
        path: endpoint,
        method: 'GET',
        headers: {
          accept: 'application/json'
      }
    }
  } else {
    return {
        host: teamcityHost,
        port: teamcityPort,
        path: endpoint,
        auth: tcUser + ':' + tcPW,
        method: 'GET',
        headers: {
          accept: 'application/json'
      }
    }
  }
};

// ################### Animation / Visualization #############################

var animateSuccess = function(){
  console.log("SUCCESS");
  switchOffAllLights();
  greenLamp.high();
};

var animateRunning = function(){
  console.log("RUNNING");
  switchOffAllLights();
  // blinking animation
  board.loop(500, function() {
    yellowLamp.write(state ^= 0x01);
  });
};

var animateFailure = function(){
  console.log("FAILURE");
  switchOffAllLights();
  redLamp.high();
};

var visualizeCurrentState = function(newState){
  console.log("visualizeCurrentState() called");
  // change BUILDSTATE if it differs from previous
  if (newState!=BUILDSTATE){
    console.log("BUILDSTATE changed");
    BUILDSTATE=newState;
    switch(BUILDSTATE) {
      // green/success
      case 2:
          animateSuccess();
          break;
      // yellow/running
      case 1:
          animateRunning();
          break;
      // red/failure
      default:
          animateFailure();<commit_msg>changes running animation implementation<commit_after>// Why Javascript?
// Atwood's Law: Any application that can be written in Javascript, will eventually be written in Javascript.
// - <NAME>, July 17, 2007
//
// Copyright 2016 <NAME>

// ################### dependencies #############################
var https = require('https');
var fs = require("fs");
var five = require("johnny-five");

// ################### init configuration #############################
var configJSON = fs.readFileSync("config.json");
var config = JSON.parse(configJSON);
var teamcityHost = config.teamcityHost;
var teamcityPort = config.teamcityPort;
var tcProject = config.tcProject;
var tcUser = config.teamcityUser;
var tcPW = config.teamcityPassword;
var tcPollingInterval = config.tcPollingIntervalInSeconds * 1000;

var runningBuildsEndpoint = "";
if (tcUser == "guest"){
  runningBuildsEndpoint = '/guestAuth/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'running:true';
} else {
  runningBuildsEndpoint = '/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'running:true';
}

var latestBuildEndpoint = "";
if (tcUser == "guest"){
  latestBuildEndpoint = '/guestAuth/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'count:1';
} else {
  latestBuildEndpoint = '/app/rest/builds/?locator='+'project:' + tcProject + ',' + 'count:1';
}

// ################### STATES #############################
var FETCHING_BUILD_CONFIGURATIONS = false;
var BUILDSTATE = -1 // 0 = red/failure, 1 = yellow/running, 2 = green/success

// ################### johnny-five / Arduino Prep #############################
var board = new five.Board();
var greenLamp,yellowLamp,redLamp;
const GREENPIN = 13;
const YELLOWPIN = 12;
const REDPIN = 11;

var runningLoop = false;

var initLamps = function(){
  greenLamp = new five.Pin(GREENPIN);
  yellowLamp = new five.Pin(YELLOWPIN);
  redLamp = new five.Pin(REDPIN);

  var runningState = 0;

  board.loop(500, function(){
    if (runningLoop == true){
      board.digitalWrite(YELLOWPIN, (runningState = runningState ? 0 : 1));
    } else {
      board.digitalWrite(YELLOWPIN, 0);
    }
  });
}

var switchOffAllLights = function(){
  greenLamp.low();
  runningLoop = false;
  redLamp.low();
}

// ################### HTTP-Config #############################
var getHttpOptions = function(endpoint){
  if(tcUser == "guest"){
    return {
        host: teamcityHost,
        port: teamcityPort,
        path: endpoint,
        method: 'GET',
        headers: {
          accept: 'application/json'
      }
    }
  } else {
    return {
        host: teamcityHost,
        port: teamcityPort,
        path: endpoint,
        auth: tcUser + ':' + tcPW,
        method: 'GET',
        headers: {
          accept: 'application/json'
      }
    }
  }
};

// ################### Animation / Visualization #############################

var animateSuccess = function(){
  console.log("SUCCESS");
  switchOffAllLights();
  greenLamp.high();
};

var animateRunning = function(){
  console.log("RUNNING");
  switchOffAllLights();
  runningLoop = true;
};

var animateFailure = function(){
  console.log("FAILURE");
  switchOffAllLights();
  redLamp.high();
};

var visualizeCurrentState = function(newState){
  console.log("visualizeCurrentState() called");
  // change BUILDSTATE if it differs from previous
  if (newState!=BUILDSTATE){
    console.log("BUILDSTATE changed");
    BUILDSTATE=newState;
    switch(BUILDSTATE) {
      // green/success
      case 2:
          animateSuccess();
          break;
      // yellow/running
      case 1:
          animateRunning();
          break;
      // red/failure
      default:
          animateFailure();
{'fraction_non_alphanumeric': 0.2159468438538206, 'fraction_numerical': 0.008955655062834031, 'mean_word_length': 3.637642330877428, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2434553', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2089, 'n_words': 447}