コード例 #1
0
ファイル: main.go プロジェクト: lab-D8/lol-at-pitt
func nameUpdates() {
	players := ols.GetPlayersDAO().All()

	for _, player := range players {
		summoner, err := goriot.SummonerByID("na", player.Id)
		if err != nil {
			fmt.Println("Error with: ", player.Ign, " : ", err, player)
			continue
		}

		player.Ign = summoner[player.Id].Name
		ols.GetPlayersDAO().Save(*player)
	}
}
コード例 #2
0
ファイル: game.go プロジェクト: lab-D8/lol-at-pitt
func CheckGames() {
	players := ols.GetPlayersDAO().All()
	matchRules := []MatchRule{CorrectPlayerTeam, CorrectOtherTeam, AlreadyChecked, CorrectGameType, CorrectGameMode}
	usedSet := map[int64]bool{}
	for _, player := range players {
		summonerId := player.Id
		games, err := goriot.RecentGameBySummoner("na", summonerId)
		if err != nil {
			log.Printf("Error: ", err.Error())
		}

		for _, game := range games {
			_, used := usedSet[game.GameID]
			if used {
				continue
			}

			allowedGame := ApplyRules(*player, game, matchRules)
			if allowedGame {
				usedSet[game.GameID] = true
				createMatch(*player, game)
			}

		}
	}

}
コード例 #3
0
ファイル: main.go プロジェクト: lab-D8/lol-at-pitt
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
}
コード例 #4
0
ファイル: main.go プロジェクト: lab-D8/lol-at-pitt
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)
		}

	}
}
コード例 #5
0
ファイル: team.go プロジェクト: lab-D8/lol-at-pitt
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()
	}
}
コード例 #6
0
ファイル: draft.go プロジェクト: lab-D8/lol-at-pitt
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
}
コード例 #7
0
ファイル: draft.go プロジェクト: lab-D8/lol-at-pitt
// 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
}
コード例 #8
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)

		}
	}
}
コード例 #9
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)
	}
}
コード例 #10
0
ファイル: router_funny.go プロジェクト: lab-D8/lol-at-pitt
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
}
コード例 #11
0
ファイル: router.go プロジェクト: lab-D8/lol-at-pitt
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)
	}

}