<commit_before>import _ from 'lodash'
import Promise from 'bluebird'
import findMatching from 'bipartite-matching'


// takes an Array of people represented as
//   [{name: String, skills: [String], interests: [String]}]
//
// and computes a pairing, represented as an Object with:
//   {
//     isComplete: true|false, // was everyone paired?
//     pairs: [ // list of pairs
//       {
//         teacherIndex: Int,
//         learnerIndex: Int,
//         skills: [String]},<commit_msg>added main function to pair all people<commit_after>import _ from 'lodash'
import Promise from 'bluebird'
import findMatching from 'bipartite-matching'
import {getAllPeople, savePairing} from '../airtable'


const {env} = process
// constants that can be overridden through environment variables
export const APPLICANTS_TABLE = env.APPLICANTS_TABLE || 'P2PL Applicants'
export const PAIRINGS_TABLE = env.PAIRINGS_TABLE || 'Pairings'



// Main pairing function:
// - reads all applicants from Airtable
// - creates a pairing
// - saves the pairing into Airtable and returns it
// Different tables can be set up through options
export const pairAllApplicants = (opts = {}) => {
  const aTable = opts.applicantsTable || APPLICANTS_TABLE
  const pTable = opts.pairingsTable || PAIRINGS_TABLE
  console.log(`Pairing people in ${aTable}, saving in ${pTable}`)
  return getAllPeople(aTable)
    .then((people) => {
      console.log(`Found ${people.length} people in ${aTable}`)
      return generatePairing(people)
    })
    .then((pairing) => {
      console.log(`Saving ${pairing.pairs.length} pairs to ${pTable}, id=${pairing.id}`)
      return savePairing(pTable, pairing)
    })
}



// takes an Array of people represented as
//   [{name: String, skills: [String], interests: [String]}]
//
// and computes a pairing, represented as an Object with:
//   {
//     isComplete: true|false, // was everyone paired?
//     pairs: [ // list of pairs
//       {
//         teacherIndex: Int,
//         learnerIndex: Int,
//         skills: [String]},
{'fraction_non_alphanumeric': 0.12831858407079647, 'fraction_numerical': 0.0004916420845624386, 'mean_word_length': 3.195876288659794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5064134', 'n_tokens_mistral': 620, 'n_tokens_neox': 600, 'n_words': 194}