<commit_before>var express = require('express');
var Scoreboard = require('../model/scoreboard');
var Q = require('q');
var _ = require('lodash');
var app = express();
var Match = require('../model/match');


app.get('/api/scoreboard', (req, res) => {
  Match.all().then((matches) => {
    var scoreboard = new Scoreboard(matches);
    res.json(scoreboard)
  }, (err) => { res.json(err) })
  .catch((err) =>
  res.json(err  ))
});

app.get('/api/player/:name', (req, res) => {
  var lowercase = (str) => str.toLowerCase()

  var isPlayer = (player) => (match) => {
    return _(match.teams).flatten()
      .map(lowercase)
      .contains(player.toLowerCase());
   }

  var won = (match, player) => {
    var playerTeam = _(match.teams)
      .flatten()
      .map(lowercase)
      .indexOf(player.toLowerCase())

    var otherTeam = playerTeam == 0 ? 1 : 0;
    return match.score[playerTeam] > match.score[otherTeam]
  }

  var player = req.param('name');

  Match.all().then((matches) => {
    return matches.filter(isPlayer(player))
  }, (err) => res.json(err))
  .then((matches) => {
    var wins = _(matches).map((match) => won(match, player))
      .filter((isTrue) => isTrue)
      .value()
      .length;
    return {
      matches: matches,
      wins: wins,
      loss: matches.length - wins
    }
  }).then((data) => {
    return res.json(data)
  })
  .catch((err) => { throw new Error(err) });

})

module.exports = app<commit_msg>(bug) Used wrong index to determine win<commit_after>var express = require('express');
var Scoreboard = require('../model/scoreboard');
var Q = require('q');
var _ = require('lodash');
var app = express();
var Match = require('../model/match');


app.get('/api/scoreboard', (req, res) => {
  Match.all().then((matches) => {
    var scoreboard = new Scoreboard(matches);
    res.json(scoreboard)
  }, (err) => { res.json(err) })
  .catch((err) =>
  res.json(err  ))
});

app.get('/api/player/:name', (req, res) => {
  var lowercase = (str) => str.toLowerCase()

  var isPlayer = (player) => (match) => {
    return _(match.teams).flatten()
      .map(lowercase)
      .contains(player.toLowerCase());
   }

  var won = (match, player) => {
    var teamsIndex = _(match.teams)
      .flatten()
      .map(lowercase)
      .indexOf(player.toLowerCase())

    var playerTeam = teamsIndex <= 1 ? 0 : 1;

    var otherTeam = playerTeam == 0? 1 : 0 ;
    return match.score[playerTeam] > match.score[otherTeam]
  }

  var player = req.param('name');

  Match.all().then((matches) => {
    return matches.filter(isPlayer(player))
  }, (err) => res.json(err))
  .then((matches) => {
    var wins = _(matches).map((match) => won(match, player))
      .filter((isTrue) => isTrue)
      .value()
      .length;
    return {
      matches: matches,
      wins: wins,
      loss: matches.length - wins
    }
  }).then((data) => {
    return res.json(data)
  })
  .catch((err) => { throw new Error(err) });

})

module.exports = app
{'fraction_non_alphanumeric': 0.19858156028368795, 'fraction_numerical': 0.00303951367781155, 'mean_word_length': 2.9811827956989245, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 37, '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': '4779049', 'n_tokens_mistral': 1013, 'n_tokens_neox': 1004, 'n_words': 209}