public ActionResult Index(int championCount, List <int?> ids) { try { var currentModel = CurrentChampionsModel; while (championCount > ids.Count) { ids.Add(currentModel.AvailableChampions[ids.Count].Id); } if (championCount < ids.Count) { ids = ids.Take(championCount).ToList(); } using (var riotDb = new RiotDataContext()) { var championTotals = new TotalsStatistics(ids, riotDb); currentModel.ChampionIds = ids; currentModel.ChampionCount = ids.Count; currentModel.ChampionTotals = championTotals; CurrentChampionsModel = currentModel; return(View(currentModel)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Champions", "Index"))); } }
private static void AddMatchIds(int bucketTime) { using (var riotDb = new RiotDataContext()) { foreach (var matchId in MatchIds) { if (!riotDb.Matches.Any(m => m.MatchId == matchId)) { riotDb.Matches.InsertOnSubmit(new Match { BucketTime = bucketTime, MatchId = matchId }); } } riotDb.SubmitChanges(); } }
public ActionResult Index() { try { var model = new MatchesViewModel { ChampionData = RiotService.ChampionsService() }; using (var riotDb = new RiotDataContext()) model.Matches = riotDb.Matches.Select(x => x.MatchId).ToList(); model.CurrentMatchData = RiotService.MatchService(model.Matches.First()); model.CurrentMatchId = model.Matches.First(); CurrentMatchModel = model; return(View(model)); } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Home", "Index"))); } }
public ActionResult Index() { try { using (var riotDb = new RiotDataContext()) { var championData = RiotService.ChampionsService(); var availableChampionIds = riotDb.Participants .Select(m => m.ChampionId ?? 0).ToList() .Where(m => m != 0).Distinct().ToList(); var availableChampions = championData.Champions .Where(x => availableChampionIds.Contains(x.Key)) .Select(x => x.Value).OrderBy(x => x.Name).ToList(); var ids = new List <int?> { availableChampions[0].Id, availableChampions[1].Id, availableChampions[2].Id }; var championTotals = new TotalsStatistics(ids, riotDb); var model = new ChampionsViewModel { AvailableChampions = availableChampions, ChampionCount = ids.Count, ChampionTotals = championTotals, ChampionIds = ids }; CurrentChampionsModel = model; return(View(model)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Champions", "Index"))); } }
private static void AddMatchData(List <Match> matches, RiotDataContext riotDb) { Console.WriteLine("Updating {0} matches.", matches.Count()); foreach (var match in matches) { var matchData = RiotService.MatchService(match.MatchId); var currentMatch = riotDb.Matches.First(m => m.MatchId == match.MatchId); currentMatch.AddMatchData(matchData); foreach (var participant in matchData.Participants) { var stats = StatisticsMapper.MapParticipantStat(participant.Statistics); currentMatch.Participants.Add(ParticipantMapper.MapParticipant(matchData, participant, stats)); } foreach (var team in matchData.Teams) { currentMatch.Teams.Add(TeamMapper.MapTeam(team)); } riotDb.SubmitChanges(); } }
private static string GetApiKey() { using (var riotDb = new RiotDataContext()) return(riotDb.ApiKeys.First().ApiKey1); }
static void Main() { Console.WriteLine("Hint: Pressing enter will use default values."); try { Console.WriteLine("How many buckets should be gather?"); RunTimes = Convert.ToInt32(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Unable to read run count. Using default of 288 (24 hours)"); RunTimes = 288; } try { Console.WriteLine("What date should we start at?"); DateTime startDate; DateTime.TryParse(Console.ReadLine(), out startDate); StartDate = startDate; if (StartDate < new DateTime(2015, 4, 1)) { throw new Exception("Invalid start date"); } } catch (Exception) { Console.WriteLine("Unable to read StartDate. Using default of 4/1/2015"); StartDate = new DateTime(2015, 4, 1); } try { Console.WriteLine("How far from the start date should we offset? i*5min"); Offset = Convert.ToInt32(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Unable to read offset. Using default of 0"); Offset = 0; } while (RunTimes >= 0) { Console.WriteLine("Runs remaining " + RunTimes); var bucketTime = BucketTime; Console.WriteLine("Time " + bucketTime); MatchIds = RiotService.ApiChallenge(bucketTime); if (MatchIds != null && MatchIds.Count > 0) { AddMatchIds(bucketTime); using (var riotDb = new RiotDataContext()) { var matches = riotDb.Matches.Where(m => m.MapId == null).ToList(); AddMatchData(matches, riotDb); } } else { Console.WriteLine("No matches found"); } RunTimes--; } }
public TotalsStatistics(IEnumerable <int?> ids, RiotDataContext riotDb) { Statistics = new List <StatisticsGroup> { new StatisticsGroup("Game", new List <StatisticItem> { new StatisticItem("Wins", new List <long>()), new StatisticItem("Losses", new List <long>()) }), new StatisticsGroup("Basic", new List <StatisticItem> { new StatisticItem("Kills", new List <long>()), new StatisticItem("Deaths", new List <long>()), new StatisticItem("Assists", new List <long>()) }), new StatisticsGroup("Farming", new List <StatisticItem> { new StatisticItem("Minions Killed", new List <long>()), new StatisticItem("Gold Earned", new List <long>()) }), new StatisticsGroup("Kill", new List <StatisticItem> { new StatisticItem("Killing Sprees", new List <long>()), new StatisticItem("Largest Killing Spree", new List <long>()), new StatisticItem("Largest Multi Kill", new List <long>()), new StatisticItem("Double Kills", new List <long>()), new StatisticItem("Triple Kills", new List <long>()), new StatisticItem("Quadra Kills", new List <long>()), new StatisticItem("Penta Kills", new List <long>()) }), new StatisticsGroup("Firsts", new List <StatisticItem> { new StatisticItem("First Blood Assist", new List <long>()), new StatisticItem("First Blood Kill", new List <long>()), new StatisticItem("First Inhibitor Assist", new List <long>()), new StatisticItem("First Inhibitor Kill", new List <long>()), new StatisticItem("First Tower Assist", new List <long>()), new StatisticItem("First Tower Kill", new List <long>()) }), new StatisticsGroup("Objective", new List <StatisticItem> { new StatisticItem("Inhibitor Kills", new List <long>()), new StatisticItem("Tower Kills", new List <long>()) }), new StatisticsGroup("Damage", new List <StatisticItem> { new StatisticItem("Largest Critical Strike", new List <long>()), new StatisticItem("Magic Damage", new List <long>()), new StatisticItem("Magic Damage To Champions", new List <long>()), new StatisticItem("Magic Damage Taken", new List <long>()), new StatisticItem("Physical Damage", new List <long>()), new StatisticItem("Physical Damage To Champions", new List <long>()), new StatisticItem("Physical Damage Taken", new List <long>()), new StatisticItem("Total Damage", new List <long>()), new StatisticItem("Total Damage To Champions", new List <long>()), new StatisticItem("Total Damage Taken", new List <long>()), new StatisticItem("True Damage", new List <long>()), new StatisticItem("True Damage To Champions", new List <long>()), new StatisticItem("True Damage Taken", new List <long>()) }), new StatisticsGroup("Healing", new List <StatisticItem> { new StatisticItem("Total Healing", new List <long>()), new StatisticItem("Total Units Healed", new List <long>()), new StatisticItem("Total Time Crowd Control Dealt", new List <long>()), }), new StatisticsGroup("Jungle", new List <StatisticItem> { new StatisticItem("Neutral Minions Killed", new List <long>()), new StatisticItem("Neutral Minions Killed Enemy Jungle", new List <long>()), new StatisticItem("Neutral Minions Killed Team Jungle", new List <long>()) }), new StatisticsGroup("Vision", new List <StatisticItem> { new StatisticItem("Sight Wards Bought", new List <long>()), new StatisticItem("Vision Wards Bought", new List <long>()), new StatisticItem("Wards Placed", new List <long>()), new StatisticItem("Wards Killed", new List <long>()) }) }; var gameSection = Statistics.First(x => x.Name == "Game").Values; var basicSection = Statistics.First(x => x.Name == "Basic").Values; var farmingSection = Statistics.First(x => x.Name == "Farming").Values; var killSection = Statistics.First(x => x.Name == "Kill").Values; var firstsSection = Statistics.First(x => x.Name == "Firsts").Values; var objectiveSection = Statistics.First(x => x.Name == "Objective").Values; var damageSection = Statistics.First(x => x.Name == "Damage").Values; var healingSection = Statistics.First(x => x.Name == "Healing").Values; var jungleSection = Statistics.First(x => x.Name == "Jungle").Values; var visionSection = Statistics.First(x => x.Name == "Vision").Values; foreach (var id in ids) { var champion = riotDb.ChampionStats.First(x => x.ChampionId == id); gameSection.First(x => x.Name == "Wins").Values.Add(champion.Wins ?? 0); gameSection.First(x => x.Name == "Losses").Values.Add(champion.Losses ?? 0); basicSection.First(x => x.Name == "Kills").Values.Add(champion.Kills ?? 0); basicSection.First(x => x.Name == "Deaths").Values.Add(champion.Deaths ?? 0); basicSection.First(x => x.Name == "Assists").Values.Add(champion.Assists ?? 0); farmingSection.First(x => x.Name == "Minions Killed").Values.Add(champion.MinionsKilled ?? 0); farmingSection.First(x => x.Name == "Gold Earned").Values.Add(champion.GoldEarned ?? 0); killSection.First(x => x.Name == "Killing Sprees").Values.Add(champion.KillingSprees ?? 0); killSection.First(x => x.Name == "Largest Killing Spree").Values.Add(champion.LargestKillingSpree ?? 0); killSection.First(x => x.Name == "Largest Multi Kill").Values.Add(champion.LargestMultiKill ?? 0); killSection.First(x => x.Name == "Double Kills").Values.Add(champion.DoubleKills ?? 0); killSection.First(x => x.Name == "Triple Kills").Values.Add(champion.TripleKills ?? 0); killSection.First(x => x.Name == "Quadra Kills").Values.Add(champion.QuadraKills ?? 0); killSection.First(x => x.Name == "Penta Kills").Values.Add(champion.PentaKills ?? 0); firstsSection.First(x => x.Name == "First Blood Assist").Values.Add(champion.FirstBloodAssists ?? 0); firstsSection.First(x => x.Name == "First Blood Kill").Values.Add(champion.FirstBloodKill ?? 0); firstsSection.First(x => x.Name == "First Inhibitor Assist").Values.Add(champion.FirstInhibitorAssist ?? 0); firstsSection.First(x => x.Name == "First Inhibitor Kill").Values.Add(champion.FirsInhibitorKill ?? 0); firstsSection.First(x => x.Name == "First Tower Assist").Values.Add(champion.FirstTowerAssist ?? 0); firstsSection.First(x => x.Name == "First Tower Kill").Values.Add(champion.FirstTowerKill ?? 0); objectiveSection.First(x => x.Name == "Inhibitor Kills").Values.Add(champion.InhibitorKills ?? 0); objectiveSection.First(x => x.Name == "Tower Kills").Values.Add(champion.TowerKills ?? 0); damageSection.First(x => x.Name == "Largest Critical Strike").Values.Add(champion.LargestCriticalStrike ?? 0); damageSection.First(x => x.Name == "Magic Damage").Values.Add(champion.MagicDamageDealt ?? 0); damageSection.First(x => x.Name == "Magic Damage To Champions").Values.Add(champion.MagicDamageDealtToChampions ?? 0); damageSection.First(x => x.Name == "Magic Damage Taken").Values.Add(champion.MagicDamageTaken ?? 0); damageSection.First(x => x.Name == "Physical Damage").Values.Add(champion.PhysicalDamageDealt ?? 0); damageSection.First(x => x.Name == "Physical Damage To Champions").Values.Add(champion.PhysicalDamageDealtToChampions ?? 0); damageSection.First(x => x.Name == "Physical Damage Taken").Values.Add(champion.PhysicalDamageTaken ?? 0); damageSection.First(x => x.Name == "Total Damage").Values.Add(champion.TotalDamageDealt ?? 0); damageSection.First(x => x.Name == "Total Damage To Champions").Values.Add(champion.TotalDamageDealtToChampions ?? 0); damageSection.First(x => x.Name == "Total Damage Taken").Values.Add(champion.TotalDamageTaken ?? 0); damageSection.First(x => x.Name == "True Damage").Values.Add(champion.TrueDamageDealt ?? 0); damageSection.First(x => x.Name == "True Damage To Champions").Values.Add(champion.TrueDamageDealtToChampions ?? 0); damageSection.First(x => x.Name == "True Damage Taken").Values.Add(champion.TrueDamageTaken ?? 0); healingSection.First(x => x.Name == "Total Healing").Values.Add(champion.TotalHealing ?? 0); healingSection.First(x => x.Name == "Total Units Healed").Values.Add(champion.TotalUnitsHealed ?? 0); healingSection.First(x => x.Name == "Total Time Crowd Control Dealt").Values.Add(champion.TotalTimeCrowdControlDealt ?? 0); jungleSection.First(x => x.Name == "Neutral Minions Killed").Values.Add(champion.NeutralMinionsKilled ?? 0); jungleSection.First(x => x.Name == "Neutral Minions Killed Enemy Jungle").Values.Add(champion.NeutralMinionsKilledEnemyJungle ?? 0); jungleSection.First(x => x.Name == "Neutral Minions Killed Team Jungle").Values.Add(champion.NeutralMinionsKilledTeamJungle ?? 0); visionSection.First(x => x.Name == "Sight Wards Bought").Values.Add(champion.SightWardsBoughtInGame ?? 0); visionSection.First(x => x.Name == "Vision Wards Bought").Values.Add(champion.VisionWardsBoughtInGame ?? 0); visionSection.First(x => x.Name == "Wards Placed").Values.Add(champion.WardsPlaced ?? 0); visionSection.First(x => x.Name == "Wards Killed").Values.Add(champion.WardsKilled ?? 0); } }
public ActionResult Index() { try { var model = new FunStatViewModel(); using (var riotDb = new RiotDataContext()) { model.ChampionData = RiotService.ChampionsService(); model.MatchCount = riotDb.Matches.Count(); var funStats = riotDb.FunStats().ToList(); var wonMatches = riotDb.Teams.Where(x => x.Winner == true); var lostMatches = riotDb.Teams.Where(x => x.Winner == false); var matchData = wonMatches.Join(lostMatches, a => a.MatchId, b => b.MatchId, (a, b) => new MatchData(a, b)) .ToList(); model.WinData.Add(new FunStatsResponse { Name = "Baron Kills", Won = matchData.Count(x => x.WinningTeam.BaronKills > x.LosingTeam.BaronKills), Lost = matchData.Count(x => x.WinningTeam.BaronKills < x.LosingTeam.BaronKills), Tied = matchData.Count(x => x.WinningTeam.BaronKills == x.LosingTeam.BaronKills) }); model.WinData.Add(new FunStatsResponse { Name = "Dragon Kills", Won = matchData.Count(x => x.WinningTeam.DragonKills > x.LosingTeam.DragonKills), Lost = matchData.Count(x => x.WinningTeam.DragonKills < x.LosingTeam.DragonKills), Tied = matchData.Count(x => x.WinningTeam.DragonKills == x.LosingTeam.DragonKills) }); model.WinData.Add(funStats.First(x => x.Name == "Minion Kills")); model.WinData.Add(funStats.First(x => x.Name == "Kills")); model.WinData.Add(funStats.First(x => x.Name == "Wards")); model.GamesWithNoDragons = matchData.Count(x => x.WinningTeam.DragonKills == 0 && x.LosingTeam.DragonKills == 0); model.GamesWithNoBarons = matchData.Count(x => x.WinningTeam.BaronKills == 0 && x.LosingTeam.BaronKills == 0); var playedChamps = riotDb.Participants.GroupBy(x => x.ChampionId) .Select(g => new PlayedChampionData { ChampionId = g.Key ?? 0, PlayCount = g.Count() }) .OrderByDescending(x => x.PlayCount); model.MostPlayedChampions = playedChamps.Take(5).ToList(); model.LeastPlayedChampions = playedChamps.OrderBy(x => x.PlayCount).Take(5).OrderByDescending(x => x.PlayCount).ToList(); var participantsAndStats = riotDb.Participants.Join(riotDb.ParticipantStats, p => p.Id, s => s.Id, (p, s) => new { Participant = p, ParticipantStats = s }); var participantsAndStatsWinners = participantsAndStats.Where(x => x.ParticipantStats.Winner == true).GroupBy(x => x.Participant.ChampionId).Select(x => new WinRateChampionData { ChampionId = x.Key ?? 0, WinCount = x.Count() }); var participantsAndStatsLosers = participantsAndStats.Where(x => x.ParticipantStats.Winner == false).GroupBy(x => x.Participant.ChampionId).Select(x => new WinRateChampionData { ChampionId = x.Key ?? 0, LossCount = x.Count() }); model.WinRateChampionData = participantsAndStatsWinners.Join(participantsAndStatsLosers, w => w.ChampionId, l => l.ChampionId, (w, l) => new WinRateChampionData { ChampionId = w.ChampionId, WinCount = w.WinCount, LossCount = l.LossCount }) .ToList() .OrderByDescending(x => x.WinRate) .Take(5) .ToList(); return(View(model)); } } catch (Exception e) { return(View("Error", new HandleErrorInfo(e, "Home", "Index"))); } }