示例#1
0
        protected override void ApplyModel(EventDto model)
        {
            EventStatus     = model.EventStatus;
            EventName       = model.EventName;
            TrackName       = model.TrackName;
            SessionsResults = model.Sessions.Select(x =>
            {
                string sessionName = x.Name;
                if (x.SessionResult == null)
                {
                    return(new KeyValuePair <string, string>(sessionName, "-"));
                }

                DriverSessionResultDto playerResult = x.SessionResult.DriverSessionResult.FirstOrDefault(y => y.IsPlayer);
                return(playerResult == null ? new KeyValuePair <string, string>(sessionName, "-") : new KeyValuePair <string, string>(sessionName, playerResult.FinishPosition.ToString()));
            }).ToList();
        }
示例#2
0
        private SessionResultDto CreateResultDto(ChampionshipDto championship, SimulatorDataSet dataSet, bool shiftPlayerToLastPlace)
        {
            var scoring = championship.Scoring[championship.CurrentSessionIndex];
            Dictionary <string, int> positionMap = CreateFinishPositionDictionary(dataSet.DriversInfo.Where(x => x.CarClassId == dataSet.PlayerInfo.CarClassId).ToList(), shiftPlayerToLastPlace);
            SessionResultDto         resultDto   = new SessionResultDto();

            foreach (DriverDto championshipDriver in championship.Drivers)
            {
                DriverInfo sessionDriver = dataSet.DriversInfo.FirstOrDefault(x => x.DriverName == championshipDriver.LastUsedName);
                if (sessionDriver == null)
                {
                    Logger.Error($"Driver {championshipDriver.LastUsedName} not found");
                    throw new InvalidOperationException($"Driver {championshipDriver.LastUsedName} not found");
                }
                int position = positionMap[sessionDriver.DriverName];
                DriverSessionResultDto driverResult = new DriverSessionResultDto()
                {
                    DriverGuid          = championshipDriver.GlobalKey,
                    DriverName          = championshipDriver.LastUsedName,
                    FinishPosition      = position,
                    PointsGain          = position <= scoring.Scoring.Count ? scoring.Scoring[position - 1] : 0,
                    BeforeEventPosition = championshipDriver.Position,
                    IsPlayer            = championshipDriver.IsPlayer,
                };
                driverResult.TotalPoints = championshipDriver.TotalPoints + driverResult.PointsGain;

                resultDto.DriverSessionResult.Add(driverResult);
            }

            DriverSessionResultComparer   comparer = new DriverSessionResultComparer(championship);
            List <DriverSessionResultDto> driversAfterRaceOrdered = resultDto.DriverSessionResult.OrderBy(x => x, comparer).ToList();

            for (int i = 0; i < driversAfterRaceOrdered.Count; i++)
            {
                driversAfterRaceOrdered[i].AfterEventPosition = i + 1;
            }

            return(resultDto);
        }