Beispiel #1
0
        public static ICollection <Result> GetResults(string course, short year)
        {
            ICollection <Result> results;

            ICollection <Student> students = GetStudents(course, year);
            string className = GetClassName(course);

            using (HonglornDb db = new HonglornDb())
            {
                DisciplineCollection disciplines = (from d in db.DisciplineCollection
                                                    where d.ClassName == className &&
                                                    d.Year == year
                                                    select d).SingleOrDefault();

                if (disciplines == null)
                {
                    throw new DataException($"No disciplines have been configured for class {className} in year {year}. Therefore, no results can be calculated.");
                }

                Discipline[] disciplineArray = new[] { disciplines.MaleSprint, disciplines.MaleJump, disciplines.MaleThrow, disciplines.MaleMiddleDistance, disciplines.FemaleSprint, disciplines.FemaleJump, disciplines.FemaleThrow, disciplines.FemaleMiddleDistance };

                if (disciplineArray.All(d => d is TraditionalDiscipline))
                {
                    TraditionalDisciplineCollection disciplineCollection = new TraditionalDisciplineCollection()
                    {
                        MaleSprint           = disciplines.MaleSprint as TraditionalDiscipline,
                        MaleJump             = disciplines.MaleJump as TraditionalDiscipline,
                        MaleThrow            = disciplines.MaleThrow as TraditionalDiscipline,
                        MaleMiddleDistance   = disciplines.MaleMiddleDistance as TraditionalDiscipline,
                        FemaleSprint         = disciplines.FemaleSprint as TraditionalDiscipline,
                        FemaleJump           = disciplines.FemaleJump as TraditionalDiscipline,
                        FemaleThrow          = disciplines.FemaleThrow as TraditionalDiscipline,
                        FemaleMiddleDistance = disciplines.FemaleMiddleDistance as TraditionalDiscipline
                    };

                    results = CalculateTraditionalResults(students, year, disciplineCollection);
                }
                else if (disciplineArray.All(d => d is CompetitionDiscipline))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    throw new DataException($"For class {className} in year {year}, some configured disciplines are traditional disciplines, while other disciplines are competition disciplines. A result can only be calculated when all disciplines are of the same type.");
                }
            }

            return(results);
        }
Beispiel #2
0
        static ICollection <Result> CalculateTraditionalResults(IEnumerable <Student> students, short year, TraditionalDisciplineCollection disciplineCollection)
        {
            ICollection <Result> results = new List <Result>();

            foreach (Student student in students)
            {
                ushort totalScore = 0;

                Competition competition = (from sc in student.Competition
                                           where sc.Year == year
                                           select sc).SingleOrDefault() ?? new Competition();

                if (student.Sex == Sex.Male)
                {
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.MaleSprint, competition.Sprint);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.MaleJump, competition.Jump);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.MaleThrow, competition.Throw);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.MaleMiddleDistance, competition.MiddleDistance);
                }
                else
                {
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.FemaleSprint, competition.Sprint);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.FemaleJump, competition.Jump);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.FemaleThrow, competition.Throw);
                    totalScore += TraditionalCalculator.CalculateScore(disciplineCollection.FemaleMiddleDistance, competition.MiddleDistance);
                }

                results.Add(new Result
                {
                    Surname     = student.Surname,
                    Forename    = student.Forename,
                    Score       = totalScore,
                    Certificate = DetermineTraditionalCertificate(student.Sex, student.YearOfBirth, totalScore)
                });
            }

            return(results);
        }