<commit_before>// File operations. Retrieve players from csv

package main

import (
	"encoding/csv"
	"os"
	"strconv"

	"github.com/topher200/baseutil"
)

func ParsePlayers(inputFilename string) []Player {
	// Open our input Players file
	file, err := os.Open(inputFilename)
	baseutil.Check(err)
	defer file.Close()

	// Read in our csv. Throw away the header. We expect the input to be of the
	// form (player name, value, gender ('m' or 'f'))
	playersCsv := csv.NewReader(file)
	_, err = playersCsv.Read()
	baseutil.Check(err)

	// Read in all players
	playersCsvLines, err := playersCsv.ReadAll()
	players := make([]Player, len(playersCsvLines))
	baseutil.Check(err)
	for i, player := range playersCsvLines {
		value, err := strconv.ParseFloat(player[1], 32)
		baseutil.Check(err)
		gender, err := StringToGender(player[2])
		baseutil.Check(err)
		players[i] = Player{player[0], float32(value), gender, 0}
	}
	return players
}<commit_msg>put players on random teams on import<commit_after>// File operations. Retrieve players from csv

package main

import (
	"encoding/csv"
	"math/rand"
	"os"
	"strconv"

	"github.com/topher200/baseutil"
)

func ParsePlayers(inputFilename string) []Player {
	// Open our input Players file
	file, err := os.Open(inputFilename)
	baseutil.Check(err)
	defer file.Close()

	// Read in our csv. Throw away the header. We expect the input to be of the
	// form (player name, value, gender ('m' or 'f'))
	playersCsv := csv.NewReader(file)
	_, err = playersCsv.Read()
	baseutil.Check(err)

	// Read in all players
	playersCsvLines, err := playersCsv.ReadAll()
	players := make([]Player, len(playersCsvLines))
	baseutil.Check(err)
	for i, player := range playersCsvLines {
		value, err := strconv.ParseFloat(player[1], 32)
		baseutil.Check(err)
		gender, err := StringToGender(player[2])
		baseutil.Check(err)
		team := uint8(rand.Intn(numTeams))
		players[i] = Player{player[0], float32(value), gender, team}
	}
	return players
}
{'fraction_non_alphanumeric': 0.13578356304236855, 'fraction_numerical': 0.011230219499744768, 'mean_word_length': 4.414364640883978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2519076', 'n_tokens_mistral': 722, 'n_tokens_neox': 682, 'n_words': 189}