<commit_before>'use strict';

var _ = require('lodash');
var Repository = require('../../v1/repository/repository.model.js');
var async = require('async');
var moment = require('moment');

function getOwner(baseUrl){
  var res = baseUrl.split('/');
  return res[3];
}

var getCollectAtTime = function(owner, callback){
  // Distinct + Sort Query
  //Repository.find({owner : owner}).distinct('collectAt').exec(function(err, ))

  Repository.aggregate([
    { $match : { owner : owner}},
    { $sort : { collectAt : 1}},
    { $group : { _id : "$collectAt"}}
  ], function(err, results){
    if(err){
      console.log(err);
      return;
    }
    console.log(results);
    callback(null, owner, results);
  });
};

var distinctByDay = function(owner, dates, callback){
  var prevDate, prevYear;
  var output = new Array();
  console.log('distinct dates : ', dates);
  dates.forEach(function(date){
    if((prevDate == date._id.getDate()) && (prevYear == date._id.getYear())){
      return;
    }
    prevYear = date._id.getYear();
    prevDate = date._id.getDate();
    output.push(date._id);
  });
  callback(null, owner, output);
};

var getStarCount = function(owner, dates, callback){
  var output = new Array();
  var prevName;
  var forkSum=0 , starSum=0, watchSum=0;
  var result;

  async.each(dates,
    function(date, callbackNextEach){
      Repository.find({owner : owner, collectAt : date}).sort({"name": 1}).exec(function (err, repositories) {
        repositories.forEach(function(currRepo){
          if(prevName == currRepo.name){
            return ;
          }
          prevName = currRepo.name;
          forkSum += currRepo.forksCount;
          starSum += currRepo.stargazersCount;
          watchSum += currRepo.watchersCount;
        });
        result = {
          'collectAt' : moment(date).format('YYYY-MM-DD'),
          'forksCount' : forkSum,
          'stargazersCount' : starSum,
          'watchersCount': watchSum
        };
        output.push(result);
        forkSum = 0, starSum = 0, watchSum = 0, prevName = 0;
        callbackNextEach();
      });
    },
    function(err){
      if(err) {
        console.log(err);
        callback(null, err);
      }<commit_msg>Add hour, minutes to date format<commit_after>'use strict';

var _ = require('lodash');
var Repository = require('../../v1/repository/repository.model.js');
var async = require('async');
var moment = require('moment');

function getOwner(baseUrl){
  var res = baseUrl.split('/');
  return res[3];
}

var getCollectAtTime = function(owner, callback){
  // Distinct + Sort Query
  //Repository.find({owner : owner}).distinct('collectAt').exec(function(err, ))

  Repository.aggregate([
    { $match : { owner : owner}},
    { $sort : { collectAt : 1}},
    { $group : { _id : "$collectAt"}}
  ], function(err, results){
    if(err){
      console.log(err);
      return;
    }
    console.log(results);
    callback(null, owner, results);
  });
};

var distinctByDay = function(owner, dates, callback){
  var prevDate, prevYear;
  var output = new Array();
  console.log('distinct dates : ', dates);
  dates.forEach(function(date){
    if((prevDate == date._id.getDate()) && (prevYear == date._id.getYear())){
      return;
    }
    prevYear = date._id.getYear();
    prevDate = date._id.getDate();
    output.push(date._id);
  });
  callback(null, owner, output);
};

var getStarCount = function(owner, dates, callback){
  var output = new Array();
  var prevName;
  var forkSum=0 , starSum=0, watchSum=0;
  var result;

  async.each(dates,
    function(date, callbackNextEach){
      Repository.find({owner : owner, collectAt : date}).sort({"name": 1}).exec(function (err, repositories) {
        repositories.forEach(function(currRepo){
          if(prevName == currRepo.name){
            return ;
          }
          prevName = currRepo.name;
          forkSum += currRepo.forksCount;
          starSum += currRepo.stargazersCount;
          watchSum += currRepo.watchersCount;
        });
        console.log(moment(date).format('YYYY-MM-DD h:mm'));
        result = {
          'collectAt' : moment(date).format('YYYY-MM-DD h:mm'),
          'forksCount' : forkSum,
          'stargazersCount' : starSum,
          'watchersCount': watchSum
        };
        output.push(result);
        forkSum = 0, starSum = 0, watchSum = 0, prevName = 0;
        callbackNextEach();
      });
    },
    function(err){
      if(err) {
        console.log(err);
        callback(null, err);
      }
{'fraction_non_alphanumeric': 0.16174183514774496, 'fraction_numerical': 0.004887802710508776, 'mean_word_length': 2.780016792611251, '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': '3013120', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1422, 'n_words': 288}