Exemple #1
0
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)
	}
}
Exemple #2
0
// Hell function that turns bullshit into magic
func createMatch(player ols.Player, game goriot.Game) {
	match, err := goriot.MatchByMatchID("na", true, game.GameID)
	participants := map[int]*ols.Participant{} // championid -> participant
	participants[game.ChampionID] = &ols.Participant{Id: player.Id}
	if err != nil {
		log.Println("Match with id: ", game.GameID, " had an error:", err.Error())
		return
	}

	// Connect participants of an anonymous game to one of a recent game...
	for _, fellowPlayer := range game.FellowPlayers {
		participants[fellowPlayer.ChampionID] = &ols.Participant{Id: fellowPlayer.SummonerID}
	}

	// All info is connected now!
	for _, matchPlayer := range match.Participants {
		participant := participants[matchPlayer.ChampionID]
		participant.ParticipantId = matchPlayer.ParticipantID
	}

	var matchParticipants []ols.Participant
	for _, participant := range participants {
		matchParticipants = append(matchParticipants, *participant)
	}
	///////////////////////
	blueTeam := getTeamName(game, BLUE_TEAM)
	redTeam := getTeamName(game, RED_TEAM)
	winnerTeam := blueTeam

	if game.Statistics.Win && game.TeamID == RED_TEAM {
		winnerTeam = redTeam
	}
	week := ols.GetMatchesDAO().LoadWeekForMatch(blueTeam, redTeam)
	olsMatch := ols.Match{
		Participants: matchParticipants,
		BlueTeam:     blueTeam,
		RedTeam:      redTeam,
		Played:       true,
		Week:         week,
		Winner:       winnerTeam,
		Id:           game.GameID,
	}
	log.Println("Match found! ", olsMatch)
	ols.GetMatchesDAO().Save(olsMatch)
}
Exemple #3
0
func UpdateMatches() {
	matches := ols.GetMatchesDAO().All()
	for _, match := range matches {
		matchInfo, err := goriot.MatchByMatchID("na", false, match.Id)
		for _, participant := range match.Participants {
			participant.ChampionId = getParticipantChampionId(matchInfo, participant.ChampionId)
		}
		ols.GetMatchesDAO().Save(*match)
		if err != nil {
			log.Println("Error: ", err)
		} else {
			log.Println("saved: ", match.BlueTeam, " vs ", match.RedTeam)
			if !ols.GetMatchesDAO().IsLeagueGameSaved(matchInfo) {
				ols.GetMatchesDAO().SaveLeagueGame(matchInfo)
			}

		}

	}
}
Exemple #4
0
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
}
Exemple #5
0
// Returns false if it is saved.
func AlreadyChecked(player ols.Player, match goriot.Game) bool {
	return !ols.GetMatchesDAO().IsSaved(match.GameID)

}