Example #1
0
        static void ShowRaceResult()
        {
            Console.WriteLine("####################################\n" +
                              "###### Teste Back-End GymPass #######\n" +
                              "####################################\n" +
                              "###### Felipe Nicolau Moreti #######\n" +
                              "#### [email protected] ######\n" +
                              "######### (11)98030-4601 ###########\n" +
                              "####################################\n" +
                              "####################################\n" +
                              "########## RACE RESULTS ############\n\n" +
                              "Posição\tcódigo\t\tNome\t\tVoltas\t\tTempo Total\t\t\tBest Lap - Best Lap Time\t\tAverage Velocity\t\ttempo atrás");

            for (int i = 0; i < results.Count; i++)
            {
                Pilot p = results[i];

                Lap      winnerLastLap  = results[0].GetLaps[results[0].GetLaps.Count - 1];
                Lap      lastLap        = p.GetLaps[p.GetLaps.Count - 1];
                TimeSpan timeAfterFirst = (lastLap.LapInitialTime + lastLap.LapTotalTime) - (winnerLastLap.LapInitialTime + winnerLastLap.LapTotalTime);

                Console.WriteLine(string.Format("{0}\t{1}\t\t{2}\t\t{3}\t\t{4}\t\t{5} - {6}\t\t{7}\t\t+{8}",
                                                i + 1, p.GetId, p.GetName, p.GetTotalLaps, p.GetTotalTime, p.GetBestLap, p.GetBestLapTime, p.GetAverageVelocity, timeAfterFirst));
            }

            Console.WriteLine("\n#### Best Lap of the race ####\n");
            Pilot faster = results.OrderBy(p => p.GetBestLapTime).First();

            Console.WriteLine(string.Format("{0} - {1}\n", faster.GetName, faster.GetBestLapTime));
        }
Example #2
0
        public static List <PilotData> ProcessRaceData(string fileName, out TimeSpan bestLapOverall)
        {
            bestLapOverall = new TimeSpan(1, 0, 0, 0);
            string line;
            var    raceData = new Dictionary <int, PilotData>();

            var file = new StreamReader(fileName);

            line = file.ReadLine(); //Discards the first line
            while ((line = file.ReadLine()) != null)
            {
                var lap = Lap.ParseLap(line);

                //Disregards all laps after the fourth one
                if (lap.LapNumber > 4)
                {
                    continue;
                }

                if (raceData.TryGetValue(lap.PilotId, out var pilotData))
                {
                    pilotData.LapsInfo.Add(lap);

                    //Just to be safe in case the laps are not in order
                    if (lap.LapNumber > pilotData.CurrentLap)
                    {
                        pilotData.CurrentLap = lap.LapNumber;
                        pilotData.FinishAt   = lap.FinishAt;
                    }

                    pilotData.BestLap = lap.LapTime.CompareTo(pilotData.BestLap) < 0 ? lap.LapTime : pilotData.BestLap;
                }
                else
                {
                    raceData[lap.PilotId] = new PilotData()
                    {
                        CurrentLap = lap.LapNumber,
                        Id         = lap.PilotId,
                        Name       = lap.PilotName,
                        LapsInfo   = new List <Lap> {
                            lap
                        },
                        BestLap  = lap.LapTime,
                        FinishAt = lap.FinishAt,
                    };
                }

                bestLapOverall = lap.LapTime.CompareTo(bestLapOverall) < 0 ? lap.LapTime : bestLapOverall;
            }

            //Order the result  by number of laps completed then by the lowest race time
            return(raceData.OrderByDescending(_ => _.Value.CurrentLap).
                   ThenBy(_ => _.Value.TotalTime.TotalMilliseconds).Select(_ => _.Value).ToList());
        }