示例#1
0
func NewPlayer(name, ign string) *ols.Player {
	player := ols.Player{Name: name}

	leaguePlayerMap, err := goriot.SummonerByName("na", goriot.NormalizeSummonerName(ign)[0])
	if err != nil {
		fmt.Println(err)
		return nil
	}
	leaguePlayer := leaguePlayerMap[goriot.NormalizeSummonerName(ign)[0]]
	player.Ign = leaguePlayer.Name
	player.Id = leaguePlayer.ID
	player.NormalizedIgn = goriot.NormalizeSummonerName(leaguePlayer.Name)[0]
	id := player.Id
	leagues_by_id, err := goriot.LeagueBySummoner("na", id)
	if err != nil {
		fmt.Println("wat: ", err.Error())
		player.Tier = "None"
	}
	league, ok := leagues_by_id[id]
	if ok {
		player.Tier = getBestLeague(league, player)
	}
	fmt.Println("New Player added: ", player)
	ols.GetPlayersDAO().Save(player)
	return &player
}
示例#2
0
func nameErrors() {
	players := ols.GetPlayersDAO().All()
	for _, player := range players {
		_, err := goriot.SummonerByName("na", goriot.NormalizeSummonerName(player.NormalizedIgn)...)
		if err != nil {
			fmt.Println("Error with: ", player.Ign, " : ", err)
		}

	}
}
示例#3
0
文件: db.go 项目: lab-D8/lol-at-pitt
func UploadCaptains(filename string) {
	r, _ := os.Open(filename)
	csvReader := csv.NewReader(r)
	allData, _ := csvReader.ReadAll()
	rand.Seed(51)
	for _, record := range allData[1:] {
		normalizedSummonerName := goriot.NormalizeSummonerName(record[1])[0]
		captain := &ols.Player{Name: record[0], Ign: record[1], NormalizedIgn: normalizedSummonerName, Id: rand.Int63()}
		if captain != nil {
			team := ols.Team{Name: captain.Ign + "'s team", Captain: captain.Id}
			team.Points, _ = strconv.Atoi(record[3])
			ols.GetPlayersDAO().Save(*captain)
			ols.GetTeamsDAO().Save(team)

		}
	}
}
示例#4
0
文件: db.go 项目: lab-D8/lol-at-pitt
func UploadPlayers(filename string) {
	r, _ := os.Open(filename)
	csvReader := csv.NewReader(r)
	allData, _ := csvReader.ReadAll()

	for _, record := range allData {
		normalizedSummonerName := goriot.NormalizeSummonerName(record[1])[0]
		amt, err := strconv.Atoi(record[2])

		if err != nil {
			log.Println("Skipping ", record[0])
			continue
		}

		proficiencies := []ols.Proficiency{}
		for _, i := range []int{3, 4, 5} {
			if record[i] == "None" {
				break
			} else {
				score, _ := strconv.Atoi(record[i+3])
				proficiencies = append(proficiencies, ols.Proficiency{
					Position: record[i],
					Score:    score,
				})
			}
		}

		totalProficiency, _ := strconv.ParseFloat(record[9], 64)

		player := &ols.Player{
			Name:             record[0],
			Ign:              record[1],
			NormalizedIgn:    normalizedSummonerName,
			Score:            amt,
			Proficiencies:    proficiencies,
			Id:               rand.Int63(),
			ProficiencyTotal: totalProficiency,
		}

		ols.GetPlayersDAO().Save(*player)
	}
}
示例#5
0
func main() {
	file, err := os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)

	if err != nil {
		panic(err)
	}
	log.SetOutput(file)
	log.Println("Success?")
	m := martini.Classic()
	goriot.SetAPIKey(LeagueApiKey)
	goriot.SetLongRateLimit(LongLeagueLimit, 10*time.Minute)
	goriot.SetSmallRateLimit(ShortLeagueLimit, 10*time.Second)
	// Setup middleware to be attached to the controllers on every call.
	if Debug {
		InitDebugMiddleware(m)
	} else {
		InitMiddleware(m)
	}

	teamHandler := func(renderer render.Render) {
		teams := ols.GetTeamsDAO().All()
		renderer.JSON(200, teams)
	}

	individualTeamHandler := func(params martini.Params, renderer render.Render) {
		team := ols.GetTeamsDAO().Load(params["name"])
		renderer.JSON(200, team)
	}
	m.Get("/admin", func(renderer render.Render) {
		renderer.HTML(200, "admin", 1)
	})

	m.Get("/error", func(urls url.Values, renderer render.Render) {
		renderer.HTML(200, "error", urls.Get("status"))
	})
	m.Get("/players/:name", func(params martini.Params, renderer render.Render) {
		normalizedName := params["name"]
		fmt.Println(normalizedName)
		player := ols.GetPlayersDAO().LoadNormalizedIGN(normalizedName)
		fmt.Println(player)
		displayTeam := ols.GetTeamsDAO().LoadPlayerDisplay(player.Id)
		fmt.Println(displayTeam)
		renderer.HTML(200, "team", displayTeam)
	})

	m.Get("/results", func(renderer render.Render) {
		players := ols.GetPlayersDAO().All()
		allPlayerDisplay := []ols.PlayerDraftResult{}
		for _, player := range players {
			team := ols.GetTeamsDAO().LoadPlayer(player.Id)
			playerDisplay := ols.PlayerDraftResult{Ign: player.Ign, Team: team.Name, NormalizedIgn: player.NormalizedIgn}
			allPlayerDisplay = append(allPlayerDisplay, playerDisplay)
		}

		renderer.HTML(200, "drafted", allPlayerDisplay)
	})
	m.Get("/teams", teamHandler)
	m.Get("/team/:name", individualTeamHandler)
	m.Get("/", func(renderer render.Render) {
		renderer.HTML(200, "main", 1)
	})
	m.Get("/register", LoginRequired, func(urls url.Values, renderer render.Render) {
		renderer.HTML(200, "register", Register{Next: urls.Get("next")})
	})

	m.Get("/oauth2error", func(token oauth2.Tokens, renderer render.Render) {
		renderer.JSON(200, token)
	})
	m.Get("/rankings", func(renderer render.Render) {
		players := ols.GetPlayersDAO().All()
		sort.Sort(players)
		renderer.HTML(200, "rank", players)
	})
	//m.Get("/draft-socket/:drafter", sockets.JSON(Message{}), func(params martini.Params, receiver <-chan *Message, sender chan<- *Message, done <-chan bool, disconnect chan<- int, errorChannel <-chan error) {

	//})

	m.Get("/register/complete", LoginRequired, func(urls url.Values, renderer render.Render, token oauth2.Tokens, w http.ResponseWriter, r *http.Request) {
		summonerName := urls.Get("summoner")
		teamName := urls.Get("team")

		if token.Expired() {
			http.Redirect(w, r, "/error?status=InvalidFacebook", 302)
			return
		}

		id, err := GetId(token.Access())
		if err != nil {
			renderer.Status(404)
			return
		}

		normalizedSummonerName := goriot.NormalizeSummonerName(summonerName)[0]
		player := ols.GetPlayersDAO().LoadNormalizedIGN(normalizedSummonerName)
		if player.Id == 0 {
			http.Redirect(w, r, "/error?status=No Player Found", 302)
			return
		}

		user := ols.GetUserDAO().GetUserFB(id)

		// User is registered registered
		if user.LeagueId != 0 {
			http.Redirect(w, r, "/error?status=Already Registered User", 302)
			return
		}

		user = site.User{LeagueId: player.Id, FacebookId: id}
		log.Println("User registered:", user)

		team := ols.GetTeamsDAO().LoadPlayerByCaptain(player.Id)
		newTeam := team
		if team.Name != "" && teamName != "" {
			newTeam.Name = teamName
			ols.GetTeamsDAO().Update(team, newTeam)
		}
		ols.GetUserDAO().Save(user)
		//next := urls.Get("next")
		log.Println("[REGISTER]: ", teamName)
		renderer.HTML(200, "register_complete", 1)
	})

	initFunnyRouter(m)
	SocketRouter(m)
	err = http.ListenAndServe(":6060", m) // Nginx needs to redirect here, so we don't need sudo priv to test.
	if err != nil {
		log.Println(err)
	}

}
示例#6
0
func (p *PlayersDAO) LoadNormalizedIGN(ign string) Player {
	var player Player
	norm := goriot.NormalizeSummonerName(ign)[0]
	p.Collection.Find(map[string]string{"normalizedign": norm}).One(&player)
	return player
}