public void AddSummonerToCache(RegionType region, Summoner summoner) { lock (SummonerCache) { SummonerCache[summoner.Region][summoner.AccountId] = summoner; } }
List<AggregatedChampionStatistics> LoadAggregatedChampionStatistics(Summoner summoner, MapType map, GameModeType gameMode, NpgsqlConnection database) { const string query = "with source as " + "(select player.champion_id, player.won, player.kills, player.deaths, player.assists, player.gold, player.minion_kills from game_result, player where game_result.map = cast(:map as map_type) and game_result.game_mode = cast(:game_mode as game_mode_type) and (game_result.team1_id = player.team_id or game_result.team2_id = player.team_id) and player.summoner_id = :summoner_id) " + "select statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills from " + "(select source.champion_id, sum(source.kills) as kills, sum(source.deaths) as deaths, sum(source.assists) as assists, sum(source.gold) as gold, sum(source.minion_kills) as minion_kills from source group by source.champion_id) " + "as statistics " + "left outer join " + "(select champion_id, count(*) as wins from source where won = true group by champion_id) " + "as champion_wins " + "on statistics.champion_id = champion_wins.champion_id " + "left outer join " + "(select champion_id, count(*) as losses from source where won = false group by champion_id) " + "as champion_losses " + "on statistics.champion_id = champion_losses.champion_id;"; DatabaseCommand select = GetCommand(query, database); select.SetEnum("map", map.ToEnumString()); select.SetEnum("game_mode", gameMode.ToEnumString()); select.Set("summoner_id", summoner.Id); using (NpgsqlDataReader reader = select.ExecuteReader()) { List<AggregatedChampionStatistics> output = new List<AggregatedChampionStatistics>(); while (reader.Read()) { AggregatedChampionStatistics statistics = new AggregatedChampionStatistics(reader); statistics.ChampionName = GetChampionName(statistics.ChampionId); output.Add(statistics); } output.Sort(); return output; } }
string GetRankedStatistics(Summoner summoner) { const string caption = "Ranked Statistics"; const string containerName = "rankedStatistics"; string table = Markup.Diverse("", id: containerName); string inline = "var rankedStatistics =\n[\n"; foreach (var champion in summoner.RankedStatistics) { int[] fields = { champion.Wins, champion.Losses, champion.Kills, champion.Deaths, champion.Assists, champion.MinionKills, champion.Gold, champion.TurretsDestroyed, champion.DamageDealt, champion.PhysicalDamageDealt, champion.MagicalDamageDealt, champion.DamageTaken, champion.DoubleKills, champion.TripleKills, champion.QuadraKills, champion.PentaKills, champion.TimeSpentDead, champion.MaximumKills, champion.MaximumDeaths, }; var stringFields = from x in fields select x.ToString(); inline += "new RankedStatistics("; inline += GetJavaScriptString(champion.ChampionName) + ", "; inline += string.Join(", ", stringFields); inline += "),\n"; } inline += "];\n"; inline += string.Format("initialiseContainer({0}, {1}, rankedStatistics);", GetJavaScriptString(caption), GetJavaScriptString(containerName)); string inlineScript = Markup.InlineScript(inline); string output = table + inlineScript; return output; }
void UpdateRunes(Summoner summoner, AllPublicSummonerDataDTO publicSummonerData, DbConnection connection) { //Remove old rune pages from the database first using (var delete = Command("delete from rune_page where summoner_id = :summoner_id", connection)) { delete.Set("summoner_id", summoner.Id); delete.Execute(); } foreach (var page in publicSummonerData.spellBook.bookPages) { string[] pageFields = { "summoner_id", "name", "is_current_rune_page", "time_created", }; using (var insert = Command("insert into rune_page ({0}) values ({1})", connection, GetGroupString(pageFields), GetPlaceholderString(pageFields))) { insert.SetFieldNames(pageFields); insert.Set(summoner.Id); insert.Set(page.name); insert.Set(page.current); insert.Set(page.createDate.ToUnixTime()); insert.Execute(); } int runePageId = GetInsertId(connection); string[] runeFields = { "rune_page_id", "rune_slot", "rune", }; foreach (var rune in page.slotEntries) { using (var insert = Command("insert into rune_slot ({0}) values ({1})", connection, GetGroupString(runeFields), GetPlaceholderString(runeFields))) { insert.SetFieldNames(runeFields); insert.Set(runePageId); insert.Set(rune.runeSlotId); insert.Set(rune.runeId); insert.Execute(); } } } }
string GetRatingTable(Summoner summoner) { string[] columnTitles = { "Map", "Mode", "Games", "W", "L", "W - L", "WR", "Left", "Rating", "Top rating", }; string caption = Markup.Caption("General Statistics"); string firstRow = GetTableHeadRow(columnTitles); int rowCount = 0; string otherRows = ""; foreach (var rating in summoner.Ratings) { int gamesPlayed = rating.Wins + rating.Losses; if (gamesPlayed == 0) continue; string row = ""; row += Markup.TableCell(rating.Map.GetString()); row += Markup.TableCell(rating.GameMode.GetString()); row += Markup.TableCell(gamesPlayed.ToString()); row += Markup.TableCell(rating.Wins.ToString()); row += Markup.TableCell(rating.Losses.ToString()); row += Markup.TableCell(SignumString(rating.Wins - rating.Losses)); row += Markup.TableCell(Percentage(((double)rating.Wins) / (rating.Wins + rating.Losses))); row += Markup.TableCell(rating.Leaves.ToString()); if (rating.CurrentRating == null) row += Markup.TableCell("?"); else row += Markup.TableCell(rating.CurrentRating.ToString()); if (rating.CurrentRating == null) row += Markup.TableCell("?"); else row += Markup.TableCell(string.Format("{0} ({1})", rating.TopRating, SignumString(rating.CurrentRating.Value - rating.TopRating.Value))); otherRows += Markup.TableRow(row); rowCount++; } if (rowCount > 0) { string ratingTable = Markup.Table(caption + firstRow + otherRows, id: "ratingTable"); return ratingTable; } else return ""; }
List<GameTeamPlayer> LoadSummonerGames(Summoner summoner, NpgsqlConnection database) { List<GameTeamPlayer> output = new List<GameTeamPlayer>(); SQLCommand select = GetCommand("select {0} from game_result, team_player where game_result.id = team_player.game_id and team_player.summoner_id = :summoner_id order by game_result.game_time desc", database, GameTeamPlayer.GetFields()); select.Set("summoner_id", summoner.Id); using (NpgsqlDataReader reader = select.ExecuteReader()) { while (reader.Read()) { GameTeamPlayer player = new GameTeamPlayer(reader); output.Add(player); } } return output; }
List<ExtendedPlayer> GetSummonerGames(Summoner summoner, DbConnection connection) { List<ExtendedPlayer> output = new List<ExtendedPlayer>(); using (var select = Command("select {0} from game, player where game.id = player.game_id and player.summoner_id = :summoner_id order by game.time desc", connection, ExtendedPlayer.GetFields())) { select.Set("summoner_id", summoner.Id); using (var reader = select.ExecuteReader()) { while (reader.Read()) { ExtendedPlayer player = new ExtendedPlayer(reader); output.Add(player); } } return output; } }
List<SummonerRankedStatistics> GetSummonerRankedStatistics(Summoner summoner, int season, DbConnection connection) { using (var select = Command("select {0} from summoner_ranked_statistics where summoner_id = :summoner_id and season = :season", connection, SummonerRankedStatistics.GetFields())) { select.Set("summoner_id", summoner.Id); select.Set("season", season); using (var reader = select.ExecuteReader()) { List<SummonerRankedStatistics> output = new List<SummonerRankedStatistics>(); while (reader.Read()) { SummonerRankedStatistics statistics = new SummonerRankedStatistics(reader); output.Add(statistics); } return output; } } }
List<RunePage> GetRunePages(Summoner summoner) { List<RunePage> output = new List<RunePage>(); using (var connection = GetConnection()) { using (var pageSelect = Command("select {0} from rune_page where summoner_id = :summoner_id", connection, RunePage.GetFields())) { pageSelect.Set("summoner_id", summoner.Id); using (var pageReader = pageSelect.ExecuteReader()) { while (pageReader.Read()) { RunePage page = new RunePage(pageReader); using (var slotSelect = Command("select {0} from rune_slot where rune_page_id = :rune_page_id", connection, RuneSlot.GetFields())) { slotSelect.Set("rune_page_id", page.Id); using (var slotReader = slotSelect.ExecuteReader()) { while (slotReader.Read()) { RuneSlot slot = new RuneSlot(slotReader); page.Slots.Add(slot); } } } page.Slots.Sort((x, y) => x.Slot.CompareTo(y.Slot)); output.Add(page); } } } } return output; }
string GetSummonerOverview(string regionName, Summoner summoner) { string profileIcon = Markup.Image(GetImage(string.Format("Profile/profileIcon{0}.jpg", summoner.ProfileIcon)), string.Format("{0}'s profile icon", summoner.SummonerName), id: "profileIcon"); var overviewFields1 = new Dictionary<string, string>() { {"Summoner name", Markup.Escape(summoner.SummonerName)}, {"Internal name", Markup.Escape(summoner.InternalName)}, {"Region", regionName}, {"Summoner level", summoner.SummonerLevel.ToString()}, {"Non-custom games played", summoner.GetGamesPlayed().ToString()}, {"Account ID", summoner.AccountId.ToString()}, {"Summoner ID", summoner.SummonerId.ToString()}, }; string updateNowLink = string.Format("javascript:updateSummoner({0}, {1})", GetJavaScriptString(regionName), summoner.AccountId); string manualUpdateDescription = Markup.Span(Markup.Link(updateNowLink, "Update now"), id: "manualUpdate"); string automaticUpdatesLink = string.Format("javascript:enableAutomaticUpdates({0}, {1})", GetJavaScriptString(regionName), summoner.AccountId); string automaticUpdatesDescription = Markup.Span(string.Format("No ({0})", Markup.Link(automaticUpdatesLink, "enable")), id: "automaticUpdates"); string matchHistory = Markup.Link(ViewSummonerGamesHandler.GetPath(regionName, summoner.AccountId.ToString()), "View games"); var overviewFields2 = new Dictionary<string, string>() { {"Match history", matchHistory}, {"Manual update", manualUpdateDescription}, {"Is updated automatically", summoner.UpdateAutomatically ? "Yes" : automaticUpdatesDescription}, {"First update", summoner.TimeCreated.ToStandardString()}, {"Last update", summoner.TimeUpdated.ToStandardString()}, }; string script = GetScript("Update.js"); string container = Markup.Diverse(profileIcon + GetOverviewTable(overviewFields1) + GetOverviewTable(overviewFields2), id: "summonerHeader"); string overview = script + container; return overview; }
OperationResult SetSummonerAutomaticUpdates(Summoner summoner, bool updateAutomatically) { using (var connection = GetConnection()) { using (var update = Command("update summoner set update_automatically = :update_automatically where region = :region and account_id = :account_id", connection)) { update.Set("update_automatically", updateAutomatically); update.Set("region", summoner.Region); update.Set("account_id", summoner.AccountId); int rowsAffected = update.Execute(); if (rowsAffected > 0) { summoner.UpdateAutomatically = updateAutomatically; return OperationResult.Success; } else return OperationResult.NotFound; } } }
List<AggregatedChampionStatistics> LoadAggregatedChampionStatistics(Summoner summoner, MapType map, GameModeType gameMode, DbConnection connection) { string viewName = GetViewName(); try { //Create a temporary view with a dynamically generated name to emulate the former CTE string createViewQuery = "create temporary view {0} as select game.map, game.game_mode, game.blue_team_id, game.purple_team_id, game.blue_team_won, player.team_id, player.summoner_id, player.champion_id, player.kills, player.deaths, player.assists, player.gold, player.minion_kills from game, player where game.blue_team_id = player.team_id or game.purple_team_id = player.team_id"; using (var createView = Command(createViewQuery, connection, viewName)) { createView.Execute(); string commonWhereClause = string.Format("{0}.summoner_id = :summoner_id and {0}.map = :map and {0}.game_mode = :game_mode", viewName); string selectQuery = "select statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills from " + "(select {0}.champion_id, sum({0}.kills) as kills, sum({0}.deaths) as deaths, sum({0}.assists) as assists, sum({0}.gold) as gold, sum({0}.minion_kills) as minion_kills from {0} where {1} group by {0}.champion_id) " + "as statistics " + "left outer join " + "(select champion_id, count(*) as wins from {0} where {1} and ((blue_team_won = 1 and blue_team_id = team_id) or (blue_team_won = 0 and purple_team_id = team_id)) group by champion_id) " + "as champion_wins " + "on statistics.champion_id = champion_wins.champion_id " + "left outer join " + "(select champion_id, count(*) as losses from {0} where {1} and ((blue_team_won = 0 and blue_team_id = team_id) or (blue_team_won = 1 and purple_team_id = team_id)) group by champion_id) " + "as champion_losses " + "on statistics.champion_id = champion_losses.champion_id"; using (var select = Command(selectQuery, connection, viewName, commonWhereClause)) { select.Set("map", map); select.Set("game_mode", gameMode); select.Set("summoner_id", summoner.Id); using (var reader = select.ExecuteReader()) { List<AggregatedChampionStatistics> output = new List<AggregatedChampionStatistics>(); while (reader.Read()) { AggregatedChampionStatistics statistics = new AggregatedChampionStatistics(reader); output.Add(statistics); } using (var dropView = Command("drop view {0}", connection, viewName)) dropView.Execute(); return output; } } } } finally { ReleaseViewName(viewName); } }
SummonerStatistics GetSummonerStatistics(Summoner summoner, DbConnection connection) { List<SummonerRating> ratings = GetSummonerRatings(summoner, connection); List<List<SummonerRankedStatistics>> rankedStatistics = new List<List<SummonerRankedStatistics>>(); for (int i = 0; i <= ProgramConfiguration.RankedSeason; i++) rankedStatistics.Add(GetSummonerRankedStatistics(summoner, i, connection)); List<AggregatedChampionStatistics> twistedTreelineStatistics = LoadAggregatedChampionStatistics(summoner, MapType.TwistedTreeline, GameModeType.Normal, connection); List<AggregatedChampionStatistics> summonersRiftStatistics = LoadAggregatedChampionStatistics(summoner, MapType.SummonersRift, GameModeType.Normal, connection); List<AggregatedChampionStatistics> dominionStatistics = LoadAggregatedChampionStatistics(summoner, MapType.Dominion, GameModeType.Normal, connection); SummonerStatistics statistics = new SummonerStatistics(ratings, rankedStatistics, twistedTreelineStatistics, summonersRiftStatistics, dominionStatistics); return statistics; }
void LoadSummonerRankedStatistics(Summoner summoner, NpgsqlConnection database) { DatabaseCommand select = GetCommand("select {0} from summoner_ranked_statistics where summoner_id = :summoner_id", database, SummonerRankedStatistics.GetFields()); select.Set("summoner_id", summoner.Id); using (NpgsqlDataReader reader = select.ExecuteReader()) { while (reader.Read()) { SummonerRankedStatistics statistics = new SummonerRankedStatistics(reader); statistics.ChampionName = GetChampionName(statistics.ChampionId); summoner.RankedStatistics.Add(statistics); } summoner.RankedStatistics.Sort(); } }
void LoadAggregatedChampionStatistics(Summoner summoner, DbConnection connection) { summoner.SummonersRiftNormalStatistics = LoadAggregatedChampionStatistics(summoner, MapType.SummonersRift, GameModeType.Normal, connection); summoner.DominionNormalStatistics = LoadAggregatedChampionStatistics(summoner, MapType.Dominion, GameModeType.Normal, connection); }
void UpdateSummonerGame(Summoner summoner, PlayerGameStats game, DbConnection connection) { //Don't store tutorial games if (game.gameMode == "TUTORIAL" || game.gameType == "TUTORIAL_GAME") return; const int blueId = 100; //const int purpleId = 200; bool isBlueTeam = game.teamId == blueId; int gameId; int summonerTeamId; GameResult gameResult = new GameResult(game); //At first we must determine if the game is already in the database using (var check = Command("select id, blue_team_id, purple_team_id from game where game.game_id = :game_id", connection)) { check.Set("game_id", game.gameId); using (var reader = check.ExecuteReader()) { if (reader.Read()) { //The game is already in the database gameId = reader.Integer(); int purpleTeamId = reader.Integer(); int blueTeamId = reader.Integer(); if (isBlueTeam) summonerTeamId = blueTeamId; else summonerTeamId = purpleTeamId; //Check if the game result for this player has already been stored using (var gameCheck = Command("select count(*) from player where (team_id = :blue_team_id or team_id = :purple_team_id) and summoner_id = :summoner_id", connection)) { gameCheck.Set("blue_team_id", blueTeamId); gameCheck.Set("purple_team_id", purpleTeamId); gameCheck.Set("summoner_id", summoner.Id); long count = (long)gameCheck.ExecuteScalar(); if (count > 0) { //The result of this game for this player has already been stored in the database, there is no work to be done return; } } //The game is already stored in the database but the results of this player were previously unknown //This means that this player must be removed from the list of unknown players for this game using (var delete = Command("delete from unknown_player where team_id = :team_id and account_id = :account_id", connection)) { delete.Set("team_id", summonerTeamId); delete.Set("account_id", summoner.AccountId); delete.Execute(); } } else { //The game is not in the database yet //Need to create the team entries first using (var newTeam = Command("insert into team default values", connection)) { newTeam.Execute(); int blueTeamId = GetInsertId(connection); newTeam.Execute(); int purpleTeamId = GetInsertId(connection); summonerTeamId = isBlueTeam ? blueTeamId : purpleTeamId; MapType map; GameModeType gameMode; switch (game.gameMapId) { //Autumn case 1: //No idea what 2 means case 2: //Not sure either, encountered this in some games from 4 months ago on an inactive account case 3: //Winter case 6: map = MapType.SummonersRift; break; case 4: map = MapType.TwistedTreeline; break; case 8: map = MapType.Dominion; break; default: throw new Exception(string.Format("Unknown game map ID in the match history of {0}: {1}", summoner.SummonerName, game.gameMapId)); } if (game.gameType == "PRACTICE_GAME") gameMode = GameModeType.Custom; else { switch (game.queueType) { case "RANKED_TEAM_3x3": case "RANKED_TEAM_5x5": case "RANKED_PREMADE_3x3": case "RANKED_PREMADE_5x5": gameMode = GameModeType.Premade; break; case "NORMAL": case "ODIN_UNRANKED": gameMode = GameModeType.Normal; break; case "RANKED_SOLO_5x5": gameMode = GameModeType.Solo; break; case "BOT": gameMode = GameModeType.Bot; break; default: throw new Exception(string.Format("Unknown queue type in the match history of {0}: {1}", summoner.SummonerName, game.queueType)); } } using (var newGame = Command("insert into game ({0}) values ({1})", connection, GetGroupString(NewGameFields), GetPlaceholderString(NewGameFields))) { newGame.SetFieldNames(NewGameFields); newGame.Set(game.gameId); newGame.Set(map); newGame.Set(gameMode); newGame.Set(game.createDate.ToUnixTime()); newGame.Set(blueTeamId); newGame.Set(purpleTeamId); newGame.Set(gameResult.Win == isBlueTeam); newGame.Execute(); gameId = GetInsertId(connection); //We need to create a list of unknown players for this game so they can get updated in future if necessary //Otherwise it is unclear who participated in this game //Retrieving their stats at this point is too expensive and hence undesirable foreach (var player in game.fellowPlayers) { using (var missingPlayer = Command("insert into unknown_player (team_id, champion_id, account_id) values (:team_id, :champion_id, :account_id)", connection)) { missingPlayer.Set("team_id", player.teamId == blueId ? blueTeamId : purpleTeamId); missingPlayer.Set("champion_id", player.championId); //It's called summonerId but it's really the account ID (I think) missingPlayer.Set("account_id", player.summonerId); missingPlayer.Execute(); } } } } } } } InsertGameResult(summoner, gameId, summonerTeamId, game, gameResult, connection); }
void SummonerMessage(string message, Summoner summoner, params object[] arguments) { WriteLine(string.Format("{0} ({1}): {2}", summoner.SummonerName, summoner.AccountId, message), arguments); }
Summoner LoadSummoner(string regionName, int accountId, NpgsqlConnection database) { RegionHandler regionHandler = GetRegionHandler(regionName); DatabaseCommand select = GetCommand("select {0} from summoner where region = cast(:region as region_type) and account_id = :account_id", database, Summoner.GetFields()); select.SetEnum("region", regionHandler.GetRegionEnum()); select.Set("account_id", accountId); using (NpgsqlDataReader reader = select.ExecuteReader()) { Summoner summoner = null; if (reader.Read()) summoner = new Summoner(reader); if (summoner == null) throw new HandlerException("No such summoner"); return summoner; } }
List<AggregatedChampionStatistics> LoadAggregatedChampionStatistics(Summoner summoner, MapType map, GameModeType gameMode, DbConnection database) { const string query = "with source as " + "(select team_player.champion_id, team_player.won, team_player.kills, team_player.deaths, team_player.assists, team_player.gold, team_player.minion_kills from game_result, team_player where game_result.result_map = cast(:result_map as map_type) and game_result.game_mode = cast(:game_mode as game_mode_type) and (game_result.team1_id = team_player.team_id or game_result.team2_id = team_player.team_id) and team_player.summoner_id = :summoner_id) " + "select statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills from " + "(select source.champion_id, sum(source.kills) as kills, sum(source.deaths) as deaths, sum(source.assists) as assists, sum(source.gold) as gold, sum(source.minion_kills) as minion_kills from source group by source.champion_id) " + "as statistics " + "left outer join " + "(select champion_id, count(*) as wins from source where won = true group by champion_id) " + "as champion_wins " + "on statistics.champion_id = champion_wins.champion_id " + "left outer join " + "(select champion_id, count(*) as losses from source where won = false group by champion_id) " + "as champion_losses " + "on statistics.champion_id = champion_losses.champion_id;", myquery = @"SELECT statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills FROM ( SELECT source.champion_id, sum(source.kills) as kills, sum(source.deaths) as deaths, sum(source.assists) as assists, sum(source.gold) as gold, sum(source.minion_kills) as minion_kills FROM source WHERE source.result_map = ?result_map AND source.game_mode = ?game_mode AND source.summoner_id = ?summoner_id GROUP BY source.champion_id ) AS statistics LEFT OUTER JOIN ( SELECT champion_id, count(*) as wins FROM source WHERE source.won = true AND source.result_map = ?result_map AND source.game_mode = ?game_mode AND source.summoner_id = ?summoner_id GROUP BY champion_id ) champion_wins ON statistics.champion_id = champion_wins.champion_id LEFT OUTER JOIN ( SELECT champion_id, count(*) as losses FROM source WHERE source.won = false AND source.result_map = ?result_map AND source.game_mode = ?game_mode AND source.summoner_id = ?summoner_id GROUP BY champion_id ) champion_losses ON statistics.champion_id = champion_losses.champion_id;"; SQLCommand select; if (database is MySql.Data.MySqlClient.MySqlConnection) select = GetCommand(myquery, database); else select = GetCommand(query, database); select.SetEnum("result_map", map.ToEnumString()); select.SetEnum("game_mode", gameMode.ToEnumString()); select.Set("summoner_id", summoner.Id); using (DbDataReader reader = select.ExecuteReader()) { List<AggregatedChampionStatistics> output = new List<AggregatedChampionStatistics>(); while (reader.Read()) { AggregatedChampionStatistics statistics = new AggregatedChampionStatistics(reader); statistics.ChampionName = GetChampionName(statistics.ChampionId); output.Add(statistics); } output.Sort(); return output; } }
void LoadSummonerRating(Summoner summoner, NpgsqlConnection database) { DatabaseCommand select = GetCommand("select {0} from summoner_rating where summoner_id = :summoner_id", database, SummonerRating.GetFields()); select.Set("summoner_id", summoner.Id); using (NpgsqlDataReader reader = select.ExecuteReader()) { while (reader.Read()) { SummonerRating rating = new SummonerRating(reader); summoner.Ratings.Add(rating); Dictionary<GameModeType, SummonerRating> dictionary; if (!summoner.RatingDictionary.TryGetValue(rating.Map, out dictionary)) { dictionary = new Dictionary<GameModeType, SummonerRating>(); summoner.RatingDictionary[rating.Map] = dictionary; } dictionary[rating.GameMode] = rating; } summoner.Ratings.Sort(CompareRatings); } }
List<SummonerRating> GetSummonerRatings(Summoner summoner, DbConnection connection) { using (var select = Command("select {0} from summoner_rating where summoner_id = :summoner_id", connection, SummonerRating.GetFields())) { select.Set("summoner_id", summoner.Id); using (var reader = select.ExecuteReader()) { List<SummonerRating> output = new List<SummonerRating>(); while (reader.Read()) { SummonerRating rating = new SummonerRating(reader); output.Add(rating); } return output; } } }
void InsertGameResult(Summoner summoner, int gameId, int teamId, PlayerGameStats game, GameResult gameResult, DbConnection connection) { string queryFields = GetGroupString(InsertGameResultFields); string queryValues = GetPlaceholderString(InsertGameResultFields); using (var insert = Command("insert into player ({0}) values ({1})", connection, queryFields, queryValues)) { insert.SetFieldNames(InsertGameResultFields); insert.Set(gameId); insert.Set(teamId); insert.Set(summoner.Id); insert.Set(game.userServerPing); insert.Set(game.timeInQueue); insert.Set(game.premadeSize); insert.Set(game.experienceEarned); insert.Set(game.boostXpEarned); insert.Set(game.ipEarned); insert.Set(game.boostIpEarned); insert.Set(game.level); insert.Set(game.spell1); insert.Set(game.spell2); insert.Set(game.championId); insert.Set(game.skinName); insert.Set(game.skinIndex); insert.Set(gameResult.Level); //Items are an array of integers and require special treatment string itemString = string.Format("'{{{0}}}'", string.Join(", ", gameResult.Items)); insert.Set(itemString); insert.Set(gameResult.Kills); insert.Set(gameResult.Deaths); insert.Set(gameResult.Assists); insert.Set(gameResult.MinionsKilled); insert.Set(gameResult.GoldEarned); insert.Set(gameResult.TotalDamageDealt); insert.Set(gameResult.PhysicalDamageDealt); insert.Set(gameResult.MagicalDamageDealt); insert.Set(gameResult.TotalDamageTaken); insert.Set(gameResult.PhysicalDamageTaken); insert.Set(gameResult.MagicalDamageTaken); insert.Set(gameResult.TotalHealingDone); insert.Set(gameResult.TimeSpentDead); insert.Set(gameResult.LargestMultiKill); insert.Set(gameResult.LargestKillingSpree); insert.Set(gameResult.LargestCriticalStrike); //Summoner's Rift/Twisted Treeline insert.Set(gameResult.NeutralMinionsKilled); insert.Set(gameResult.TurretsDestroyed); insert.Set(gameResult.InhibitorsDestroyed); //Dominion insert.Set(gameResult.NodesNeutralised); insert.Set(gameResult.NodeNeutralisationAssists); insert.Set(gameResult.NodesCaptured); insert.Set(gameResult.VictoryPoints); insert.Set(gameResult.Objectives); insert.Set(gameResult.TotalScore); insert.Set(gameResult.ObjectiveScore); insert.Set(gameResult.CombatScore); insert.Set(gameResult.Rank); insert.Execute(); } }
void InitialiseSummonerCache() { SummonerCache = new Dictionary<RegionType, Dictionary<int, Summoner>>(); foreach (RegionType regionType in Enum.GetValues(typeof(RegionType))) SummonerCache[regionType] = new Dictionary<int, Summoner>(); using (var connection = Provider.GetConnection()) { using (var select = new DatabaseCommand("select {0} from summoner", connection, null, Summoner.GetFields())) { using (var reader = select.ExecuteReader()) { while (reader.Read()) { Summoner summoner = new Summoner(reader); SummonerCache[summoner.Region][summoner.AccountId] = summoner; } } } } }
string GetSummonerGamesTable(Summoner summoner, List<GameTeamPlayer> games) { string[] titles = { "Champion", "Map", "Mode", "Date", "K", "D", "A", "MK", "NK", "Gold", "Rating", "Adjusted rating", "Team rating", "Items", "Premade", "Ping", "Time in queue", "Game ID", }; string firstRow = ""; foreach (var title in titles) firstRow += Markup.TableHead(title); string rows = Markup.TableRow(firstRow); foreach (var game in games) { string championName = GetChampionName(game.ChampionId); string championDescription = Markup.Image(GetImage(string.Format("Champion/Small/{0}.png", Markup.UriEncode(championName))), championName) + championName; string items = "\n"; foreach (var itemId in game.Items) { if (itemId == 0) items += Markup.Image(GetImage("Item/Small/Blank.png"), "Unused"); else { ItemInformation item = GetItemInformation(itemId); items += Markup.Image(GetImage(string.Format("Item/Small/{0}.png", item.UnknownItem ? "Unknown" : itemId.ToString())), item.Name); } } string noValue = "-"; string ratingDescription = noValue; if (game.Rating.HasValue && game.RatingChange.HasValue && game.Rating > 0) ratingDescription = string.Format("{0} ({1})", game.Rating + game.RatingChange, SignumString(game.RatingChange.Value)); string adjustedRating = noValue; if (game.AdjustedRating.HasValue && game.AdjustedRating.Value > 0) adjustedRating = game.AdjustedRating.ToString(); string teamRating = noValue; if(game.Rating.HasValue && game.TeamRating.HasValue && game.Rating > 0) teamRating = string.Format("{0} ({1})", game.TeamRating, SignumString(game.Rating.Value - game.TeamRating.Value)); string[] fields1 = { championDescription, game.Map.GetString(), game.GameMode.GetString(), game.GameTime.ToStandardString(), game.Kills.ToString(), game.Deaths.ToString(), game.Assists.ToString(), game.MinionKills.ToString(), game.NeutralMinionsKilled.HasValue ? game.NeutralMinionsKilled.ToString() : noValue, game.Gold.ToString(), ratingDescription, adjustedRating, teamRating, }; string row = ""; foreach (var field in fields1) row += Markup.TableCell(field); row += Markup.ContentTag("td", items, new Dictionary<string, string>() {{"class", "items"}}, true); string premadeString; if (game.GameMode == GameModeType.Custom) premadeString = noValue; else premadeString = game.PremadeSize <= 1 ? "No" : string.Format("Yes, {0}", game.PremadeSize); string queueTimeString = game.TimeSpentInQueue > 0 ? string.Format("{0} s", game.TimeSpentInQueue) : noValue; string[] fields2 = { premadeString, string.Format("{0} ms", game.Ping), queueTimeString, game.InternalGameId.ToString(), }; foreach (var field in fields2) row += Markup.TableCell(field); rows += Markup.TableRow(row, style: game.Won ? "win" : "loss"); } string caption = Markup.Caption(string.Format("Games of {0}", summoner.SummonerName)); string table = Markup.Table(caption + rows, style: "statistics", id: "summonerGames"); return table; }
string GetAggregatedChampionStatistics(Summoner summoner) { string output = GetAggregatedChampionStatistics("Normal Summoner's Rift Statistics", "summonersRiftNormal", summoner.SummonersRiftNormalStatistics); output += GetAggregatedChampionStatistics("Normal Dominion Statistics", "dominionNormal", summoner.DominionNormalStatistics); return output; }
void LoadAggregatedChampionStatistics(Summoner summoner, NpgsqlConnection database) { summoner.SummonersRiftNormalStatistics = LoadAggregatedChampionStatistics(summoner, MapType.SummonersRift, GameModeType.Normal, database); summoner.DominionNormalStatistics = LoadAggregatedChampionStatistics(summoner, MapType.Dominion, GameModeType.Normal, database); }