<commit_before>import React from 'react';
import request from 'request';
import Jumbotron from 'react-bootstrap/lib/Jumbotron';
import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import InitialBoard from './components/InitialBoard';
import NameGameBoard from './components/NameGameBoard';

/*
 * @class Game representing the game board.
 */
class Game extends React.Component {

  /**
   * @constructor
   */
  constructor(options) {
    super(options);
    this.state = {
      employees: [],
      round: 0
    };
  }

  /**
   * @description Load all the data and update state
   * TODO: handle graceful failure of REST API
   * TODO: use local storage to cache the API response
   */
  componentDidMount () {
    request(this.props.url, function (error, response, body) {
      if (!error && response.statusCode === 200) {
        var employees = JSON.parse(body);
        this.setState({
          employees: employees,
          init: true
        });
      }
    }.bind(this));
  }

  /**
   * @description Top level render of name game application
   */
  render () {
    if (!this.state.init) {
      return null;
    }
    return <div>
            <Jumbotron>
              <h1>WillowTree Name Game</h1>
              <p>How many names can you remember?</p>
            </Jumbotron>
            <ProgressBar active={this.inProgress()} bsStyle="success" now={this.getProgress()} />
            {this.getCurrentBoard()}
           </div>;
  }

  getCurrentBoard () {
    if (this.state.round === 0) {
      return this.getInitialBoard();
    } else if (this.state.round === this.props.roundCount) {
      return this.getEndBoard();
    } else {
      return this.getInPlayBoard();
    }
  }

  startGame () {
    this.setState({
      round: 1
    });
  }

  /**
   * @description the initial board which explains how to play the game
   */
  getInitialBoard() {
    return <InitialBoard employee={this.getExampleEmployee()}
                         startCallback={this.startGame.bind(this)} />
  }

  getExampleEmployee() {
    var employeeCount = this.state.employees.length;
    var exampleIndex = Math.floor(Math.random() * employeeCount);
    return this.state.employees[exampleIndex];
  }

  /**
   * TODO this needs improving vastly
   */
  getEmployeesForRound() {
    var employeeCount = this.state.employees.length;
    var uniqueEmployeeIndices = [];
    while (uniqueEmployeeIndices.length < 3) {
      var candidate = Math.floor(Math.random() * employeeCount);
      if (uniqueEmployeeIndices.indexOf(candidate) == -1) {
        uniqueEmployeeIndices.push(candidate);
      }
    }
    var chosenEmployees = [];
    for (var employeeIndex of uniqueEmployeeIndices) {
      chosenEmployees.push(this.state.employees[employeeIndex]);
    }
    return chosenEmployees;
  }

  getInPlayBoard() {
    return <NameGameBoard employees={this.getEmployeesForRound()} round={this.state.round} />;
  }

  getEndBoard() {
    return <p>Finished!</p>;
  }

  /**
   * @description Get users progress through the current game (0 - 100)
   */
  getProgress() {
    return (this.state.round / this.props.roundCount) * 100;<commit_msg>Cleaned up function<commit_after>import React from 'react';
import request from 'request';
import Jumbotron from 'react-bootstrap/lib/Jumbotron';
import ProgressBar from 'react-bootstrap/lib/ProgressBar';
import InitialBoard from './components/InitialBoard';
import NameGameBoard from './components/NameGameBoard';

/*
 * @class Game representing the game board.
 */
class Game extends React.Component {

  /**
   * @constructor
   */
  constructor(options) {
    super(options);
    this.state = {
      employees: [],
      round: 0
    };
  }

  /**
   * @description Load all the data and update state
   * TODO: handle graceful failure of REST API
   */
  componentDidMount () {
    request(this.props.url, function (error, response, body) {
      if (!error && response.statusCode === 200) {
        var employees = JSON.parse(body);
        this.setState({
          employees: employees,
          init: true
        });
      }
    }.bind(this));
  }

  /**
   * @description Top level render of name game application
   */
  render () {
    if (!this.state.init) {
      return null;
    }
    return <div>
            <Jumbotron>
              <h1>WillowTree Name Game</h1>
              <p>How many names can you remember?</p>
            </Jumbotron>
            <ProgressBar active={this.inProgress()} bsStyle="success" now={this.getProgress()} />
            {this.getCurrentBoard()}
           </div>;
  }

  getCurrentBoard () {
    if (this.state.round === 0) {
      return this.getInitialBoard();
    } else if (this.state.round === this.props.roundCount) {
      return this.getEndBoard();
    } else {
      return this.getInPlayBoard();
    }
  }

  startGame () {
    this.setState({
      round: 1
    });
  }

  /**
   * @description the initial board which explains how to play the game
   */
  getInitialBoard() {
    return <InitialBoard employee={this.getExampleEmployee()}
                         startCallback={this.startGame.bind(this)} />
  }

  getExampleEmployee() {
    var employeeCount = this.state.employees.length;
    var exampleIndex = Math.floor(Math.random() * employeeCount);
    return this.state.employees[exampleIndex];
  }

  getEmployeesForRound() {
    var employeeCount = this.state.employees.length;
    var uniqueEmployeeIndices = [];
    var uniqueEmployees = [];
    while (uniqueEmployeeIndices.length < 3) {
      var candidate = Math.floor(Math.random() * employeeCount);
      if (uniqueEmployeeIndices.indexOf(candidate) == -1) {
        uniqueEmployeeIndices.push(candidate);
        uniqueEmployees.push(this.state.employees[candidate]);
      }
    }
    return uniqueEmployees;
  }

  getInPlayBoard() {
    return <NameGameBoard employees={this.getEmployeesForRound()} round={this.state.round} />;
  }

  getEndBoard() {
    return <p>Finished!</p>;
  }

  /**
   * @description Get users progress through the current game (0 - 100)
   */
  getProgress() {
    return (this.state.round / this.props.roundCount) * 100;
{'fraction_non_alphanumeric': 0.1288323548597521, 'fraction_numerical': 0.005544683626875407, 'mean_word_length': 2.622563496751329, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, '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': '607583', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1789, 'n_words': 414}