예제 #1
0
func Test_GetYear_PrintBatter(t *testing.T) {
	lahman.Load(2014)
	players := lahman.GetYear(2014)

	//for _, p := range players {
	//	fmt.Println(p.Year(), p.Name(), p.Bat, p.Pit)
	//}

	t.Log("Players in 2014", len(players))

	p := players[42] // Oswaldo Arcia
	t.Log(p.Name(), "should be Oswaldo Arcia")
	switch {
	case p.Bat.PA() != 410:
		fallthrough
	case p.Bat.G() != 103:
		fallthrough
	case p.Bat.AB() != 372:
		fallthrough
	case p.Bat.R() != 46:
		fallthrough
	case p.Bat.H() != 86:
		fallthrough
	case p.Bat.H2() != 16:
		fallthrough
	case p.Bat.H3() != 3:
		fallthrough
	case p.Bat.HR() != 20:
		fallthrough
	case p.Bat.RBI() != 57:
		fallthrough
	case p.Bat.SB() != 1:
		fallthrough
	case p.Bat.CS() != 2:
		fallthrough
	case p.Bat.BB() != 31:
		fallthrough
	case p.Bat.SO() != 127:
		fallthrough
	case p.Bat.IBB() != 4:
		fallthrough
	case p.Bat.HBP() != 6:
		fallthrough
	case p.Bat.SH() != 0:
		fallthrough
	case p.Bat.SF() != 1:
		fallthrough
	case p.Bat.GIDP() != 6:
		t.Fatal("Error printing one of Oswaldo's stats")
	default:
		t.Log("Oswaldo printed fine.")
	}
}
예제 #2
0
파일: main.go 프로젝트: frenata/marcel
func loadyears() (ps playerS) {
	for _, y := range config.years {
		var playerYears playerS
		if config.post {
			playerYears = lahman.GetPostYear(y)
		} else {
			playerYears = lahman.GetYear(y)
		}
		for _, p := range playerYears {
			ps = append(ps, p)
		}
	}
	return ps
}
예제 #3
0
파일: main.go 프로젝트: frenata/marcel
func check(min, max int) (pp []*lahman.Player, count int, apps int) {
	//pp := []*lahman.Player{}

	for i := min; i <= max; i++ {
		players := lahman.GetYear(i)
		for _, p := range players {
			//if p.Pitching != nil && p.Pitching.BFP < p.Batting.AB {
			if p.IsPosPitcher() {
				pp = append(pp, p)
				count++
				apps += int(p.Pit.G())
			}
		}
	}
	return pp, count, apps
}
예제 #4
0
파일: marcel.go 프로젝트: frenata/marcel
func leagueAvg(year int) (bat lahman.BatStats, pit lahman.PitchStats) {
	//lahman.Load(year)
	var bCount, pCount, ipCount, bfCount float64
	players := lahman.GetYear(year)

	for _, p := range players {
		if p.IsBatter() {
			for i := 0; i < len(bat); i++ {
				bat[i] += p.Bat[i]
			}
			bCount++
		}
		if p.IsPitcher() && !p.IsPosPitcher() {
			for i := 0; i < len(pit); i++ {
				switch i {
				case 13:
					pit[i] = pit[i] + p.Pit[i]*p.Pit.BFP()
					bfCount += p.Pit.BFP()
				case 14:
					pit[i] = pit[i] + p.Pit[i]*p.Pit.IPouts()
					ipCount += p.Pit.IPouts()
				default:
					pit[i] += p.Pit[i]
				}
			}
			pCount++
		}
	}

	for i := 1; i < len(bat); i++ {
		bat[i] = bat[i] / bat.PA()
	}
	bat[0] = bat[0] / bCount

	for i := 0; i < len(pit); i++ {
		switch i {
		case 13:
			pit[i] = pit[i] / bfCount
		case 14:
			pit[i] = pit[i] / ipCount
		default:
			pit[i] = pit[i] / pCount
		}
	}
	return bat, pit
}
예제 #5
0
func Test_GetYear(t *testing.T) {
	players := lahman.GetYear(2003)

	none := true
	for _, p := range players {
		if p.IsPosPitcher() { // in 2003, only wiki
			none = false
			if wiki2003 != p.String() {
				t.Log(p)
				t.Log(wiki2003)
				t.Fatal("Wiki Gonzalez should be the 439th entry in the database!")
			}
		}
	}
	if none {
		t.Fatal("Wiki isn't there! :(")
	}
}
예제 #6
0
func Test_GetYear_PrintPitcher(t *testing.T) {
	lahman.Load(2014)
	players := lahman.GetYear(2014)

	t.Log("Players in 2014", len(players))
	p := players[0] // Fernando Abad
	t.Log(p.Name(), "should be Abad")

	switch {
	case p.Pit.W() != 2:
		fallthrough
	case p.Pit.L() != 4:
		fallthrough
	case p.Pit.G() != 69:
		fallthrough
	case p.Pit.GS() != 0:
		fallthrough
	case p.Pit.CG() != 0:
		fallthrough
	case p.Pit.SHO() != 0:
		fallthrough
	case p.Pit.SV() != 0:
		fallthrough
	case p.Pit.IPouts() != 172:
		fallthrough
	case p.Pit.H() != 34:
		fallthrough
	case p.Pit.ER() != 10:
		fallthrough
	case p.Pit.HR() != 4:
		fallthrough
	case p.Pit.BB() != 15:
		fallthrough
	case p.Pit.SO() != 51:
		fallthrough
	case p.Pit.BAopp() != .175:
		fallthrough
	case p.Pit.ERA() != 1.57:
		fallthrough
	case p.Pit.IBB() != 3:
		fallthrough
	case p.Pit.WP() != 0:
		fallthrough
	case p.Pit.HBP() != 4:
		fallthrough
	case p.Pit.BK() != 0:
		fallthrough
	case p.Pit.BFP() != 216:
		fallthrough
	case p.Pit.GF() != 17:
		fallthrough
	case p.Pit.R() != 11:
		fallthrough
	case p.Pit.SH() != 1:
		fallthrough
	case p.Pit.SF() != 2:
		fallthrough
	case p.Pit.GIDP() != 6:
		t.Fatal("Error printing one of Abad's stats")
	default:
		t.Log("Abad printed fine.")
	}
}