func UpdateTeamName(teamName, updatedName string) { team := ols.GetTeamsDAO().Load(teamName) updatedTeam := ols.GetTeamsDAO().Load(teamName) updatedTeam.Name = updatedName ols.GetTeamsDAO().Update(team, updatedTeam) matches := ols.GetMatchesDAO().LoadTeamMatches(team.Name) for _, match := range matches { var newMatch ols.Match = *match if newMatch.BlueTeam == team.Name { newMatch.BlueTeam = updatedName } if newMatch.RedTeam == teamName { newMatch.RedTeam = updatedName } if newMatch.Winner == teamName { newMatch.Winner = updatedName } ols.GetMatchesDAO().Update(*match, newMatch) } }
func Previous() { lock.Lock() if len(previous) > 0 { currentArr := DraftPlayers{} currentArr = append(currentArr, current) upcomingPlayers = append(currentArr, upcomingPlayers...) current = previous[len(previous)-1] previous = previous[:len(previous)-1] // Refund logic. captain := GetAuctionerByTeam(current.Team) if captain != nil { oldteam := ols.GetTeamsDAO().LoadPlayerByCaptain(captain.Id) team := oldteam team.Points += current.HighestBid team.Players = team.Players[:len(team.Players)-1] ols.GetTeamsDAO().Update(oldteam, team) captain.Points += current.HighestBid } current.HighestBid = 0 current.Team = "" } log.Println("[UNDO]: admin hit Undo") lock.Unlock() }
func UpdateTeamScore(name string, win bool) { team := ols.GetTeamsDAO().Load(name) if win { team.Wins++ } else { team.Losses++ } ols.GetTeamsDAO().Save(team) }
func RemoveTeamPlayer(teamName string, removePlayerId int64) { team := ols.GetTeamsDAO().Load(teamName) newPlayers := []int64{} for _, playerId := range team.Players { if playerId != removePlayerId { newPlayers = append(newPlayers, playerId) } } team.Players = newPlayers ols.GetTeamsDAO().Save(team) }
// Setup stuff func getPlayers() []*DraftPlayer { players := ols.GetPlayersDAO().All() sort.Sort(players) var sortedPlayers []*ols.Player = players draftPlayers := []*DraftPlayer{} for _, player := range sortedPlayers { team := ols.GetTeamsDAO().LoadPlayerByCaptain(player.Id) otherTeam := ols.GetTeamsDAO().LoadPlayer(player.Id) if team.Captain != player.Id && !otherTeam.IsPlayerOnTeam(player.Id) { draftPlayers = append(draftPlayers, &DraftPlayer{Player: *player}) } } return draftPlayers }
func getTeamName(game goriot.Game, teamCode int) string { for _, fellowPlayer := range game.FellowPlayers { if teamCode == fellowPlayer.TeamID { team := ols.GetTeamsDAO().LoadPlayer(fellowPlayer.SummonerID) if team.Name != "" { return team.Name } } } return "" }
func ShowTeams() { teams := ols.GetTeamsDAO().All() for _, team := range teams { fmt.Print("Team (", team.Name, "): ") for _, playerId := range team.Players { player := ols.GetPlayersDAO().Load(playerId) fmt.Print(player.Ign, " ") } fmt.Println() } }
func Win() { lock.Lock() captain := GetAuctionerByTeam(current.Team) if captain != nil { log.Println("[WIN]: ", captain.Ign, ",", captain.Name, ",", current.Ign, ",", current.HighestBid, ",", captain.TeamName) captain.Points -= current.HighestBid oldteam := ols.GetTeamsDAO().LoadPlayerByCaptain(captain.Id) team := oldteam team.Points -= current.HighestBid team.Players = append(team.Players, current.Id) ols.GetTeamsDAO().Update(oldteam, team) } Paused = true previous = append(previous, current) if len(upcomingPlayers) != 0 { current = upcomingPlayers[0] upcomingPlayers = upcomingPlayers[1:] } lock.Unlock() }
func CorrectPlayerTeam(player ols.Player, match goriot.Game) bool { myTeamMatch := 0 playingTeam := ols.GetTeamsDAO().LoadPlayer(player.Id) myTeam := match.TeamID for _, fellowPlayer := range match.FellowPlayers { if fellowPlayer.TeamID == myTeam && playingTeam.IsPlayerOnTeam(fellowPlayer.SummonerID) { myTeamMatch++ } } return myTeamMatch >= 3 }
func getCaptains() []*DraftCaptain { captains := ols.GetPlayersDAO().All() sort.Sort(captains) draftCaptains := []*DraftCaptain{} var captains_sorted []*ols.Player = captains for _, player := range captains_sorted { team := ols.GetTeamsDAO().LoadPlayerByCaptain(player.Id) if team.Captain == player.Id { user := ols.GetUserDAO().GetUserLeague(player.Id) draftCaptains = append(draftCaptains, &DraftCaptain{Player: *player, FacebookID: user.FacebookId, Points: team.Points, TeamName: team.Name}) } } return draftCaptains }
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) } } }
func getOtherTeam(player ols.Player, match goriot.Game) ols.Team { var otherTeam ols.Team otherTeamId := BLUE_TEAM myTeam := match.TeamID if myTeam == otherTeamId { otherTeamId = RED_TEAM } // Get other player on other team.. for _, fellowPlayer := range match.FellowPlayers { if fellowPlayer.TeamID != myTeam { otherTeam = ols.GetTeamsDAO().LoadPlayer(fellowPlayer.SummonerID) if otherTeam.Name != "" { break } } } return otherTeam }
func initStats() []PlayerStats { pStats := []PlayerStats{} for _, team := range ols.GetTeamsDAO().All() { matches := ols.GetMatchesDAO().LoadTeamMatches(team.Name) for _, playerId := range team.Players { pStat := PlayerStats{} player := ols.GetPlayersDAO().Load(playerId) pStat.Summoner = player.Ign pStat.Team = team.Name pStat.Division = team.League for _, match := range matches { leagueMatch := ols.GetMatchesDAO().LoadLeagueGame(match.Id) index := getParticipantIndex(leagueMatch, *match, player.Id) if index == -1 { continue } pleague := leagueMatch.Participants[index].Stats pStat.AssistsPerGame += float32(pleague.Assists) pStat.DeathsPerGame += float32(pleague.Deaths) pStat.GamesPlayed += 1 pStat.KillsPerGame += float32(pleague.Kills) pStat.TotalAssists += int(pleague.Assists) pStat.TotalDeaths += int(pleague.Deaths) pStat.TotalGold += int(pleague.GoldEarned) pStat.TotalKills += int(pleague.Kills) } if pStat.GamesPlayed > 0 { pStat.AssistsPerGame /= float32(pStat.GamesPlayed) pStat.DeathsPerGame /= float32(pStat.GamesPlayed) pStat.KillsPerGame /= float32(pStat.GamesPlayed) pStat.KDA = float32(pStat.TotalAssists+pStat.TotalKills) / float32(pStat.TotalDeaths) } pStats = append(pStats, pStat) } } return pStats }
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) } }
func AddTeamPlayer(teamName string, playerId int64) { team := ols.GetTeamsDAO().Load(teamName) team.Players = append(team.Players, playerId) ols.GetTeamsDAO().Save(team) }
func UpdateTeamCaptain(teamName string, playerId int64) { team := ols.GetTeamsDAO().Load(teamName) team.Captain = playerId ols.GetTeamsDAO().Save(team) }
func NewTeamScore(name string, wins int, losses int) { team := ols.GetTeamsDAO().Load(name) team.Wins = wins team.Losses = losses ols.GetTeamsDAO().Save(team) }