Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CorrectPicks")] BracketModel bracketModel)
        {
            if (id != bracketModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bracketModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BracketModelExists(bracketModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bracketModel));
        }
Beispiel #2
0
        /// <summary>
        /// Adds a user to the tournament of the first bracket.
        /// </summary>
        /// <param name="model">The user model to be added to the tournament</param>
        /// <returns>True if saved; false if save failed</returns>
        private bool AddUserToTournament(TournamentUserModel model)
        {
            // Add the user to the tournament
            services.Tournament.AddTournamentUser(model);

            if (model.PermissionLevel == (int)Permission.TOURNAMENT_STANDARD)
            {
                // Add user to the beginning bracket
                BracketModel bracket  = Model.Brackets.ElementAt(0);
                int?         seedData = bracket.TournamentUsersBrackets.Max(x => x.Seed);
                int          seed     = seedData != null ? seedData.Value + 1 : 1;

                TournamentUsersBracketModel bracketUser = new TournamentUsersBracketModel()
                {
                    TournamentID     = Model.TournamentID,
                    TournamentUserID = model.TournamentUserID,
                    Seed             = seed,
                    BracketID        = bracket.BracketID
                };

                services.Tournament.AddTournamentUsersBracket(bracketUser);
            }

            return(services.Save());
        }
Beispiel #3
0
        /// <summary>
        /// Sets this Bracket's main data from a related BracketModel.
        /// Data affected includes most fields, as well as the playerlist.
        /// </summary>
        /// <remarks>
        /// This is overriden in Group Stages for additional functionality.
        /// </remarks>
        /// <param name="_model">Related BracketModel</param>
        protected virtual void SetDataFromModel(BracketModel _model)
        {
            if (null == _model)
            {
                throw new ArgumentNullException("_model");
            }

            this.Id               = _model.BracketID;
            this.BracketType      = _model.BracketType.Type;
            this.IsFinalized      = _model.Finalized;
            this.AdvancingPlayers = _model.NumberPlayersAdvance;
            this.MaxRounds        = _model.MaxRounds;
            this.MatchWinValue    = 2;
            this.MatchTieValue    = 1;

            // Convert TournamentUserBracketModels into Players,
            // and add them to the Bracket's playerlist:
            List <TournamentUserModel> userModels = _model.TournamentUsersBrackets
                                                    .OrderBy(u => u.Seed, new SeedComparer())
                                                    .Select(u => u.TournamentUser)
                                                    .ToList();

            this.Players = new List <IPlayer>();
            foreach (TournamentUserModel userModel in userModels)
            {
                Players.Add(new Player(userModel));
            }

            ResetBracketData();
        }
        public StepladderBracket(BracketModel _model)
        {
            // Call a helper method to copy the bracket status fields,
            // and to load the playerlist:
            SetDataFromModel(_model);

            if (_model.Matches.Count > 0)
            {
                foreach (MatchModel mm in _model.Matches)
                {
                    // Create Matches from all MatchModels:
                    Matches.Add(mm.MatchNumber, new Match(mm));
                }
                this.NumberOfMatches = Matches.Count;
                this.NumberOfRounds  = Matches.Count;
            }

            RecalculateRankings();

            if (this.IsFinalized && false == Validate())
            {
                throw new BracketValidationException
                          ("Bracket is Finalized but not Valid!");
            }
        }
        /// <summary>
        /// Creates a Model of this Bracket's current state.
        /// Any contained objects (Players, Matches) are also converted into Models.
        /// </summary>
        /// <param name="_tournamentID">ID of containing Tournament</param>
        /// <returns>Matching BracketModel</returns>
        public override BracketModel GetModel(int _tournamentID)
        {
            BracketModel model = base.GetModel(_tournamentID);

            model.NumberOfGroups = this.NumberOfGroups;

            return(model);
        }
Beispiel #6
0
 public Bracket(IService services, IBracket bracket, BracketModel model)
 {
     this.services     = services;
     this.bracket      = bracket;
     this.model        = model;
     this.groupBracket = bracket as IGroupStage;
     IsLocked          = model.IsLocked;
     Init();
 }
Beispiel #7
0
        public void TestSetup()
        {
            db      = new DatabaseInterface();
            bracket = db.GetBracketByID(1);
            match   = new MatchModel();
            match   = db.GetMatchById(1);

            numGames = 3;
        }
Beispiel #8
0
 static void PrintBracket(DatabaseInterface db, BracketModel bracket)
 {
     Console.WriteLine("Title: " + bracket.BracketTitle);
     Console.WriteLine("Bracket Type: " + bracket.BracketType.Type.ToString());
     foreach (var match in bracket.Matches)
     {
         Console.WriteLine("Match number: " + match.MatchNumber);
         Console.WriteLine("Challenger: " + match.Challenger.FirstName + ' ' + match.Challenger.LastName);
         Console.WriteLine("Defender: " + match.Defender.FirstName + ' ' + match.Defender.LastName);
     }
 }
        public void Update_Bracket_No_Cascade()
        {
            var db = new DatabaseRepository("VictoriousEntities");

            BracketModel bracket = db.GetBracket(3);

            //bracket.BracketTitle = "new title";

            var result = db.UpdateBracket(bracket);

            Assert.AreEqual(DbError.SUCCESS, result);
        }
        public DoubleElimBracket(BracketModel _model)
            : base(_model)
        {
            this.NumberOfLowerRounds = 0;
            if (_model.Matches.Count > 0)
            {
                if (CalculateTotalLowerBracketMatches(Players.Count) > 0)
                {
                    int numOfGrandFinal = _model.Matches.Count;

                    // Create Matches from MatchModels.
                    // This is extending SEB's method, so all upper bracket Matches are already done.
                    foreach (MatchModel mm in _model.Matches.OrderBy(m => m.MatchNumber))
                    {
                        if (Matches.ContainsKey(mm.MatchNumber))
                        {
                            // Case 1: match is upper bracket:
                            continue;
                        }
                        if (mm.MatchNumber == numOfGrandFinal)
                        {
                            // Case 2: match is grand final:
                            this.grandFinal = new Match(mm);
                        }
                        else
                        {
                            // Case 3: match is lower bracket:
                            Match match = new Match(mm);
                            LowerMatches.Add(match.MatchNumber, match);
                            this.NumberOfLowerRounds = Math.Max(NumberOfLowerRounds, match.RoundIndex);
                        }
                    }
                }
                this.NumberOfMatches = Matches.Count + LowerMatches.Count;
                if (null != grandFinal)
                {
                    ++NumberOfMatches;
                }
            }

            RecalculateRankings();
            if (grandFinal?.IsFinished ?? false)
            {
                this.IsFinished = true;
            }

            if (this.IsFinalized && false == Validate())
            {
                throw new BracketValidationException
                          ("Bracket is Finalized but not Valid!");
            }
        }
        /// <summary>
        /// (Re)creates a Bracket object from the given BracketModel.
        /// Determines the BracketType from the Model's data,
        /// and calls the appropriate constructor.
        /// If the type is not identifiable, an exception is thrown.
        /// </summary>
        /// <param name="_model">Model of an existing Bracket</param>
        /// <returns>Recreated Bracket</returns>
        public IBracket RestoreBracket(BracketModel _model)
        {
            if (null == _model)
            {
                throw new ArgumentNullException("_model");
            }

            IBracket ret = null;

            switch (_model.BracketType.Type)
            {
            case (BracketType.SINGLE):
                ret = new SingleElimBracket(_model);
                break;

            case (BracketType.DOUBLE):
                ret = new DoubleElimBracket(_model);
                break;

            case (BracketType.STEP):
                ret = new StepladderBracket(_model);
                break;

            case (BracketType.ROUNDROBIN):
                ret = new RoundRobinBracket(_model);
                break;

            case (BracketType.SWISS):
                ret = new SwissBracket(_model);
                break;

            case (BracketType.RRGROUP):
                ret = new RoundRobinGroups(_model);
                break;

            case (BracketType.GSLGROUP):
                throw new NotImplementedException();

            //ret = new GSLGroups(_model);
            //break;
            default:
                throw new NotImplementedException();
            }
            if (0 == ret.NumberOfMatches)
            {
                // If the Model has no Matches,
                // use the data we have to generate them:
                ret.CreateBracket();
            }

            return(ret);
        }
Beispiel #12
0
        public async Task <IActionResult> Create([Bind("Id,Name")] BracketModel bracketModel)
        {
            bracketModel.Games        = new List <GameModel>(63);
            bracketModel.CorrectPicks = 0;
            if (ModelState.IsValid)
            {
                _context.Add(bracketModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Pick", "Bracket", new { bracketId = bracketModel.Id, bracketPosition = 0 }));
            }
            return(View(bracketModel));
        }
Beispiel #13
0
        public void RRGGetModel_HasModelsOfAllPlayers()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 17; ++i)
            {
                IPlayer p = new Player(i + 1, "Player " + (i + 1).ToString());
                pList.Add(p);
            }
            IBracket b = new RoundRobinGroups(pList, 4);

            BracketModel bModel = b.GetModel(0);

            Assert.AreEqual(pList.Count, bModel.TournamentUsersBrackets.Count);
        }
Beispiel #14
0
        public void RRGGetModel_HasModelsOfAllMatches()
        {
            List <IPlayer> pList = new List <IPlayer>();

            for (int i = 0; i < 17; ++i)
            {
                IPlayer p = new Player(i + 1, "Player " + (i + 1).ToString());
                pList.Add(p);
            }
            IBracket b = new RoundRobinGroups(pList, 4);

            BracketModel bModel = b.GetModel(0);

            Assert.AreEqual(b.NumberOfMatches, bModel.Matches.Count);
        }
        public void AddBracket_Save()
        {
            var bracket = new BracketModel()
            {
                //BracketTitle = "Bracket",
                BracketTypeID  = 2,
                Finalized      = true,
                TournamentID   = service.GetAllTournaments()[0].TournamentID,
                NumberOfGroups = 2
            };

            service.AddBracket(bracket);
            var result = unitOfWork.Save();

            Assert.AreEqual(true, result);
        }
Beispiel #16
0
        /// <summary>
        /// Sets this Bracket's main data from a related BracketModel.
        /// Data affected includes most fields, as well as the playerlist.
        /// </summary>
        /// <param name="_model">Related BracketModel</param>
        protected override void SetDataFromModel(BracketModel _model)
        {
            // Call the base (Bracket) method to set common data and playerlist:
            base.SetDataFromModel(_model);
            this.NumberOfGroups = _model.NumberOfGroups;

            if (_model.Matches.Count > 0)
            {
                foreach (MatchModel matchModel in _model.Matches)
                {
                    // Convert each MatchModel to a Match, and add:
                    Matches.Add(matchModel.MatchNumber, new Match(matchModel));
                }

                this.NumberOfMatches = Matches.Count;
                this.NumberOfRounds  = Matches.Values
                                       .Max(m => m.RoundIndex);
                this.IsFinished = Matches.Values
                                  .All(m => m.IsFinished);
            }

            // "Recreate" the groups:
            List <List <IPlayer> > playerGroups = DividePlayersIntoGroups();

            for (int g = 0; g < playerGroups.Count; ++g)
            {
                // Use these groups to remake the GroupRankings:
                GroupRankings.Add(new List <IPlayerScore>());
                foreach (IPlayer player in playerGroups[g])
                {
                    // Make a new ranking object for each Player,
                    // and add it to Rankings and GroupRankings:
                    IPlayerScore pScore = new PlayerScore(player.Id, player.Name);
                    Rankings.Add(pScore);
                    GroupRankings[g].Add(pScore);
                }
            }

            // Go through the Matches to recalculate the current Rankings:
            RecalculateRankings();

            if (this.IsFinalized && false == Validate())
            {
                throw new BracketValidationException
                          ("Bracket is Finalized but not Valid!");
            }
        }
Beispiel #17
0
        /// <summary>
        /// This will finalize a bracket.
        /// </summary>
        /// <param name="bracketId">The ID of the bracket</param>
        /// <param name="roundData">The data that will be used to set the max amount of games.</param>
        /// <returns>True if the bracket was finalized or false if failed to save</returns>
        public bool FinalizeBracket(int bracketId, Dictionary <String, Dictionary <String, int> > roundData)
        {
            // Set variables
            BracketModel bracketModel = Model.Brackets.Single(x => x.BracketID == bracketId);

            Tournaments.IBracket bracket = Tourny.Brackets.Single(x => x.Id == bracketId);

            // Set max games for every round
            foreach (KeyValuePair <String, Dictionary <String, int> > roundInfo in roundData)
            {
                foreach (KeyValuePair <String, int> data in roundInfo.Value)
                {
                    switch (roundInfo.Key)
                    {
                    case "upper":
                        bracket.SetMaxGamesForWholeRound(int.Parse(data.Key), data.Value);
                        break;

                    case "lower":
                        bracket.SetMaxGamesForWholeLowerRound(int.Parse(data.Key), data.Value);
                        break;

                    case "final":
                        bracket.SetMaxGamesForWholeRound(int.Parse(data.Key), data.Value);
                        break;
                    }
                }
            }

            if (bracket.Validate())
            {
                // Update the necesarry information
                bracketModel.Finalized = true;
                Model.InProgress       = true;

                // Update the database
                bracketModel.Matches = bracket.GetModel(Model.TournamentID).Matches;
                services.Tournament.UpdateBracket(bracketModel);
                services.Tournament.UpdateTournament(Model);
                return(services.Save());
            }
            else
            {
                return(false);
            }
        }
        public void Add_Bracket()
        {
            var db = new DatabaseRepository("VictoriousEntities");

            var bracket = new BracketModel()
            {
                //BracketTitle = "Bracket",
                BracketTypeID  = 2,
                Finalized      = true,
                TournamentID   = db.GetAllTournaments()[0].TournamentID,
                NumberOfGroups = 2
            };

            var result = db.AddBracket(bracket);

            Assert.AreEqual(DbError.SUCCESS, result);
        }
Beispiel #19
0
        public void UpdateBrackets()
        {
            int updates = Math.Max(viewModel.BracketData.Count, Model.Brackets.Count);
            List <BracketModel> updatedBrackets = new List <BracketModel>();

            for (int i = 0; i < updates; i++)
            {
                BracketViewModel newBracket   = viewModel.BracketData.ElementAtOrDefault(i);
                BracketModel     bracketModel = Model.Brackets.ElementAtOrDefault(i);
                //List<TournamentUsersBracketModel> users = new List<TournamentUsersBracketModel>();

                if (newBracket != null)
                {
                    if (bracketModel != null)
                    {
                        // We just need to update the data
                        bracketModel.BracketTypeID        = newBracket.BracketTypeID;
                        bracketModel.MaxRounds            = newBracket.NumberOfRounds;
                        bracketModel.NumberOfGroups       = newBracket.NumberOfGroups;
                        bracketModel.NumberPlayersAdvance = newBracket.NumberPlayersAdvance;

                        updatedBrackets.Add(bracketModel);
                        //services.Tournament.UpdateBracket(bracketModel);
                    }
                    else if (bracketModel == null)
                    {
                        // We need to add this bracket
                        bracketModel = new BracketModel()
                        {
                            MaxRounds            = newBracket.NumberOfRounds,
                            BracketTypeID        = newBracket.BracketTypeID,
                            NumberOfGroups       = newBracket.NumberOfGroups,
                            NumberPlayersAdvance = newBracket.NumberPlayersAdvance,
                            Finalized            = false,
                            TournamentID         = Model.TournamentID
                        };

                        updatedBrackets.Add(bracketModel);
                        //services.Tournament.AddBracket(bracketModel);
                    }
                }
            }

            Model.Brackets = updatedBrackets;
        }
        public SingleElimBracket(BracketModel _model)
        {
            // Call a helper method to copy the bracket status fields,
            // and to load the playerlist:
            SetDataFromModel(_model);

            /*
             * Since this method is extended in child classes,
             * we may be loading a lower bracket.
             * We need to add a couple checks here to make sure
             * we don't accidentally load lower bracket Matches
             * into our upper bracket.
             */
            int totalUBMatches = Players.Count - 1;

            if (_model.Matches.Count > 0)
            {
                foreach (MatchModel mm in _model.Matches.OrderBy(m => m.MatchNumber))
                {
                    if (mm.MatchNumber <= totalUBMatches)
                    {
                        Matches.Add(mm.MatchNumber, new Match(mm));
                    }
                    else
                    {
                        // Match doesn't belong in upper bracket, so we're done:
                        break;
                    }
                }
                this.NumberOfMatches = Matches.Count;
                this.NumberOfRounds  = Matches.Values
                                       .Max(m => m.RoundIndex);
            }

            if (BracketType.SINGLE == BracketType)
            {
                RecalculateRankings();

                if (this.IsFinalized && false == Validate())
                {
                    throw new BracketValidationException
                              ("Bracket is Finalized but not Valid!");
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Will progress the tournament and add new players to the net bracket
        /// </summary>
        /// <param name="bracketId">ID of the bracket</param>
        /// <param name="isLocked">Lock or unlock the bracket</param>
        /// <returns>True if saved; false if not saved</returns>
        public bool LockBracket(int bracketId, bool isLocked)
        {
            Tournaments.IBracket currentBracket = Tourny.Brackets.Single(x => x.Id == bracketId);
            Tournaments.IBracket nextBracket    = Tourny.Brackets.ElementAtOrDefault(Tourny.Brackets.FindIndex(x => x == currentBracket) + 1);

            // Make changes to the current bracket
            if (currentBracket != null)
            {
                BracketModel model = Model.Brackets.Single(x => x.BracketID == bracketId);
                model.IsLocked = isLocked;

                services.Tournament.UpdateBracket(model);
            }

            if (nextBracket != null)
            {
                BracketModel nextBracketModel = Model.Brackets.Single(x => x.BracketID == nextBracket.Id);

                List <TournamentUsersBracketModel> usersToProceed = new List <TournamentUsersBracketModel>();
                Tourny.AdvancePlayersByRanking(currentBracket, nextBracket);

                //nextBracketModel.TournamentUsersBrackets = nextBracket.GetModel(Model.TournamentID).TournamentUsersBrackets;

                foreach (Tournaments.IPlayer player in nextBracket.Players)
                {
                    TournamentUsersBracketModel user = new TournamentUsersBracketModel()
                    {
                        BracketID        = nextBracket.Id,
                        TournamentID     = Model.TournamentID,
                        TournamentUserID = player.Id,
                        Seed             = nextBracket.GetPlayerSeed(player.Id)
                    };

                    usersToProceed.Add(user);
                }

                nextBracketModel.TournamentUsersBrackets = usersToProceed;
                services.Tournament.UpdateBracket(nextBracketModel);
            }

            return(services.Save());
        }
Beispiel #22
0
        /// <summary>
        /// Creates a Model of this Bracket's current state.
        /// Any contained objects (Players, Matches) are also converted into Models.
        /// </summary>
        /// <remarks>
        /// This method is overriden in Group Stages.
        /// </remarks>
        /// <param name="_tournamentID">ID of containing Tournament</param>
        /// <returns>Matching BracketModel</returns>
        public virtual BracketModel GetModel(int _tournamentID)
        {
            BracketModel model = new BracketModel();

            model.TournamentID         = _tournamentID;
            model.BracketID            = this.Id;
            model.BracketTypeID        = Convert.ToInt32(this.BracketType);
            model.Finalized            = this.IsFinalized;
            model.NumberOfGroups       = 0;
            model.MaxRounds            = this.MaxRounds;
            model.NumberPlayersAdvance = this.AdvancingPlayers;

            // Convert the BracketType to relevant model, and add it:
            model.BracketType = new BracketTypeModel();
            model.BracketType.BracketTypeID = model.BracketTypeID;
            model.BracketType.Type          = this.BracketType;
            model.BracketType.TypeName      = this.BracketType.ToString("f");

            // Convert all Players to Models, and add them:
            //model.TournamentUsersBrackets = new List<TournamentUsersBracketModel>();
            foreach (IPlayer player in Players)
            {
                TournamentUsersBracketModel m = player.GetTournamentUsersBracketModel(this.Id, GetPlayerSeed(player.Id), _tournamentID);
                model.TournamentUsersBrackets.Add(m);
            }

            // Convert all Matches to Models, and add them:
            //model.Matches = new List<MatchModel>();
            //if (!(this is IGroupStage))
            //{
            for (int n = 1; n <= NumberOfMatches; ++n)
            {
                model.Matches.Add(GetMatchModel(n));
            }
            //}

            return(model);
        }
Beispiel #23
0
        public RoundRobinBracket(BracketModel _model)
        {
            // Call a helper method to copy the bracket status fields,
            // and to load the playerlist:
            SetDataFromModel(_model);

            foreach (IPlayer player in Players)
            {
                // Create an initial ranking for every Player:
                Rankings.Add(new PlayerScore(player.Id, player.Name));
            }

            foreach (MatchModel mm in _model.Matches)
            {
                // Create Matches from all MatchModels:
                Matches.Add(mm.MatchNumber, new Match(mm));
            }
            this.NumberOfMatches = Matches.Count;
            this.NumberOfRounds  = 0;

            this.IsFinished = false;
            if (NumberOfMatches > 0)
            {
                this.NumberOfRounds = Matches.Values
                                      .Max(m => m.RoundIndex);
                this.IsFinished = Matches.Values.All(m => m.IsFinished);
            }

            RecalculateRankings();

            if (this.IsFinalized && false == Validate())
            {
                throw new BracketValidationException
                          ("Bracket is Finalized but not Valid!");
            }
        }
Beispiel #24
0
 public RoundRobinGroups(BracketModel _model)
 {
     SetDataFromModel(_model);
 }
Beispiel #25
0
        public void TestParser()
        {
            //Make a list of income year models to test
            ObservableCollection <IncomeYearModel> testModels = new ObservableCollection <IncomeYearModel>();

            string[] filePaths = Directory.GetFiles("res\\TaxCSV", "*.csv");

            //Testing 2003.csv
            testModels.Add(Parser.ParseCSV(filePaths[0]));

            ObservableCollection <IncomeYearModel> answers = new ObservableCollection <IncomeYearModel>();
            IncomeYearModel ans1 = new IncomeYearModel();

            ans1.Year = 2003;
            ObservableCollection <BracketModel> brackets1 = new ObservableCollection <BracketModel>();
            BracketModel b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19;

            b1  = new BracketModel();
            b2  = new BracketModel();
            b3  = new BracketModel();
            b4  = new BracketModel();
            b5  = new BracketModel();
            b6  = new BracketModel();
            b7  = new BracketModel();
            b8  = new BracketModel();
            b9  = new BracketModel();
            b10 = new BracketModel();
            b11 = new BracketModel();
            b12 = new BracketModel();
            b13 = new BracketModel();
            b14 = new BracketModel();
            b15 = new BracketModel();
            b16 = new BracketModel();
            b17 = new BracketModel();
            b18 = new BracketModel();
            b19 = new BracketModel();

            //Manually copying the data into the brackets:
            b1.LowerBound    = 0;
            b1.UpperBound    = 0;
            b1.NumReturns    = 4522;
            b1.GrossIncome   = -5094991;
            b1.TaxableIncome = 0;
            b1.IncomeTax     = 78488;
            b1.PercentOfTaxableIncomePaid = 0;
            b1.PercentOfGrossIncomePaid   = 0;
            b1.AverageTotalIncomeTax      = 17377;

            b2.LowerBound    = 1;
            b2.UpperBound    = 4999;
            b2.NumReturns    = 835921;
            b2.GrossIncome   = 2494290;
            b2.TaxableIncome = 610224;
            b2.IncomeTax     = 72959;
            b2.PercentOfTaxableIncomePaid = 11.96;
            b2.PercentOfGrossIncomePaid   = 2.9;
            b2.AverageTotalIncomeTax      = 87.27977883;

            b3.LowerBound    = 5000;
            b3.UpperBound    = 9999;
            b3.NumReturns    = 4116242;
            b3.GrossIncome   = 31995563;
            b3.TaxableIncome = 7956944;
            b3.IncomeTax     = 780450;
            b3.PercentOfTaxableIncomePaid = 9.81;
            b3.PercentOfGrossIncomePaid   = 2.4;
            b3.AverageTotalIncomeTax      = 189.602555;

            b4.LowerBound    = 10000;
            b4.UpperBound    = 14999;
            b4.NumReturns    = 6042925;
            b4.GrossIncome   = 75393048;
            b4.TaxableIncome = 28261843;
            b4.IncomeTax     = 2750658;
            b4.PercentOfTaxableIncomePaid = 9.73;
            b4.PercentOfGrossIncomePaid   = 3.6;
            b4.AverageTotalIncomeTax      = 455.1865198;

            b5.LowerBound    = 15000;
            b5.UpperBound    = 19999;
            b5.NumReturns    = 6304104;
            b5.GrossIncome   = 110625567;
            b5.TaxableIncome = 50371975;
            b5.IncomeTax     = 5404734;
            b5.PercentOfTaxableIncomePaid = 10.73;
            b5.PercentOfGrossIncomePaid   = 4.9;
            b5.AverageTotalIncomeTax      = 857.3357927;

            b6.LowerBound    = 20000;
            b6.UpperBound    = 24999;
            b6.NumReturns    = 6095228;
            b6.GrossIncome   = 137029808;
            b6.TaxableIncome = 72410263;
            b6.IncomeTax     = 8274086;
            b6.PercentOfTaxableIncomePaid = 11.4;
            b6.PercentOfGrossIncomePaid   = 6;
            b6.AverageTotalIncomeTax      = 1357;

            b7.LowerBound    = 25000;
            b7.UpperBound    = 29999;
            b7.NumReturns    = 6092090;
            b7.GrossIncome   = 167694124;
            b7.TaxableIncome = 97429358;
            b7.IncomeTax     = 11036040;
            b7.PercentOfTaxableIncomePaid = 11.3;
            b7.PercentOfGrossIncomePaid   = 6.6;
            b7.AverageTotalIncomeTax      = 1812;

            b8.LowerBound    = 30000;
            b8.UpperBound    = 39999;
            b8.NumReturns    = 11856081;
            b8.GrossIncome   = 413146253;
            b8.TaxableIncome = 254354428;
            b8.IncomeTax     = 29737818;
            b8.PercentOfTaxableIncomePaid = 11.7;
            b8.PercentOfGrossIncomePaid   = 7.2;
            b8.AverageTotalIncomeTax      = 2508;

            b9.LowerBound    = 40000;
            b9.UpperBound    = 49999;
            b9.NumReturns    = 9668366;
            b9.GrossIncome   = 432975517;
            b9.TaxableIncome = 276796514;
            b9.IncomeTax     = 34634209;
            b9.PercentOfTaxableIncomePaid = 12.5;
            b9.PercentOfGrossIncomePaid   = 8;
            b9.AverageTotalIncomeTax      = 3582;

            b10.LowerBound    = 50000;
            b10.UpperBound    = 74999;
            b10.NumReturns    = 17024921;
            b10.GrossIncome   = 1045511568;
            b10.TaxableIncome = 702291485;
            b10.IncomeTax     = 94256193;
            b10.PercentOfTaxableIncomePaid = 13.4;
            b10.PercentOfGrossIncomePaid   = 9;
            b10.AverageTotalIncomeTax      = 5536;

            b11.LowerBound    = 75000;
            b11.UpperBound    = 99999;
            b11.NumReturns    = 9486123;
            b11.GrossIncome   = 816206695;
            b11.TaxableIncome = 575890228;
            b11.IncomeTax     = 84253116;
            b11.PercentOfTaxableIncomePaid = 14.6;
            b11.PercentOfGrossIncomePaid   = 10.3;
            b11.AverageTotalIncomeTax      = 8882;

            b12.LowerBound    = 100000;
            b12.UpperBound    = 199999;
            b12.NumReturns    = 8861764;
            b12.GrossIncome   = 1167988946;
            b12.TaxableIncome = 875512626;
            b12.IncomeTax     = 163342405;
            b12.PercentOfTaxableIncomePaid = 18.7;
            b12.PercentOfGrossIncomePaid   = 14;
            b12.AverageTotalIncomeTax      = 18432;

            b13.LowerBound    = 200000;
            b13.UpperBound    = 499999;
            b13.NumReturns    = 1996787;
            b13.GrossIncome   = 575673389;
            b13.TaxableIncome = 482717655;
            b13.IncomeTax     = 120710917;
            b13.PercentOfTaxableIncomePaid = 25;
            b13.PercentOfGrossIncomePaid   = 21;
            b13.AverageTotalIncomeTax      = 60453;

            b14.LowerBound    = 500000;
            b14.UpperBound    = 999999;
            b14.NumReturns    = 355750;
            b14.GrossIncome   = 240943755;
            b14.TaxableIncome = 212761707;
            b14.IncomeTax     = 60180621;
            b14.PercentOfTaxableIncomePaid = 28.3;
            b14.PercentOfGrossIncomePaid   = 25;
            b14.AverageTotalIncomeTax      = 169166;

            b15.LowerBound    = 1000000;
            b15.UpperBound    = 1499999;
            b15.NumReturns    = 81588;
            b15.GrossIncome   = 98744564;
            b15.TaxableIncome = 88335720;
            b15.IncomeTax     = 25550669;
            b15.PercentOfTaxableIncomePaid = 28.9;
            b15.PercentOfGrossIncomePaid   = 25.9;
            b15.AverageTotalIncomeTax      = 313177;

            b16.LowerBound    = 1500000;
            b16.UpperBound    = 1999999;
            b16.NumReturns    = 33984;
            b16.GrossIncome   = 58440100;
            b16.TaxableIncome = 52488902;
            b16.IncomeTax     = 15315946;
            b16.PercentOfTaxableIncomePaid = 29.2;
            b16.PercentOfGrossIncomePaid   = 26.2;
            b16.AverageTotalIncomeTax      = 450683;

            b17.LowerBound    = 2000000;
            b17.UpperBound    = 4999999;
            b17.NumReturns    = 48235;
            b17.GrossIncome   = 142091816;
            b17.TaxableIncome = 128190317;
            b17.IncomeTax     = 36900818;
            b17.PercentOfTaxableIncomePaid = 28.8;
            b17.PercentOfGrossIncomePaid   = 26;
            b17.AverageTotalIncomeTax      = 765117;

            b18.LowerBound    = 5000000;
            b18.UpperBound    = 9999999;
            b18.NumReturns    = 11160;
            b18.GrossIncome   = 76253821;
            b18.TaxableIncome = 68499870;
            b18.IncomeTax     = 19313626;
            b18.PercentOfTaxableIncomePaid = 28.2;
            b18.PercentOfGrossIncomePaid   = 25.3;
            b18.AverageTotalIncomeTax      = 1730613;

            b19.LowerBound    = 10000000;
            b19.UpperBound    = 999999999;
            b19.NumReturns    = 6114;
            b19.GrossIncome   = 158454920;
            b19.TaxableIncome = 140179919;
            b19.IncomeTax     = 35416375;
            b19.PercentOfTaxableIncomePaid = 25.3;
            b19.PercentOfGrossIncomePaid   = 22.4;
            b19.AverageTotalIncomeTax      = 5792690;

            //Add brackets to list
            brackets1.Add(b1);
            brackets1.Add(b2);
            brackets1.Add(b3);
            brackets1.Add(b4);
            brackets1.Add(b5);
            brackets1.Add(b6);
            brackets1.Add(b7);
            brackets1.Add(b8);
            brackets1.Add(b9);
            brackets1.Add(b10);
            brackets1.Add(b11);
            brackets1.Add(b12);
            brackets1.Add(b13);
            brackets1.Add(b14);
            brackets1.Add(b15);
            brackets1.Add(b16);
            brackets1.Add(b17);
            brackets1.Add(b18);
            brackets1.Add(b19);

            //Add brackets to answer
            ans1.Brackets = brackets1;
            answers.Add(ans1);

            //Go through all the tests (Right now there's just 1 for the year 2003)
            for (int i = 0; i < testModels.Count; i++)
            {
                //Check that the years match
                Assert.AreEqual(answers[i].Year, testModels[i].Year);
                //Check that the number of brackets is the same
                Assert.AreEqual(answers[i].Brackets.Count, testModels[i].Brackets.Count);
                //Check that each value is the same
                for (int j = 0; j < testModels[i].Brackets.Count; j++)
                {
                    Assert.AreEqual(answers[i].Brackets[j].LowerBound, testModels[i].Brackets[j].LowerBound);
                    Assert.AreEqual(answers[i].Brackets[j].UpperBound, testModels[i].Brackets[j].UpperBound);
                    Assert.AreEqual(answers[i].Brackets[j].NumReturns, testModels[i].Brackets[j].NumReturns);
                    Assert.AreEqual(answers[i].Brackets[j].GrossIncome, testModels[i].Brackets[j].GrossIncome);
                    Assert.AreEqual(answers[i].Brackets[j].TaxableIncome, testModels[i].Brackets[j].TaxableIncome);
                    Assert.AreEqual(answers[i].Brackets[j].IncomeTax, testModels[i].Brackets[j].IncomeTax);
                    Assert.AreEqual(answers[i].Brackets[j].PercentOfTaxableIncomePaid, testModels[i].Brackets[j].PercentOfTaxableIncomePaid);
                    Assert.AreEqual(answers[i].Brackets[j].PercentOfGrossIncomePaid, testModels[i].Brackets[j].PercentOfGrossIncomePaid);
                    Assert.AreEqual(answers[i].Brackets[j].AverageTotalIncomeTax, testModels[i].Brackets[j].AverageTotalIncomeTax);
                }
            }
        }
Beispiel #26
0
 /// <summary>
 /// Adds a single Bracket to the database.
 /// </summary>
 /// <param name="bracket"> The model of the bracket to be added to the database. </param>
 public void AddBracket(BracketModel bracket)
 {
     unitOfWork.BracketRepo.Add(bracket);
 }
 public void TestSetup()
 {
     db      = new DatabaseInterface();
     bracket = db.GetBracketByID(1);
 }
Beispiel #28
0
        public void UpdateSeeds(Dictionary <String, int> players, int bracketId)
        {
            foreach (KeyValuePair <String, int> player in players)
            {
                TournamentUsersBracketModel user = Model.Brackets.Single(x => x.BracketID == bracketId)
                                                   .TournamentUsersBrackets.SingleOrDefault(z => z.TournamentUserID == int.Parse(player.Key));
                if (user != null)
                {
                    user.Seed = player.Value;
                    services.Tournament.UpdateTournamentUsersBracket(user);
                }
                else
                {
                    user = new TournamentUsersBracketModel()
                    {
                        Seed             = player.Value,
                        TournamentUserID = int.Parse(player.Key),
                        TournamentID     = Model.TournamentID,
                        BracketID        = bracketId
                    };

                    services.Tournament.AddTournamentUsersBracket(user);
                }
            }

            // Pass updated seeds to IBracket, which will fix any invalid values:
            Tourny.Brackets.Single(x => x.Id == bracketId)
            .SetNewPlayerlist(Model.Brackets.Single(x => x.BracketID == bracketId)
                              .TournamentUsersBrackets);

            // Give correct values to all user seeds in the first BracketModel.
            // This prevents two users having the same seed and being randomly sorted.
            BracketModel bracketModel = Model.Brackets.First();

            foreach (TournamentUsersBracketModel userModel in bracketModel.TournamentUsersBrackets)
            {
                int newPlayerSeed = Tourny.Brackets
                                    .Single(b => b.Id == bracketModel.BracketID)
                                    .GetPlayerSeed(userModel.TournamentUserID);

                if (newPlayerSeed != userModel.Seed)
                {
                    userModel.Seed = newPlayerSeed;
                    services.Tournament.UpdateTournamentUsersBracket(userModel);
                }
            }
#if false
            foreach (TournamentTeamBracketModel teamModel in bracketModel.TournamentTeamBrackets)
            {
                int newPlayerSeed = Tourny.Brackets
                                    .Single(b => b.Id == bracketModel.BracketID)
                                    .GetPlayerSeed(teamModel.TournamentTeamID);

                if (newPlayerSeed != teamModel.Seed)
                {
                    teamModel.Seed = newPlayerSeed;
                    services.Tournament.UpdateTournamentTeamsBracket(teamModel);
                }
            }
#endif

            services.Save();
        }
Beispiel #29
0
 /// <summary>
 /// Updates a single Bracket int the database.
 /// </summary>
 /// <param name="bracket"> The model of the Bracket to be updated. </param>
 public void UpdateBracket(BracketModel bracket)
 {
     unitOfWork.BracketRepo.Update(bracket);
 }
        public SwissBracket(BracketModel _model)
            : base(_model)
        {
            /*
             * This constructor extends the parent (round robin) version.
             * By the time we're "here," we already have our main data restored:
             * Players, Matches, and inherited Bracket fields.
             * Now, we need to recreate the Swiss-specific fields:
             * Matchups, PlayerByes, and PairingMethod.
             */

            for (int r = 1; r <= NumberOfRounds; ++r)
            {
                List <IMatch> round = GetRound(r);
                if (round.Any(m => m.Players.Contains(null)))
                {
                    // This round isn't populated yet. Break out:
                    break;
                }

                // playersInRound is a list of all players (by index)
                // in matchups this round. We check for the missing player
                // to know who got a bye.
                List <int> playersInRound = new List <int>();

                foreach (IMatch match in round)
                {
                    // For each populated Match, add a Matchup to the private list:
                    int defIndex  = Players.FindIndex(p => p.Id == match.Players[(int)PlayerSlot.Defender].Id);
                    int chalIndex = Players.FindIndex(p => p.Id == match.Players[(int)PlayerSlot.Challenger].Id);

                    playersInRound.Add(defIndex);
                    playersInRound.Add(chalIndex);
                    Matchups.Add(new Matchup(defIndex, chalIndex, r));
                }

                if (playersInRound.Count < Players.Count)
                {
                    // Find the player with a bye this round:
                    int byePlayerIndex = Enumerable
                                         .Range(0, Players.Count).ToList()
                                         .Except(playersInRound).First();

                    // Add him to Byes list and award a "Win" Outcome:
                    PlayerByes.Add(Players[byePlayerIndex].Id);
                    Rankings.Find(p => p.Id == Players[byePlayerIndex].Id)
                    .AddMatchOutcome(Outcome.Win, true);
                }

                // Set ActiveRound (this finds the last populated round):
                ActiveRound = r;
            }

            // Determine the Pairing Method from examining round 1:
            // (default is Slide)
            this.PairingMethod = PairingMethod.Slide;
            if (NumberOfMatches > 0 && ActiveRound > 0)
            {
#if CHOOSE_PAIRING
                // Find the top seed's first Match:
                int firstPlayerIndex = (0 == PlayerByes.Count)
                                        ? 0 : 1;
                IMatch firstPlayerMatch = GetRound(1)
                                          .Where(m => m.Players.Select(p => p.Id).Contains(this.Players[firstPlayerIndex].Id))
                                          .First();
                // Find the ID of the Player the top seed is matched against:
                int secondPlayerId = firstPlayerMatch.Players
                                     .Select(p => p.Id)
                                     .Where(i => i != this.Players[firstPlayerIndex].Id)
                                     .First();

                if (Players[1 + firstPlayerIndex].Id == secondPlayerId)
                {
                    // The second Player is also the second seed.
                    // This must be Adjancent pairings.
                    PairingMethod = PairingMethod.Adjacent;
                }
                else if (Players.Last().Id == secondPlayerId)
                {
                    // The second Player is the last seed.
                    // This must be Fold pairings.
                    PairingMethod = PairingMethod.Fold;
                }
#endif

                if (PlayerByes.Count > 0)
                {
                    // If we added points for byes, we need to update rankings.
                    // Call the parent (round robin) method:
                    UpdateRankings();
                }
            }
        }