<commit_before>import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import {
  ListView,
  View,
  Text
} from 'react-native'

const RankingView = React.createClass({
  getInitialState() {
    return {
      ranking: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2 })
        .cloneWithRows(this.props.ranking)
    }
  },
  componentWillReceiveProps(props) {
    if (props.ranking !== this.props.ranking) {
      this.state = {
        ranking: this.state.ranking.cloneWithRows(props.ranking)
      }
    }
  },
  renderRow(item) {
    return (
      <View style={{flex: 1, flexDirection: 'row'}}>
        <Text>{item.name}</Text>
        <Text>{item.score}</Text>
      </View>
    )
  },
  render() {
    return (
      <ListView dataSource={this.state.ranking}
                renderRow={this.renderRow}/>
    )
  }
})

function mapStateToProps(state) {
  function addToScoreMap(player, scoreMap) {
    if (!scoreMap[player.name]) {
      scoreMap[player.name] = 0
    }
    scoreMap[player.name] += player.score
  }
  let scoreMap = {}
  for (playedGame of state.playedGames) {
    addToScoreMap(playedGame.team1.attacker, scoreMap)
    addToScoreMap(playedGame.team1.defender, scoreMap)
    addToScoreMap(playedGame.team2.attacker, scoreMap)
    addToScoreMap(playedGame.team2.defender, scoreMap)
  }
  let scoreList = []
  for (let name in scoreMap) {
    if (scoreMap.hasOwnProperty(name)) {
      scoreList.push({
        name: name,
        score: scoreMap[name]
      })
    }
  }
  return {
    ranking: scoreList
  }
}

export default connect(mapStateToProps)(RankingView)<commit_msg>Compute player scores by win ratio<commit_after>import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import {
  ListView,
  View,
  Text
} from 'react-native'

const RankingView = React.createClass({
  getInitialState() {
    return {
      ranking: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2 })
        .cloneWithRows(this.props.ranking)
    }
  },
  componentWillReceiveProps(props) {
    if (props.ranking !== this.props.ranking) {
      this.state = {
        ranking: this.state.ranking.cloneWithRows(props.ranking)
      }
    }
  },
  renderRow(item) {
    return (
      <View style={{flex: 1, flexDirection: 'row'}}>
        <Text>{item.name}</Text>
        <Text>{item.score}</Text>
      </View>
    )
  },
  render() {
    return (
      <ListView dataSource={this.state.ranking}
                renderRow={this.renderRow}/>
    )
  }
})

function mapStateToProps(state) {
  function addToScoreMap(player, won, scoreMap) {
    if (!scoreMap[player.name]) {
      scoreMap[player.name] = {
        played: 0,
        won: 0
      }
    }
    scoreMap[player.name].played += 1
    scoreMap[player.name].won += won
  }
  let scoreMap = {}
  for (playedGame of state.playedGames) {
    let team1Win = playedGame.team1.attacker.score + playedGame.team1.defender.score >
                  playedGame.team2.attacker.score + playedGame.team2.defender.score
    addToScoreMap(playedGame.team1.attacker, team1Win, scoreMap)
    addToScoreMap(playedGame.team1.defender, team1Win, scoreMap)
    addToScoreMap(playedGame.team2.attacker, !team1Win, scoreMap)
    addToScoreMap(playedGame.team2.defender, !team1Win, scoreMap)
  }
  let scoreList = []
  for (let name in scoreMap) {
    if (scoreMap.hasOwnProperty(name)) {
      scoreList.push({
        name: name,
        score: scoreMap[name].won / scoreMap[name].played
      })
    }
  }
  return {
    ranking: scoreList
  }
}

export default connect(mapStateToProps)(RankingView)
{'fraction_non_alphanumeric': 0.1324339207048458, 'fraction_numerical': 0.008535242290748899, 'mean_word_length': 2.873134328358209, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, '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': '1438644', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1204, 'n_words': 213}