<commit_before>#!/usr/bin/env node
var path = require('path'),
  http = require('http'),
  express = require('express'),
  bodyParser = require('body-parser'),
  config = require(path.join(__dirname, 'config.json')),
  compression = require('compression'),
  app = express(),
  request = require('request'),
  async = require('async'),
  _teams = [],
  fs = require('fs'),
  glob = require('glob');


app.set('port', process.env.VCAP_APP_PORT || 80);
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get("/teams", getTeamInfo);
app.get("/imgs/:year?", getImageNames);

var server = http.createServer(app);

/************************************** API End Points **************************************/

function getImageNames(req, res) {
  var year = req.param('year', null);
  var file_ext = req.param('ext', 'jpg') //default parameter is jpg
  var img_path = path.join('web', 'images');
  
  if(year) {
    img_path = path.join(img_path, year);
  }

  img_path = path.join(img_path, "**", "*." + file_ext); //for globbing

  glob(img_path, function(err, names) {
      console.log("Files: " + JSON.stringify(names));
    res.send(names);
  });
}

function getTeamInfo(req, res) {
  res.send(_teams);
}

/************************************** Team Processing Functions **************************************/

//Happened more commonly in old versions. 
function removeDuplicates(list) {
  var uniqueArr = list.filter(function(elem, pos) {
    return list.indexOf(elem) == pos;
  });
  return uniqueArr;
}

function processResponse(err, team, creator) {
  if(creator) {
    var response = getUserResponse(creator.answers);

    if(response.approved) {
      var teamObj = {
        name: team.name,
        members: team.attendee_count,
        description: response.description,
        captain: {
          name: creator.profile.name,
          email: creator.profile.email
        }
      }
      _teams.push(teamObj);
    }
  }
}

function getCreator(team, attendees, cb) {
  attendees.forEach(function(attendee) {
    if(team.creator.emails[0].email === attendee.profile.email) {
      cb(null, team, attendee);
    }
  });
  cb(null);
}

function getUserResponse(questions) {
  var response = {
    approved: false,
    description: null
  };

  questions.forEach(function(answer) {
    if(answer.question_id === "8622569") { //"question": "Would you like to have your team listed on our Team finder page?",
      if(answer.answer === "Yes, I am looking for additional members") {
        response.approved = true;
      }

    } else if(answer.question_id === "8622571") {
      if(typeof(answer.answer) !== "undefined") {
        response.description = answer.answer;
      }<commit_msg>Forget to jshint before I pushed<commit_after>#!/usr/bin/env node
var path = require('path'),
  http = require('http'),
  express = require('express'),
  bodyParser = require('body-parser'),
  config = require(path.join(__dirname, 'config.json')),
  compression = require('compression'),
  app = express(),
  request = require('request'),
  async = require('async'),
  _teams = [],
  fs = require('fs'),
  glob = require('glob');


app.set('port', process.env.VCAP_APP_PORT || 80);
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get("/teams", getTeamInfo);
app.get("/imgs/:year?", getImageNames);

var server = http.createServer(app);

/************************************** API End Points **************************************/

function getImageNames(req, res) {
  var year = req.param('year', null);
  var file_ext = req.param('ext', 'jpg'); //default parameter is jpg
  var img_path = path.join('web', 'images');
  
  if(year) {
    img_path = path.join(img_path, year);
  }

  img_path = path.join(img_path, "**", "*." + file_ext); //for globbing

  glob(img_path, function(err, names) {
      console.log("Files: " + JSON.stringify(names));
    res.send(names);
  });
}

function getTeamInfo(req, res) {
  res.send(_teams);
}

/************************************** Team Processing Functions **************************************/

//Happened more commonly in old versions. 
function removeDuplicates(list) {
  var uniqueArr = list.filter(function(elem, pos) {
    return list.indexOf(elem) == pos;
  });
  return uniqueArr;
}

function processResponse(err, team, creator) {
  if(creator) {
    var response = getUserResponse(creator.answers);

    if(response.approved) {
      var teamObj = {
        name: team.name,
        members: team.attendee_count,
        description: response.description,
        captain: {
          name: creator.profile.name,
          email: creator.profile.email
        }
      };
      _teams.push(teamObj);
    }
  }
}

function getCreator(team, attendees, cb) {
  attendees.forEach(function(attendee) {
    if(team.creator.emails[0].email === attendee.profile.email) {
      cb(null, team, attendee);
    }
  });
  cb(null);
}

function getUserResponse(questions) {
  var response = {
    approved: false,
    description: null
  };

  questions.forEach(function(answer) {
    if(answer.question_id === "8622569") { //"question": "Would you like to have your team listed on our Team finder page?",
      if(answer.answer === "Yes, I am looking for additional members") {
        response.approved = true;
      }

    } else if(answer.question_id === "8622571") {
      if(typeof(answer.answer) !== "undefined") {
        response.description = answer.answer;
      }
{'fraction_non_alphanumeric': 0.206323396567299, 'fraction_numerical': 0.006142728093947606, 'mean_word_length': 3.675675675675676, 'pattern_counts': {'":': 2, '<': 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': '6733025', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1710, 'n_words': 363}