Example #1
0
        private static List <CompetitorChampionship> ClassResults(int events, int firstCompetitor, int classCompetitors, string[] lines)
        {
            var classResult = new List <CompetitorChampionship>();

            for (int i = firstCompetitor; i < firstCompetitor + classCompetitors; i++)
            {
                string[] split = lines[i].Split(',');
                var      competitorChampionship = new CompetitorChampionship
                {
                    Number    = int.Parse(split[0]),
                    Name      = split[1],
                    Car       = split[2],
                    Points    = new List <EventPoints>(),
                    Total     = int.Parse(split[events * 3 + 3]),
                    Penalties = int.Parse(split[events * 3 + 4]),
                };
                for (int j = 0; j < events; j++)
                {
                    var eventPoints = new EventPoints
                    {
                        Position           = Int32.TryParse(split[3 * j + 3], out int tempVal) ? Int32.Parse(split[3 * j + 3]) : (int?)null,
                        CompetitorsInClass = Int32.TryParse(split[3 * j + 4], out tempVal) ? Int32.Parse(split[3 * j + 4]) : (int?)null,
                        FastestLap         = Int32.TryParse(split[3 * j + 5], out tempVal) ? Int32.Parse(split[3 * j + 5]) : (int?)null
                    };
                    competitorChampionship.Points.Add(eventPoints);
                }
                classResult.Add(competitorChampionship);
            }
            return(classResult);
        }
Example #2
0
        public static Championship Calculate(List <CompetitorResult> overallCompetitors,
                                             List <CompetitorResult> n2Competitors,
                                             List <CompetitorResult> n4Competitors,
                                             List <CompetitorResult> e2Competitors,
                                             List <CompetitorResult> e4Competitors,
                                             List <CompetitorResult> proCompetitors,
                                             List <CompetitorResult> truckCompetitors)
        {
            // First event of the season
            var championship = new Championship
            {
                Events             = 1,
                OverallCompetitors = overallCompetitors.Count(),
                N2Competitors      = n2Competitors.Count(),
                N4Competitors      = n4Competitors.Count(),
                E2Competitors      = e2Competitors.Count(),
                E4Competitors      = e4Competitors.Count(),
                ProCompetitors     = proCompetitors.Count(),
                TruckCompetitors   = truckCompetitors.Count()
            };

            // Overall results
            championship.Overall = new List <CompetitorChampionship>();
            foreach (var competitor in overallCompetitors)
            {
                var competitorChampionship = new CompetitorChampionship()
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep);
                championship.Overall.Add(competitorChampionship);
            }
            ;

            // N2 results
            championship.N2 = new List <CompetitorChampionship>();
            foreach (var competitor in n2Competitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.N2.Add(competitorChampionship);
            }
            ;

            // N4 results
            championship.N4 = new List <CompetitorChampionship>();
            foreach (var competitor in n4Competitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.N4.Add(competitorChampionship);
            }
            ;

            // E2 results
            championship.E2 = new List <CompetitorChampionship>();
            foreach (var competitor in e2Competitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.E2.Add(competitorChampionship);
            }
            ;

            // E4 results
            championship.E4 = new List <CompetitorChampionship>();
            foreach (var competitor in e4Competitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.E4.Add(competitorChampionship);
            }
            ;

            // Pro results
            championship.Pro = new List <CompetitorChampionship>();
            foreach (var competitor in proCompetitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.Pro.Add(competitorChampionship);
            }
            ;

            // Truck results
            championship.Truck = new List <CompetitorChampionship>();
            foreach (var competitor in truckCompetitors)
            {
                var competitorChampionship = new CompetitorChampionship
                {
                    Number    = competitor.Number,
                    Car       = competitor.Car,
                    Name      = competitor.Name,
                    Points    = new List <EventPoints>(),
                    Total     = competitor.PositionPoints + competitor.CompetitorsInClassPoints + competitor.FastestLapPoints,
                    Penalties = competitor.Penalties
                };
                EventPoints ep = new EventPoints()
                {
                    Position           = competitor.PositionPoints,
                    CompetitorsInClass = competitor.CompetitorsInClassPoints,
                    FastestLap         = competitor.FastestLapPoints
                };
                competitorChampionship.Points.Add(ep); championship.Truck.Add(competitorChampionship);
            }
            ;

            return(championship);
        }