コード例 #1
0
 protected virtual void ResetLapTimes()
 {
     _lapTimes    = new EventVehicleLapTimes();
     _lastElapsed = -1;
     _lastRaceId  = -1;
     _lastRunId   = -1;
 }
コード例 #2
0
        protected virtual string GetFileDirectory(string rootDirectory, EventVehicleLapTimes data)
        {
            SeriesType seriesType = (SeriesType)(data.SeriesId - 1);

            var series = seriesType.ToString();

            var track = data.TrackName;

            var runName = data.RunName;

            var eventDate = DateTime.Now.ToString("MM-dd-yyyy");

            var subDirectoryPath = $"{series}\\{track}\\{eventDate}\\{runName}";

            foreach (var c in Path.GetInvalidPathChars())
            {
                subDirectoryPath = subDirectoryPath.Replace(c.ToString(), "");
            }

            var fullFileDirectory = Path.Combine(rootDirectory, subDirectoryPath);

            if (!Directory.Exists(fullFileDirectory))
            {
                Directory.CreateDirectory(fullFileDirectory);
            }

            return(fullFileDirectory);
        }
コード例 #3
0
 protected virtual string GetContent(EventVehicleLapTimes lapTimes)
 {
     return(JsonConvert.SerializeObject(
                lapTimes,
                Formatting.Indented,
                new JsonSerializerSettings {
         NullValueHandling = NullValueHandling.Include
     }));
 }
コード例 #4
0
        protected virtual void ProcessLiveFeedDataAsync(LiveFeedData liveFeedData)
        {
            try
            {
                if (_verbose)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append($"Elapsed:{liveFeedData.Elapsed} ");
                    sb.Append($"SeriesId:{liveFeedData.SeriesType} ");
                    sb.Append($"RaceId:{liveFeedData.RaceId} ");
                    sb.AppendLine($"RunId:{liveFeedData.RunId}");
                    sb.Append($"LapNumber:{liveFeedData.LapNumber} ");
                    sb.AppendLine($"FlagState:{liveFeedData.FlagState.ToString()}");

                    Console.WriteLine("------------------");
                    Console.WriteLine(sb);
                }

                if (liveFeedData.RaceId != _lastRaceId ||
                    liveFeedData.SeriesType != _lastSeriesId ||
                    liveFeedData.RunId != _lastRunId)
                {
                    if (_verbose)
                    {
                        Console.WriteLine("Resetting lap times");
                    }

                    ResetLapTimes();

                    _lapTimes.RaceId    = liveFeedData.RaceId;
                    _lapTimes.SeriesId  = (int)liveFeedData.SeriesType;
                    _lapTimes.RunId     = liveFeedData.RunId;
                    _lapTimes.Elapsed   = liveFeedData.Elapsed;
                    _lapTimes.TrackName = liveFeedData.TrackName;
                    _lapTimes.RunName   = liveFeedData.RunName;
                }

                _lapTimes = ReadLapTimes(liveFeedData);

                if (liveFeedData.Elapsed != _lastElapsed)
                {
                    OnLapTimesUpdated(_lapTimes);

                    _lastElapsed  = liveFeedData.Elapsed;
                    _lastRaceId   = liveFeedData.RaceId;
                    _lastSeriesId = liveFeedData.SeriesType;
                    _lastRunId    = liveFeedData.RunId;
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error pumping lap times", ex);
            }
        }
コード例 #5
0
        protected virtual string GetFileContent(EventVehicleLapTimes data)
        {
            var fileContent = JsonConvert.SerializeObject(
                data,
                Formatting.Indented,
                new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Include
            });

            return(fileContent);
        }
コード例 #6
0
        protected virtual void OnLapTimesUpdated(EventVehicleLapTimes lapTimes)
        {
            var handler = LapTimesUpdated;

            if (handler != null)
            {
                handler.Invoke(this, new LapTimesUpdatedEventArgs()
                {
                    LapTimes = lapTimes
                });
            }
        }
コード例 #7
0
        public void WriteFile(string rootDirectory, EventVehicleLapTimes data)
        {
            var fileDirectory = GetFileDirectory(rootDirectory, data);

            var fileTitle = GetFileTitle(data);

            var fullFilePath = Path.Combine(fileDirectory, fileTitle);

            var fileContent = GetFileContent(data);

            File.WriteAllText(fullFilePath, fileContent);

            LastElapsedWritten = data.Elapsed;
        }
コード例 #8
0
        public virtual async Task WriteLapTimesAsync(EventVehicleLapTimes lapAverages)
        {
            var key = GetKey(lapAverages);

            var content = GetContent(lapAverages);

            var contentType = GetContentType(lapAverages);

            var item = new AwsItem()
            {
                Key         = key,
                Content     = content,
                ContentType = contentType
            };

            await _repository.PutAsync(item);
        }
コード例 #9
0
ファイル: LapTimeParser.cs プロジェクト: RacerData/RacerData
        public EventVehicleLapTimes ParseLapTimes(EventVehicleLapTimes lapTimes, LiveFeedData data)
        {
            foreach (Vehicle vehicle in data.Vehicles)
            {
                var existingLap = lapTimes.VehicleLapTimes.FirstOrDefault(l => l.VehicleId == vehicle.CarNumber && l.LapNumber == vehicle.LapsCompleted);

                if (existingLap == null)
                {
                    if (_verbose)
                    {
                        Console.WriteLine($"Adding lap time for car {vehicle.CarNumber} for lap {vehicle.LapsCompleted}: {vehicle.LastLapTime}");
                    }

                    lapTimes.VehicleLapTimes.Add(new VehicleLapTime()
                    {
                        VehicleId      = vehicle.CarNumber,
                        LapNumber      = vehicle.LapsCompleted,
                        LapTime        = vehicle.LastLapTime,
                        EventElapsed   = data.Elapsed,
                        VehicleElapsed = vehicle.VehicleElapsedTime,
                        TrackState     = data.FlagState,
                        VehicleStatus  = (VehicleStatus)vehicle.Status
                    });
                }
                else
                {
                    if (existingLap.VehicleElapsed != vehicle.VehicleElapsedTime ||
                        existingLap.LapNumber != vehicle.LapsCompleted ||
                        existingLap.LapTime != vehicle.LastLapTime ||
                        existingLap.VehicleStatus != (VehicleStatus)vehicle.Status ||
                        existingLap.TrackState != data.FlagState)
                    {
                        if (_verbose)
                        {
                            Console.WriteLine($"Updating lap time for car {vehicle.CarNumber} " +
                                              $"for lap {vehicle.LapsCompleted}: " +
                                              $"  from {existingLap.LapTime} to {vehicle.LastLapTime}" +
                                              $"  from {existingLap.VehicleStatus} to {((VehicleStatus)vehicle.Status).ToString()}" +
                                              $"  from {existingLap.TrackState} to {data.FlagState.ToString()}");
                        }

                        existingLap.VehicleElapsed = vehicle.VehicleElapsedTime;
                        existingLap.LapNumber      = vehicle.LapsCompleted;
                        existingLap.LapTime        = vehicle.LastLapTime;
                        existingLap.VehicleStatus  = (VehicleStatus)vehicle.Status;
                        existingLap.TrackState     = data.FlagState;
                    }
                }

                //foreach (PitStop pitStop in vehicle.PitStops)
                //{
                //    var existingPitStop = history.GetPitStopEventAt(pitStop.PitInElapsed);

                //    if (existingPitStop == null)
                //    {
                //        history.AddPitEvent(pitStop.PitInElapsed, pitStop.PitInLap, pitStop.PitOutElapsed);
                //    }
                //    else
                //    {
                //        if (existingPitStop.PitOutElapsed == 0.0)
                //        {
                //            existingPitStop.PitOutElapsed = pitStop.PitOutElapsed;
                //        }
                //    }
                //}
            }
            return(lapTimes);
        }
コード例 #10
0
        protected virtual string GetFileTitle(EventVehicleLapTimes data)
        {
            var fileTitle = $"{data.SeriesId}-{data.RaceId}-{data.RunId}-{data.Elapsed}.json";

            return(fileTitle);
        }
コード例 #11
0
 public void WriteFile(EventVehicleLapTimes data)
 {
     WriteFile(RootDirectory, data);
 }
コード例 #12
0
 protected virtual string GetContentType(EventVehicleLapTimes lapTimes)
 {
     return("application/json");
 }
コード例 #13
0
 protected virtual string GetKey(EventVehicleLapTimes lapTimes)
 {
     return($"{lapTimes.SeriesId}-{lapTimes.RaceId}-{lapTimes.RunId}");
 }