Ejemplo n.º 1
0
 public GWTeam()
 {
     picks          = new List <Pick>();
     automatic_subs = new List <AutomaticSub>();
     ActiveChips    = new List <string>();
     GWTransfers    = new List <Transfer>();
     EntryHistory   = new EntryHistory();
 }
Ejemplo n.º 2
0
        public async Task <EntryHistory> AddExtraDatatoEntryHistory(EntryHistory entryHistory, CompleteEntryHistory completeEntryHistory)
        {
            var response = await _httpClient.GetAsync("bootstrap-static/");

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var totalPlayersJson = AllChildren(JObject.Parse(content))
                                   .First(c => c.Type == JTokenType.Integer && c.Path.Contains("total_players"));

            //EntryHistory entryHistory = new EntryHistory();

            int totalPlayers = totalPlayersJson.ToObject <int>();

            entryHistory.TotalPlayers = totalPlayers;

            var gwRankPercentile      = 0m;
            var overallRankPercentile = 0m;

            if (entryHistory.rank != null)
            {
                gwRankPercentile = Math.Round(((decimal)entryHistory.rank / (decimal)totalPlayers) * 100m, 2);

                if (gwRankPercentile < 1)
                {
                    entryHistory.GwRankPercentile = 1;
                }
                else
                {
                    entryHistory.GwRankPercentile = Convert.ToInt32(Math.Ceiling(gwRankPercentile));
                }
            }

            if (entryHistory.overall_rank != null)
            {
                overallRankPercentile = Math.Round(((decimal)entryHistory.overall_rank / (decimal)totalPlayers) * 100m, 2);

                if (overallRankPercentile < 1)
                {
                    entryHistory.TotalRankPercentile = 1;
                }
                else
                {
                    entryHistory.TotalRankPercentile = Convert.ToInt32(Math.Ceiling(overallRankPercentile));
                }
            }

            if (completeEntryHistory.CurrentSeasonEntryHistory.Count() > 1)
            {
                var lastEventIndex = completeEntryHistory.CurrentSeasonEntryHistory.Count() - 2;
                entryHistory.LastEventOverallRank = completeEntryHistory.CurrentSeasonEntryHistory[lastEventIndex].overall_rank;
            }

            return(entryHistory);
        }
Ejemplo n.º 3
0
        private int CalculateTeamBuyingPower(List <Pick> picks, EntryHistory entryHistory)
        {
            var buyingPower = entryHistory.bank;

            foreach (var pick in picks)
            {
                buyingPower += pick.selling_price;
            }

            return(buyingPower);
        }
Ejemplo n.º 4
0
        public async Task <CompleteEntryHistory> GetCompleteEntryHistory(CompleteEntryHistory completeEntryHistory, int teamId)
        {
            HttpClientHandler handler = new HttpClientHandler();

            var response = await _httpClient.GetAuthAsync(CreateHandler(handler), $"entry/{teamId}/history/");

            response.EnsureSuccessStatusCode();

            var content = await response.Content.ReadAsStringAsync();

            var currentSeasonEntryHistoryJSON = AllChildren(JObject.Parse(content))
                                                .First(c => c.Type == JTokenType.Array && c.Path.Contains("current"))
                                                .Children <JObject>();

            List <EntryHistory> currentSeasonEntryHistory = new List <EntryHistory>();
            int totalTransfers    = 0;
            int totalTransferCost = 0;

            foreach (JObject result in currentSeasonEntryHistoryJSON)
            {
                EntryHistory eh = result.ToObject <EntryHistory>();
                currentSeasonEntryHistory.Add(eh);
                totalTransfers    += eh.event_transfers;
                totalTransferCost += eh.event_transfers_cost;
            }

            var chipsUsedJSON = AllChildren(JObject.Parse(content))
                                .First(c => c.Type == JTokenType.Array && c.Path.Contains("chips"))
                                .Children <JObject>();

            List <BasicChip> chipsUsed = new List <BasicChip>();

            foreach (JObject result in chipsUsedJSON)
            {
                BasicChip bc = result.ToObject <BasicChip>();
                chipsUsed.Add(bc);
            }

            completeEntryHistory.CurrentSeasonEntryHistory = currentSeasonEntryHistory;
            completeEntryHistory.ChipsUsed          = chipsUsed;
            completeEntryHistory.TotalTransfersMade = totalTransfers;
            completeEntryHistory.TotalTransfersCost = totalTransferCost;

            return(completeEntryHistory);
        }
Ejemplo n.º 5
0
        private async Task <EntryHistory> GetEntryHistory(int teamId, int gameweekId)
        {
            if (gameweekId != 0)
            {
                var response = await _httpClient.GetAsync($"entry/{teamId}/event/{gameweekId}/picks/");

                response.EnsureSuccessStatusCode();

                var content = await response.Content.ReadAsStringAsync();

                var entryHistoryJSON = AllChildren(JObject.Parse(content))
                                       .First(c => c.Type == JTokenType.Object && c.Path.Contains("entry_history"));

                EntryHistory entryHistory = new EntryHistory();

                entryHistory = entryHistoryJSON.ToObject <EntryHistory>();

                return(entryHistory);
            }
            else
            {
                return(new EntryHistory());
            }
        }