<commit_before>var Promise = require('bluebird');
var request = require('request');
var tradesController = require('./../../../server/db/dbcontrollers/tradesController');

module.exports = function (knex) {
  
  var module = {};

  tradesController = tradesController(knex);

//Decides who was the winner of the match
//-------------------------------------------------  
  module.scoreMatches = function (providedDate) {
    console.log('kicking off match scoring job');
    //formulate the date to look for
    var today = new Date();
    var date = providedDate || new Date(today.getFullYear(), today.getMonth(), today.getDate(), 21);
    //get all matches that are active and ending on the provided date
    return module.selectCompletingMatches( date )
      .then( function (matches) {
        return module.determineWinners(matches);
      })
      .catch( function ( err ) {
        console.error(err);
      });
  };

//Find all matches where end date is today
  module.selectCompletingMatches = function (date) {
    console.log('grabbing matches to evaluate');
    return knex('matches')
      .where('status', 'active')
      .then( function(matches) {
        return matches.filter(function(match) {
          return Date.parse(match.enddate) <= Date.parse(date);
        });
      });
  };

//Determine the winner
  module.determineWinners = function (matches) {
    return Promise.map(matches, function (match) {
      if( match.creator_id === match.challengee ) {
           return recordWinner(match.m_id, match.creator_id);
      } else {
        //get creator's portfolio
        return module.getPortfolio(match.creator_id, match.m_id)
        .then (function (creatorPortfolio) {
          //get challengee's portfolio
          return module.getPortfolio(match.challengee, match.m_id)
          .then (function (challengeePortfolio) {
            //evaluate portfolio values against each other
            if( creatorPortfolio.totalValue > challengeePortfolio.totalValue ) {<commit_msg>fix additional missing 'module' issue in scoreMatches<commit_after>var Promise = require('bluebird');
var request = require('request');
var tradesController = require('./../../../server/db/dbcontrollers/tradesController');

module.exports = function (knex) {
  
  var module = {};

  tradesController = tradesController(knex);

//Decides who was the winner of the match
//-------------------------------------------------  
  module.scoreMatches = function (providedDate) {
    console.log('kicking off match scoring job');
    //formulate the date to look for
    var today = new Date();
    var date = providedDate || new Date(today.getFullYear(), today.getMonth(), today.getDate(), 21);
    //get all matches that are active and ending on the provided date
    return module.selectCompletingMatches( date )
      .then( function (matches) {
        return module.determineWinners(matches);
      })
      .catch( function ( err ) {
        console.error(err);
      });
  };

//Find all matches where end date is today
  module.selectCompletingMatches = function (date) {
    console.log('grabbing matches to evaluate');
    return knex('matches')
      .where('status', 'active')
      .then( function(matches) {
        return matches.filter(function(match) {
          return Date.parse(match.enddate) <= Date.parse(date);
        });
      });
  };

//Determine the winner
  module.determineWinners = function (matches) {
    return Promise.map(matches, function (match) {
      if( match.creator_id === match.challengee ) {
           return module.recordWinner(match.m_id, match.creator_id);
      } else {
        //get creator's portfolio
        return module.getPortfolio(match.creator_id, match.m_id)
        .then (function (creatorPortfolio) {
          //get challengee's portfolio
          return module.getPortfolio(match.challengee, match.m_id)
          .then (function (challengeePortfolio) {
            //evaluate portfolio values against each other
            if( creatorPortfolio.totalValue > challengeePortfolio.totalValue ) {
{'fraction_non_alphanumeric': 0.14053654934777257, 'fraction_numerical': 0.0009844942160964804, 'mean_word_length': 2.6878402903811254, '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': '367089', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1092, 'n_words': 294}