Beispiel #1
0
        public ActionResult Details(int?id)
        {
            var tournaments = ApiCaller.CallTournamentApi();

            var tournament = tournaments.SingleOrDefault(t => t.id == id);

            if (tournament == null)
            {
                return(HttpNotFound());
            }

            return(View(tournament));
        }
Beispiel #2
0
        //private ApplicationDbContext _context;
        //public TournamentController()
        //{
        //_context = new ApplicationDbContext();
        //}

        //protected override void Dispose(bool disposing)
        //{
        //_context.Dispose();
        //}

        public ActionResult Index()
        {
            var tournaments = ApiCaller.CallTournamentApi();

            return(View(tournaments));
        }
Beispiel #3
0
        public ActionResult UpdatePlayerInfo()
        {
            var tournaments = ApiCaller.CallTournamentApi();

            foreach (var tournament in tournaments)
            {
                if (tournament.completed_at == null)
                {
                    continue;
                }

                if (!tournament.game_name.Equals("Super Smash Bros. Melee"))
                {
                    continue;
                }

                var participants = ApiCaller.CallParticipantApi(tournament.id);

                foreach (var participant in participants)
                {
                    var player = _context.Players.SingleOrDefault(
                        p => p.Name.ToLower().Equals(participant.name.ToLower()));
                    if (player == null)
                    {
                        continue;
                    }
                    var updateSetWinCheck  = player.SetWins;
                    var updateSetLoseCheck = player.SetLoses;

                    var current = _context.CurrentPlayers.SingleOrDefault(
                        c => c.Name.ToLower().Equals(participant.name.ToLower()));
                    if (current == null)
                    {
                        continue;
                    }

                    if (player.LastUpdated.HasValue)
                    {
                        if (player.LastUpdated >= tournament.completed_at)
                        {
                            continue;
                        }
                    }

                    if (current.LastUpdated.HasValue)
                    {
                        if (current.LastUpdated >= tournament.completed_at)
                        {
                            continue;
                        }
                    }

                    // Helps give edge to Second place over Third
                    if (participant.final_rank == 2)
                    {
                        player.Bonus  = 5;
                        current.Bonus = 5;
                    }

                    var matches = ApiCaller.CallMatchApi(tournament.id, participant.id);

                    foreach (var match in matches)
                    {
                        // Helps track index used to get score for scores array
                        var winningScoreId = 0;
                        var losingScoreId  = 1;
                        if (participant.id == match.player2_id)
                        {
                            winningScoreId = 1;
                            losingScoreId  = 0;
                        }

                        //Get Split Scores into an int[]
                        int[] scores = Array.ConvertAll(match.scores_csv.Split('-'), Int32.Parse);
                        if (participant.id == match.winner_id)
                        {
                            player.SetWins++;
                            current.SetWins++;

                            player.MatchWins   += scores[winningScoreId];
                            player.MatchLoses  += scores[losingScoreId];
                            current.MatchWins  += scores[winningScoreId];
                            current.MatchLoses += scores[losingScoreId];
                        }
                        else if (participant.id == match.loser_id)
                        {
                            player.SetLoses++;
                            current.SetLoses++;

                            player.MatchWins   += scores[winningScoreId];
                            player.MatchLoses  += scores[losingScoreId];
                            current.MatchWins  += scores[winningScoreId];
                            current.MatchLoses += scores[losingScoreId];
                        }
                    }

                    if (player.SetWins == updateSetWinCheck && player.SetLoses == updateSetLoseCheck)
                    {
                        continue;
                    }

                    player.LastUpdated  = tournament.completed_at;
                    current.LastUpdated = tournament.completed_at;
                    player.LastUpdated  = player.LastUpdated.Value.AddMinutes(1);
                    current.LastUpdated = player.LastUpdated.Value.AddMinutes(1);

                    _context.SaveChanges();
                }
            }

            foreach (var player in _context.Players)
            {
                var power = Convert.ToInt32(CalculatePowerRank(player.SetWins, player.SetLoses,
                                                               player.MatchWins, player.MatchLoses));

                player.PowerRank  = power;
                player.PowerRank += player.Bonus;
                player.Bonus      = 0;
            }

            foreach (var player in _context.CurrentPlayers)
            {
                var power = Convert.ToInt32(CalculatePowerRank(player.SetWins, player.SetLoses,
                                                               player.MatchWins, player.MatchLoses));

                player.PowerRank  = power;
                player.PowerRank += player.Bonus;
                player.Bonus      = 0;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }