public async Task <IActionResult> GetMostChampPlayedRanked([FromBody] MostPlayedChampsRequestModel body) { try { var queueList = new List <GamesByQueue>(); var vm = new RankedProfileVM(); //* looping and declaring informationObject per queue with configuration information foreach (var entry in body.LeagueEntries) { queueList.Add(new GamesByQueue(entry)); } //* Fetch all ranked games played this season and add them to list foreach (var queue in queueList) { var refList = new ReferenceListWithTag(queue); refList.MatchList = await _leagueApiService.GetMatchesRankedProfileAsync(queue); vm.RankedQueues.Add(refList); } //* DataService picks most played champs _datahandler.GetMostPlayedChamp(vm.RankedQueues[0]); //* vm has obj for most played in solo and flex and total var VM = new ChampionRankedMostPlayedVM(); foreach (var reference in vm.RankedQueues) { var result = _datahandler.GetMostPlayedChamp(reference); VM.QueueList.Add(result); } //TODO Create method for calculating winrate when better API key is accuired return(Ok(VM)); } catch (System.Exception) { return(StatusCode(500)); } }
public ListMatchListForChampion GetMostPlayedChamp(ReferenceListWithTag reference) { var listForChampion = new ListMatchListForChampion(); listForChampion.QueueId = new int[] { reference.QueueId }; try { var most = reference.MatchList.GroupBy(x => x.Champion).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key).Take(5).ToList(); foreach (var champId in most) { var newChamp = new MatchListForChampion(); newChamp.ChampionId = champId; var result = reference.MatchList.Where(x => x.Champion == champId).ToList(); newChamp.GameCount = result.Count; listForChampion.MatchListChampion.Add(newChamp); } return(listForChampion); } catch (System.Exception ex) { throw ex; } }