<commit_before>'use strict';

var mongoose = require('mongoose'),
  GitDev = mongoose.model('GitDev'),
  async = require('async'),
  GitApiConfig = require('../config/git_api');


exports.ajax_test = function(req, res) {
  
  var json_response = {'status': 'success', 'msg': 'A json object just for you!'};
  
  res.json(json_response);
  
};



exports.git_developer_lookup = function(req, res) {

  var developer = req.body.username,
    gitdev = new GitDev({}),
    git_wrapper = GitApiConfig.git_api_wrapper;
  
  var now = new Date(),
    dateMinus1Day =  now.setDate(now.getDate()-1),
    query = GitDev.where({'user.login_lower' : developer.toLowerCase()}).where('updated_at').gte(dateMinus1Day);

  
  async.series([
    function(callback) {
      query.findOne( function(err, gitDeveloper) {
        if (err) {
          console.log(err);
          res.json({'Status' : 'Error'});
        } else if (gitDeveloper) {
          res.json(gitDeveloper);
          return;
        } else {
          callback(null, null);
        }
      });
    },
    function(callback) {
      async.parallel({
        user: function(callback) {
          git_wrapper.authenticate_app();
          git_wrapper.github.user.getFrom({user:developer}, function(err, api_res) { callback(err, api_res); });
        },
        repos: function(callback) {
          git_wrapper.authenticate_app();
          git_wrapper.github.repos.getFromUser({user:developer}, function(err, api_res) { callback(err, api_res); });
        }
      },
      function(err, results) {
        if (results.user) {
            gitdev.user = results.user;
            gitdev.user.login_lower = results.user.login.toLowerCase();
            gitdev.repos = results.repos;
        
            var gitdev_obj = gitdev.toObject();
            delete gitdev_obj._id;
            
            GitDev.findOneAndUpdate({'user.id': gitdev.user.id}, gitdev_obj, {upsert:true}, function(err, row) {
              if (err) {
                console.log(err);<commit_msg>getting started on adding additional repo metrics for user<commit_after>'use strict';

var mongoose = require('mongoose'),
  GitDev = mongoose.model('GitDev'),
  async = require('async'),
  GitApiConfig = require('../config/git_api');


exports.ajax_test = function(req, res) {
  
  var json_response = {'status': 'success', 'msg': 'A json object just for you!'};
  
  res.json(json_response);
  
};



exports.git_developer_lookup = function(req, res) {

  var developer = req.body.username,
    gitdev = new GitDev({}),
    git_wrapper = GitApiConfig.git_api_wrapper;
  
  var now = new Date(),
    dateMinus1Day =  now.setDate(now.getDate()-1),
    query = GitDev.where({'user.login_lower' : developer.toLowerCase()}).where('updated_at').gte(dateMinus1Day);

  
  async.series([
    function(callback) {
      query.findOne( function(err, gitDeveloper) {
        if (err) {
          console.log(err);
          res.json({'Status' : 'Error'});
        } else if (gitDeveloper) {
          res.json(gitDeveloper);
          return;
        } else {
          callback(null, null);
        }
      });
    },
    function(callback) {
      async.parallel({
        user: function(callback) {
          git_wrapper.authenticate_app();
          git_wrapper.github.user.getFrom({user:developer}, function(err, api_res) { callback(err, api_res); });
        },
        repos: function(callback) {
          var user_repos = []
          async.series([
            function(callback) {
              git_wrapper.authenticate_app();
              git_wrapper.github.repos.getFromUser({user:developer}, 
                function(err, api_res) { 
                  user_repos = api_res;
                  callback(err, api_res); 
              });
            },
            function(callback)
      },
      function(err, results) {
        if (results.user) {
            gitdev.user = results.user;
            gitdev.user.login_lower = results.user.login.toLowerCase();
            gitdev.repos = results.repos;
        
            var gitdev_obj = gitdev.toObject();
            delete gitdev_obj._id;
            
            GitDev.findOneAndUpdate({'user.id': gitdev.user.id}, gitdev_obj, {upsert:true}, function(err, row) {
              if (err) {
                console.log(err);
{'fraction_non_alphanumeric': 0.13894052044609664, 'fraction_numerical': 0.0013940520446096654, 'mean_word_length': 2.271276595744681, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '17200', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1301, 'n_words': 226}