Ejemplo n.º 1
0
        public ActionResult Stats(BamStatsVM vm)
        {
            if (ModelState.IsValid)
            {
                BamStatsVM stats = TempData["Info"] as BamStatsVM;

                int  winner;
                int  loser;
                bool stance;
                if (vm.Winner == 0)
                {
                    winner = stats.Defender.Id;
                    loser  = stats.Attacker.Id;
                    stance = false;
                }
                else
                {
                    winner = stats.Attacker.Id;
                    loser  = stats.Defender.Id;
                    stance = true;
                }

                BamFight fight = new BamFight()
                {
                    Winner    = winner,
                    Loser     = loser,
                    Stance    = stance,
                    FightDate = DateTime.Now.AddHours(-5)
                };

                db.BamFights.Add(fight);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
Ejemplo n.º 2
0
        public ActionResult Stats(int def, int att)
        {
            /*
             * Defence Wins vs Att %
             * Attack Wins vs Def %
             * Defence Wins vs Att in D stance %
             * Attack Wins vs Def in A stance %
             *
             * Defence Total Win/Loss %
             * Attack Total Win/Loss %
             * Defence Total Win/Loss in D stance %
             * Attack Total Win/Loss in A stance %
             *
             * Defence Total Games Recorded
             * Attack Total Games Recorded
             */

            BamName defender = (from bam in db.BamNames where bam.Id == def select bam).FirstOrDefault();
            BamName attacker = (from bam in db.BamNames where bam.Id == att select bam).FirstOrDefault();

            int dWinsCurrent = (from fight in db.BamFights where fight.Winner == def && fight.Loser == att select fight).Count();
            int aWinsCurrent = (from fight in db.BamFights where fight.Winner == att && fight.Loser == def select fight).Count();

            int gamesTogether = dWinsCurrent + aWinsCurrent;

            int dWinRateCurrent = (int)Math.Round(((double)dWinsCurrent / gamesTogether) * 100);
            int aWinRateCurrent = (int)Math.Round(((double)aWinsCurrent / gamesTogether) * 100);

            int dWinsInStanceCurrent = (from fight in db.BamFights where fight.Winner == def && fight.Loser == att && fight.Stance == false select fight).Count();
            int aWinsInStanceCurrent = (from fight in db.BamFights where fight.Winner == att && fight.Loser == def && fight.Stance == true select fight).Count();

            int gamesTogetherInStance = dWinsInStanceCurrent + aWinsInStanceCurrent;

            int dWinRateStanceCurrent = 0;
            int aWinRateStanceCurrent = 0;

            if (gamesTogetherInStance > 0)
            {
                dWinRateStanceCurrent = (int)Math.Round(((double)dWinsInStanceCurrent / gamesTogetherInStance) * 100);
                aWinRateStanceCurrent = (int)Math.Round(((double)aWinsInStanceCurrent / gamesTogetherInStance) * 100);
            }

            int dWinsOverall = (from fight in db.BamFights where fight.Winner == def select fight).Count();
            int aWinsOverall = (from fight in db.BamFights where fight.Winner == att select fight).Count();

            int dLossesOverall = (from fight in db.BamFights where fight.Loser == def select fight).Count();
            int aLossesOverall = (from fight in db.BamFights where fight.Loser == att select fight).Count();

            int dGameCountOverall = dWinsOverall + dLossesOverall;
            int aGameCountOverall = aWinsOverall + aLossesOverall;

            int dWinRateOverall = (int)Math.Round(((double)dWinsOverall / dGameCountOverall) * 100);
            int aWinRateOverall = (int)Math.Round(((double)aWinsOverall / aGameCountOverall) * 100);

            int dWinsInStanceOverall = (from fight in db.BamFights where fight.Winner == def && fight.Stance == false select fight).Count();
            int aWinsInStanceOverall = (from fight in db.BamFights where fight.Winner == att && fight.Stance == true select fight).Count();

            int dLossesInStanceOverall = (from fight in db.BamFights where fight.Loser == def && fight.Stance == false select fight).Count();
            int aLossesInStanceOverall = (from fight in db.BamFights where fight.Loser == att && fight.Stance == true select fight).Count();

            int dWinRateInStanceOverall = (int)Math.Round(((double)dWinsInStanceOverall / (dWinsInStanceOverall + dLossesInStanceOverall)) * 100);
            int aWinRateInStanceOverall = (int)Math.Round(((double)aWinsInStanceOverall / (aWinsInStanceOverall + aLossesInStanceOverall)) * 100);

            int dGamesRecordedOverall = (from fight in db.BamFights where fight.Winner == def || fight.Loser == def select fight).Count();
            int aGamesRecordedOverall = (from fight in db.BamFights where fight.Winner == att || fight.Loser == att select fight).Count();

            BamStatsVM vm = new BamStatsVM
            {
                Defender                = defender,
                Attacker                = attacker,
                DWinsCurrent            = dWinsCurrent,
                AWinsCurrent            = aWinsCurrent,
                DWinRateCurrent         = dWinRateCurrent,
                AWinRateCurrent         = aWinRateCurrent,
                DWinsInStanceCurrent    = dWinsInStanceCurrent,
                AWinsInStanceCurrent    = aWinsInStanceCurrent,
                DWinRateStanceCurrent   = dWinRateStanceCurrent,
                AWinRateStanceCurrent   = aWinRateStanceCurrent,
                DWinsOverall            = dWinsOverall,
                AWinsOverall            = aWinsOverall,
                DLossesOverall          = dLossesOverall,
                ALossesOverall          = aLossesOverall,
                DWinRateOverall         = dWinRateOverall,
                AWinRateOverall         = aWinRateOverall,
                DWinsInStanceOverall    = dWinsInStanceOverall,
                AWinsInStanceOverall    = aWinsInStanceOverall,
                DLossesInStanceOverall  = dLossesInStanceOverall,
                ALossesInStanceOverall  = aLossesInStanceOverall,
                DWinRateInStanceOverall = dWinRateInStanceOverall,
                AWinRateInStanceOverall = aWinRateInStanceOverall,
                DGamesRecordedOverall   = dGamesRecordedOverall,
                AGamesRecordedOverall   = aGamesRecordedOverall
            };

            TempData["Info"] = vm;
            return(View(vm));
        }