Example #1
0
        private List <TimeSheet> GenerateValidTimeSheets(int numberToCreate)
        {
            var validScores = new List <TimeSheet>();
            var TaskA       = new TaskA_LastFlightSevenMin();

            if (numberToCreate == 0)
            {
                return(validScores);
            }
            var rnd = new Random();

            for (var i = 0; i < numberToCreate; ++i)
            {
                var timeGates = new List <TimeGate> {
                    new TimeGate(TimeSpan.MinValue, i, TimeGateType.Task)
                };
                var roundScore = new TimeSheet
                {
                    RoundOrdinal = 1,
                    TimeGates    = timeGates,
                    PilotId      = $"pilot{rnd.Next(1, 100)}",
                    ContestId    = "234234",
                    TaskId       = TaskA.Id,
                    FlightGroup  = FlightGroup.A
                };

                validScores.Add(roundScore);
            }

            return(validScores);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskRepository" /> class.
        /// </summary>
        public TaskRepository()
        {
            var taskA  = new TaskA_LastFlightSevenMin();
            var taskB  = new TaskB_LastTwoFlights4MinMax();
            var taskC  = new TaskC_AllUpLastDown(3);
            var taskC4 = new TaskC_AllUpLastDown(4);
            var taskC5 = new TaskC_AllUpLastDown(5);
            var taskD  = new TaskD_Ladder();
            var taskE  = new TaskE_Poker();
            var taskF  = new TaskF_BestThreeOutOfSix();
            var taskG  = new TaskG_FiveTwos();
            var taskH  = new TaskH_FourThreeTwoOne();
            var taskI  = new TaskI_ThreeThreeTwenties();
            var taskJ  = new TaskJ_LastThree();

            this.internalCache.Add(taskA.Id, taskA);
            this.internalCache.Add(taskB.Id, taskB);
            this.internalCache.Add(taskC.Id, taskC);
            this.internalCache.Add(taskC4.Id, taskC4);
            this.internalCache.Add(taskC5.Id, taskC5);
            this.internalCache.Add(taskD.Id, taskD);
            this.internalCache.Add(taskE.Id, taskE);
            this.internalCache.Add(taskF.Id, taskF);
            this.internalCache.Add(taskG.Id, taskG);
            this.internalCache.Add(taskH.Id, taskH);
            this.internalCache.Add(taskI.Id, taskI);
            this.internalCache.Add(taskJ.Id, taskJ);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskRepository" /> class.
        /// </summary>
        public TaskRepository()
        {
            var taskA  = new TaskA_LastFlightSevenMin();
            var taskB  = new TaskB_LastTwoFlights4MinMax();
            var taskC  = new TaskC_AllUpLastDown(3);
            var taskC4 = new TaskC_AllUpLastDown(4);
            var taskC5 = new TaskC_AllUpLastDown(5);
            var taskD  = new TaskD_Ladder();
            var taskE  = new TaskE_Poker();
            var taskF  = new TaskF_BestThreeOutOfSix();
            var taskG  = new TaskG_FiveTwos();
            var taskH  = new TaskH_FourThreeTwoOne();
            var taskI  = new TaskI_ThreeThreeTwenties();
            var taskJ  = new TaskJ_LastThree();
            var taskK  = new TaskK_BigLadder();


            this.internalCache.Add(taskA.Id, taskA);
            this.internalCache.Add(taskB.Id, taskB);
            this.internalCache.Add(taskC.Id, taskC);
            this.internalCache.Add(taskC4.Id, taskC4);
            this.internalCache.Add(taskC5.Id, taskC5);
            this.internalCache.Add(taskD.Id, taskD);
            this.internalCache.Add(taskE.Id, taskE);
            this.internalCache.Add(taskF.Id, taskF);
            this.internalCache.Add(taskG.Id, taskG);
            this.internalCache.Add(taskH.Id, taskH);
            this.internalCache.Add(taskI.Id, taskI);
            this.internalCache.Add(taskJ.Id, taskJ);
            this.internalCache.Add(taskK.Id, taskK);

// Add in a task that runs quick for debugging.
#if DEBUG
            var taskT = new TaskT_TestTask();
            this.internalCache.Add(taskT.Id, taskT);
#endif
        }
        /// <summary>
        /// Generates valid time sheets.
        /// </summary>
        /// <param name="numberOfPilots">The number to create.</param>
        /// <param name="contestId">The contest identifier.</param>
        /// <param name="numberOfRounds">The number of rounds.</param>
        /// <param name="maxTimeGateTimeInSeconds">The maximum time gate time in seconds.</param>
        /// <param name="multipleFlightGroups">if set to <c>true</c> [multiple flight groups].</param>
        /// <param name="generateScores">if set to <c>true</c> [generate scores].</param>
        /// <returns></returns>
        public static List <TimeSheet> GenerateValidTimeSheets(int numberOfPilots,
                                                               string contestId             = "SASS August 2017",
                                                               int numberOfRounds           = 1,
                                                               int maxTimeGateTimeInSeconds = 120,
                                                               bool multipleFlightGroups    = false,
                                                               bool generateScores          = false)
        {
            var validScoresToReturn = new List <TimeSheet>();
            var validScoresForRound = new List <TimeSheet>();
            var TaskA = new TaskA_LastFlightSevenMin();

            if (numberOfPilots == 0)
            {
                return(validScoresToReturn);
            }
            var rnd = new Random();

            // Set up a mock task to validate and score the rounds if required.
            var mockTask = new Mock <TaskBase>();

            mockTask.Setup(x => x.ValidateTask(It.IsAny <RoundScoreBase>())).Returns(true);
            mockTask.Setup(x => x.ScoreTask(It.IsAny <RoundScoreBase>())).Returns <RoundScoreBase>(y => y.TimeGates.Sum(x => x.Time.TotalSeconds));
            var f3kRoundScoreAlgo = new RoundScoringAlgo();

            for (var i = 0; i < numberOfRounds; ++i)
            {
                // Reset
                validScoresForRound = new List <TimeSheet>();

                for (var j = 0; j < numberOfPilots; ++j)
                {
                    var flightGroup = FlightGroup.A;

                    // Generate 2 flight groups
                    if (multipleFlightGroups)
                    {
                        flightGroup = (j % 2) != 0 ? FlightGroup.A : FlightGroup.B;
                    }

                    var timeGates = new List <TimeGate> {
                        new TimeGate(TimeSpan.FromSeconds(rnd.Next(45, maxTimeGateTimeInSeconds)), j, TimeGateType.Task)
                    };
                    var roundScore = new TimeSheet
                    {
                        RoundOrdinal = i,
                        TimeGates    = timeGates,
                        PilotId      = $"pilot{j}",
                        ContestId    = contestId,
                        TaskId       = TaskA.Id,
                        FlightGroup  = FlightGroup.A
                    };

                    // Generate the scores if needed.
                    if (generateScores)
                    {
                    }

                    validScoresForRound.Add(roundScore);
                }

                if (generateScores)
                {
                    f3kRoundScoreAlgo.ScoreRound(validScoresForRound, mockTask.Object);
                }

                validScoresToReturn.AddRange(validScoresForRound);
            }

            return(validScoresToReturn);
        }