public void LineCrossed() { if (CommonReferences.sessionManager.times.Count != 0) { GameObject.FindWithTag("UI_Time").GetComponent <TMPro.TMP_Text>().text = CommonReferences.sessionManager.times[0].time.ToString(); } if (myTime != null) { CommonReferences.sessionManager.AddTime(myTime); if (isPlayer && GamePreferences.adaptativeAI) { GamePreferences.difficulty = (myTime.time - 39f) / -6.5f; Debug.Log("difficulty set to " + GamePreferences.difficulty); } myTime.time = 0f; } if (myTime == null) { myTime = new LapTime(0f, carData); } if (isPlayer) { List <CarData> positions = CommonReferences.sessionManager.standings.AddLap(carData); posText.text = "Pos: " + (positions.IndexOf(carData) + 1) + "/" + positions.Count; } else { CommonReferences.sessionManager.standings.AddLap(carData); } }
public async Task <EntityState> Update(string id, LapTime lapTime) { using (ApplicationDbContext db = new ApplicationDbContext()) { db.Entry(lapTime).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (db.LapTimes.Count(e => e.Id == id) == 0) { return(EntityState.Unchanged); } else { throw; } } return(db.Entry(lapTime).State); } }
public int AddTime(LapTime lapTime) { Debug.Log("adding the time: " + lapTime.time + "..."); if (times.Count == 0) { times.Add(lapTime); return(1); } else { for (int i = 0; i < times.Count; i++) { if (times[i].carData == lapTime.carData) { times.Remove(times[i]); Debug.Log("A time was removed as it will be replaced"); } } for (int i = 0; i < times.Count; i++) { if (times[i].time > lapTime.time) { times.Insert(i, lapTime); return(i + 1); } } times.Add(lapTime); return(times.Count); } }
private LapData BuildLapData(TimeSpan timeSpan) { var ts = timeSpan == TimeSpan.Zero ? LapTimeSpan() : timeSpan; var lapTime = new LapTime(ts.Minutes, ts.Seconds, ts.Milliseconds); var position = new Position(1); return(new LapData(lapTime, position)); }
public override bool Equals(object obj) { return(obj is LapEntry entry && TimeOfDay.Equals(entry.TimeOfDay) && DriverNumber == entry.DriverNumber && DriverName == entry.DriverName && LapNumber == entry.LapNumber && LapTime.Equals(entry.LapTime) && AvarageSpeed == entry.AvarageSpeed); }
public async Task <LapTime> Insert(LapTime lapTime) { using (ApplicationDbContext db = new ApplicationDbContext()) { lapTime.Id = string.IsNullOrEmpty(lapTime.Id) ? Guid.NewGuid().ToString() : lapTime.Id; lapTime = db.LapTimes.Add(lapTime); await db.SaveChangesAsync(); } return(lapTime); }
public void PublishLapTime(LapTime lapTime) { try { (_baseUrl + "/laptimes").PostJsonToUrl(lapTime); } catch (WebException e) { Log.LogError("Failed to send lap time: " + e.Message); } }
public override string ToString() { var builder = new System.Text.StringBuilder(); builder.AppendFormat("{0} {{", nameof(LeaderboardEntry)).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(CarId), CarId.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(LapTime), LapTime.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(Laps), Laps.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(HasFinished), HasFinished.ToString()).AppendLine(); builder.AppendFormat("}}").AppendLine(); return(builder.ToString()); }
public static void ProcessErgastLapTimes() { string fileLocation = Seed.baseLocation + "lap_times.csv"; var data = new List <LapTime>(); var docOpen = true; var counter = 0; var length = 0; using (var db = new F1EncyclopediaContext()) { while (docOpen) { try { using (var sr = new StreamReader(fileLocation)) { var fileArr = File.ReadAllLines(fileLocation); length = fileArr.Length; data = fileArr.Skip(1) .Select(x => { Console.Write("\rProcessed: {0}", counter, counter * 100 / length); return(LapTime.FromCsv(x, db)); }) .ToList(); } docOpen = false; } catch (IOException e) { docOpen = true; Console.WriteLine("CSV file is open in another application. Please close to continue."); System.Threading.Thread.Sleep(2000); } } counter = 0; Console.WriteLine("Completed processing data. Starting add.\n"); foreach (var lt in data) { db.LapTimes.AddIfNotExists(lt, x => x.RaceWeekendId == lt.RaceWeekendId && x.DriverId == lt.DriverId && x.Lap == lt.Lap); Console.Write("\rAdded: {0}", counter += 1); } Console.WriteLine("Entities added and tracked, saving changes..."); db.SaveChanges(); Console.WriteLine("Completed."); } }
public void LapTimeDTO_Test() { LapTimeDTO laptimeDTO = Mapper.Map <LapTimeDTO>(laptime); LapTime testLaptime = Mapper.Map <LapTime>(laptimeDTO); Assert.AreEqual(laptime.DriverResultId, laptimeDTO.DriverResultId); Assert.AreEqual(laptime.LapNumber, laptimeDTO.LapNumber); Assert.AreEqual(laptime.Time, laptimeDTO.Time); Assert.AreEqual(laptime.DriverResultId, testLaptime.DriverResultId); Assert.AreEqual(laptime.LapNumber, testLaptime.LapNumber); Assert.AreEqual(laptime.Time, testLaptime.Time); }
public bool Equals(CalculatedLap other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Time.Equals(other.Time) && Index == other.Index && LapTime.Equals(other.LapTime) && Rounds == other.Rounds && RoundsToGo == other.RoundsToGo && PassedLength == other.PassedLength && Ranking == other.Ranking); }
public override int GetHashCode() { unchecked { var hashCode = Time.GetHashCode(); hashCode = (hashCode * 397) ^ Index; hashCode = (hashCode * 397) ^ LapTime.GetHashCode(); hashCode = (hashCode * 397) ^ Rounds.GetHashCode(); hashCode = (hashCode * 397) ^ RoundsToGo.GetHashCode(); hashCode = (hashCode * 397) ^ PassedLength; hashCode = (hashCode * 397) ^ Ranking.GetHashCode(); return(hashCode); } }
public IEnumerable <ResultRowModel> GetResultRows() { List <IRacingResultRow> resultRows = new List <IRacingResultRow>(); foreach (var resultRow in SessionResults) { IRacingResultRow row = new IRacingResultRow { //FinalPosition = int.Parse(line["FinPos"]), StartPosition = (int)resultRow.starting_position + 1, IRacingId = (string)resultRow.cust_id, FinishPosition = (int)resultRow.finish_position + 1, CarNumber = resultRow.livery.car_number, ClassId = resultRow.car_class_id, Car = "", CarClass = "", CompletedLaps = resultRow.laps_complete, LeadLaps = resultRow.laps_lead, FastLapNr = resultRow.best_lap_num, Incidents = resultRow.incidents, Status = Enum.TryParse((string)resultRow.reason_out, out RaceStatusEnum statusEnum) ? statusEnum : RaceStatusEnum.Unknown, QualifyingTime = new LapTime(TimeSpan.Zero) }; var eventLaps = (int)ResultData.event_laps_complete; row.CompletedPct = eventLaps >= row.CompletedLaps ? (row.CompletedLaps / eventLaps) * 100 : 100; //if (!LeagueClient.LeagueMembers.ToList().Exists(x => x.IRacingId == row.IRacingId)) if (MemberList.Any(x => x.IRacingId == (string)resultRow.cust_id)) { row.Member = MemberList.SingleOrDefault(x => x.IRacingId == (string)resultRow.cust_id); } //row.Interval = new LapInterval( // TimeSpan.TryParse("0:" + line["Interval"].Replace("-",""), culture, out TimeSpan intvTime) ? intvTime : TimeSpan.Zero, // int.TryParse(line["Interval"].Replace("L", ""), out int intvLaps) ? intvLaps : 0); //row.Interval = new LapInterval(GetTimeSpanFromString(line["Interval"]), int.TryParse(line["Interval"].Replace("L", ""), out int intvLaps) ? intvLaps : 0); row.Interval = resultRow.interval >= 0 ? new LapInterval(new TimeSpan((long)resultRow.interval * (TimeSpan.TicksPerMillisecond / 10))) : new LapInterval(TimeSpan.Zero, (int)ResultData.event_laps_complete - row.CompletedLaps); //row.AvgLapTime = new LapTime(TimeSpan.TryParse(PrepareTimeString(line["AverageLapTime"]), culture, out TimeSpan avgLap) ? avgLap : TimeSpan.Zero); row.AvgLapTime = new LapTime(new TimeSpan((long)resultRow.average_lap * (TimeSpan.TicksPerMillisecond / 10))); //row.FastestLapTime = new LapTime(TimeSpan.TryParse(PrepareTimeString(line["FastestLapTime"]), culture, out TimeSpan fastLap) ? fastLap : TimeSpan.Zero); row.FastestLapTime = new LapTime(new TimeSpan((long)resultRow.best_lap_time * (TimeSpan.TicksPerMillisecond / 10))); //row.PositionChange = row.StartPosition - row.FinishPosition; row.OldIRating = resultRow.oldi_rating; row.NewIRating = resultRow.newi_rating; row.OldSafetyRating = ((double)resultRow.old_sub_level) / 100; row.NewSafetyRating = ((double)resultRow.new_sub_level) / 100; resultRows.Add(row); } return(resultRows); }
public IEnumerable <ResultRowModel> GetResultRows(string resultName) { List <IRacingResultRow> resultRows = new List <IRacingResultRow>(); var culture = System.Globalization.CultureInfo.GetCultureInfo("de-EN"); foreach (var line in DataLines) { IRacingResultRow row = new IRacingResultRow { //FinalPosition = int.Parse(line["FinPos"]), StartPosition = int.Parse(line["StartPos"]), IRacingId = line["CustID"], FinishPosition = int.Parse(line["FinPos"]), CarNumber = int.Parse(line["Car#"]), ClassId = int.Parse(line["CarClassID"]), Car = line["Car"], CarClass = line["CarClass"], CompletedLaps = int.Parse(line["LapsComp"]), LeadLaps = int.Parse(line["LapsLed"]), FastLapNr = int.TryParse(line["FastLap#"], out int fastLapNr) ? fastLapNr : 0, Incidents = int.Parse(line["Inc"]), Status = (RaceStatusEnum)Enum.Parse(typeof(RaceStatusEnum), line["Out"]), QualifyingTime = new LapTime(TimeSpan.Zero) }; //if (!LeagueClient.LeagueMembers.ToList().Exists(x => x.IRacingId == row.IRacingId)) if (MemberList.Any(x => x.IRacingId == line["CustID"])) { row.Member = MemberList.SingleOrDefault(x => x.IRacingId == line["CustID"]); row.Team = row.Member.Team; } //row.Interval = new LapInterval( // TimeSpan.TryParse("0:" + line["Interval"].Replace("-",""), culture, out TimeSpan intvTime) ? intvTime : TimeSpan.Zero, // int.TryParse(line["Interval"].Replace("L", ""), out int intvLaps) ? intvLaps : 0); var teststrt = line["Interval"]; var test = int.TryParse(line["Interval"].Replace("L", ""), out int intvtest) ? intvtest : 0; row.Interval = new LapInterval(GetTimeSpanFromString(line["Interval"]), int.TryParse(line["Interval"].Replace("L", ""), out int intvLaps) ? intvLaps : 0); row.AvgLapTime = new LapTime(TimeSpan.TryParse(PrepareTimeString(line["AverageLapTime"]), culture, out TimeSpan avgLap) ? avgLap : TimeSpan.Zero); row.FastestLapTime = new LapTime(TimeSpan.TryParse(PrepareTimeString(line["FastestLapTime"]), culture, out TimeSpan fastLap) ? fastLap : TimeSpan.Zero); //row.PositionChange = row.StartPosition - row.FinishPosition; resultRows.Add(row); } return(resultRows); }
public override string ToString() { var builder = new System.Text.StringBuilder(); builder.AppendFormat("{0} {{", nameof(LapCompletedInfo)).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(CarId), CarId.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(LapTime), LapTime.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(Cuts), Cuts.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(GripLevel), GripLevel.ToString()).AppendLine(); builder.AppendFormat(" Leaderboard: "); for (var i = 0; i < Leaderboard.Count; i++) { LeaderboardEntry entry = Leaderboard[i]; builder.AppendFormat(" - {0}: {1}", i, entry).AppendLine(); } builder.AppendFormat("}}").AppendLine(); return(builder.ToString()); }
public void MainPageViewModelTest() { var stopwatch = new Mock <IStopwatch>(); ServiceLocator.Register(stopwatch.Object); var elapsedTime = TimeSpan.FromSeconds(100); stopwatch.Setup(m => m.ElapsedTime).Returns(elapsedTime); var status = StopwatchStatus.Paused; stopwatch.Setup(m => m.Status).Returns(status); var lapTime = new LapTime(1, TimeSpan.MaxValue); var lapTimes = new ReadOnlyObservableCollection <LapTime>(new ObservableCollection <LapTime> { lapTime }); stopwatch.Setup(m => m.LapTimes).Returns(lapTimes); var viewModel = new MainPageViewModel(); Assert.AreEqual(elapsedTime, viewModel.ElapsedTime); Assert.AreEqual(status, viewModel.Status); Assert.IsNotNull(viewModel.LapTimes); Assert.AreEqual(1, viewModel.LapTimes.Count); Assert.AreEqual(lapTime, viewModel.LapTimes[0]); Assert.IsNotNull(viewModel.StartOrStopCommand); Assert.IsTrue(viewModel.StartOrStopCommand.CanExecute(null)); viewModel.StartOrStopCommand.Execute(null); stopwatch.Verify(m => m.Start()); Assert.IsNotNull(viewModel.PauseOrResetCommand); Assert.IsTrue(viewModel.PauseOrResetCommand.CanExecute(null)); }
public void Initialize() { if (!automapperIntialised) { Mapper.Initialize(cfg => { cfg.CreateMap <RaceSession, RaceSessionDTO>() .ReverseMap() .ForMember(src => src.DriverResults, opt => opt.Ignore()) .ForMember(src => src.RaceType, opt => opt.Ignore()) .ForMember(src => src.Track, opt => opt.Ignore()); cfg.CreateMap <DriverResult, DriverResultDTO>() .ForMember(dest => dest.DriverId, opt => opt.MapFrom(src => src.ApplicationUserId)) .ReverseMap() .ForMember(dest => dest.ApplicationUserId, opt => opt.MapFrom(src => src.DriverId)); cfg.CreateMap <Track, TrackDTO>() .ForPath(dest => dest.RecordHolder, opt => opt.MapFrom(src => src.BestLapTime == null ? "No Record set" : src.BestLapTime.ApplicationUser.UserName)) .ForPath(dest => dest.TrackRecord, opt => opt.MapFrom(src => src.BestLapTime == null ? new System.TimeSpan(0, 0, 59) : src.BestLapTime.LapTime.Time)) .ReverseMap() .ForMember(src => src.BestLapTimeId, opt => opt.Ignore()) .ForMember(src => src.ApplicationUsers, opt => opt.Ignore()) .ForMember(src => src.Cars, opt => opt.Ignore()); cfg.CreateMap <Car, CarDTO>() .ForPath(dest => dest.RecordHolder, opt => opt.MapFrom(src => src.BestLapTime == null ? "No Record set" : src.BestLapTime.ApplicationUser.UserName)) .ForPath(dest => dest.TrackRecord, opt => opt.MapFrom(src => src.BestLapTime == null ? new System.TimeSpan(0, 0, 59) : src.BestLapTime.LapTime.Time)) .ReverseMap() .ForPath(src => src.BestLapTimeId, opt => opt.Ignore()); cfg.CreateMap <RaceType, RaceTypeDTO>(); cfg.CreateMap <Driver, DriverDTO>() .ForPath(dest => dest.UserId, opt => opt.MapFrom(src => src.ApplicationUser.Id)) .ForPath(dest => dest.UserName, opt => opt.MapFrom(src => src.ApplicationUser.UserName)) .ForPath(dest => dest.ImageName, opt => opt.MapFrom(src => src.ApplicationUser.ImageName)) .ForMember(dest => dest.SelectedCar, opt => opt.MapFrom(src => src.Car)) .ReverseMap() .ForMember(src => src.ApplicationUserId, opt => opt.MapFrom(dest => dest.UserId)) .ForPath(src => src.ApplicationUser, opt => opt.Ignore()) .ForPath(src => src.Track, opt => opt.Ignore()) .ForMember(src => src.Car, opt => opt.MapFrom(dest => dest.SelectedCar)); cfg.CreateMap <LapTime, LapTimeDTO>() .ReverseMap() .ForMember(src => src.DriverResult, opt => opt.Ignore()); }); automapperIntialised = true; } user = new ApplicationUser(); user.Id = driverId.ToString(); user.UserName = recordHolderName; user.ImageName = imageName; raceType = new RaceType(); raceType.Id = raceTypeId; raceType.Name = raceTypeName; raceType.Rules = raceTypeRules; raceType.Symbol = raceTypeSymbol; laptime = new LapTime(); laptime.Id = "1"; laptime.DriverResultId = driverResultId; laptime.LapNumber = lapNumber; laptime.Time = trackRecord; bestLapTime = new BestLapTime(); bestLapTime.ApplicationUserId = user.Id.ToString(); bestLapTime.ApplicationUser = user; bestLapTime.LapTime = laptime; bestLapTime.CarId = carId; bestLapTime.LapTimeId = laptime.Id; track = new Track(); track.BestLapTime = bestLapTime; track.Length = trackLength; track.Name = trackName; track.Id = trackId; car = new Car(); car.Id = carId; car.TrackId = trackId; car.ImageName = imageName; car.Name = name; car.Track = new Track(); car.BestLapTime = bestLapTime; driver = new Driver(); driver.Id = driverId; driver.ApplicationUser = user; driver.ApplicationUserId = user.Id; driver.Car = car; driver.CarId = car.Id; driver.ControllerId = controllerId; driver.Track = track; driver.TrackId = track.Id; driverResult = new DriverResult(); driverResult.Id = driverResultId; driverResult.ApplicationUser = user; driverResult.ApplicationUserId = user.Id; driverResult.BestLapTime = trackRecord; driverResult.Car = car; driverResult.CarId = car.Id; driverResult.ControllerNumber = controllerId; driverResult.Finished = finished; driverResult.Fuel = fuel; raceSession = new RaceSession(); raceSession.Id = raceSessionId; raceSession.CrashPenalty = crashPenalty; raceSession.EndTime = endTime; raceSession.FuelEnabled = fuelEnabled; raceSession.LapsNotDuration = lapsNotDuration; raceSession.NumberOfDrivers = numDrivers; raceSession.RaceLength = raceLength; raceSession.RaceLimitValue = raceLimitValue; raceSession.RaceType = raceType; raceSession.RaceTypeId = raceType.Id; raceSession.StartTime = startTime; raceSession.Track = track; raceSession.TrackId = trackId; }
public async Task <HttpResponseMessage> PostLapTime(LapTimeDTO[] lapTimeDTOs) { if (!ModelState.IsValid) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } LapTimeDTO first = lapTimeDTOs.FirstOrDefault(); if (first != null) { DriverResultsRepository <DriverResult> driverResultsRepo = new DriverResultsRepository <DriverResult>(); CarsRepository <Car, CarDTO> carsRepo = new CarsRepository <Car, CarDTO>(); TracksRepository <Track> tracksRepo = new TracksRepository <Track>(); BestLapTimesRepository <BestLapTime> bestLapsRepo = new BestLapTimesRepository <BestLapTime>(); DriverResult driverResult = await driverResultsRepo.GetById(first.DriverResultId); BestLapTime usersBestLapInCar = bestLapsRepo.GetForUserId(driverResult.ApplicationUserId).Where(bl => bl.CarId == driverResult.CarId).FirstOrDefault(); TimeSpan fastestLap = driverResult.BestLapTime; BestLapTime bestLapTime = new BestLapTime(); foreach (LapTimeDTO lapTimeDTO in lapTimeDTOs) { LapTime lapTime = new LapTime() { Id = Guid.NewGuid().ToString(), DriverResultId = lapTimeDTO.DriverResultId, LapNumber = lapTimeDTO.LapNumber, Time = lapTimeDTO.Time }; lapTime = await repo.Insert(lapTime); if (lapTime.Time == fastestLap) { bestLapTime = new BestLapTime() { Id = Guid.NewGuid().ToString(), ApplicationUserId = driverResult.ApplicationUserId, CarId = driverResult.CarId, LapTimeId = lapTime.Id, }; if (usersBestLapInCar == null) { bestLapTime = await bestLapsRepo.Insert(bestLapTime); } else if (fastestLap < usersBestLapInCar.LapTime.Time) { EntityState response = await bestLapsRepo.Update(usersBestLapInCar.Id, bestLapTime); } Car car = await carsRepo.GetById(driverResult.CarId); var carsBestLapTime = car?.BestLapTime?.LapTime?.Time; if (car?.BestLapTimeId == null || fastestLap < carsBestLapTime) { car.BestLapTimeId = bestLapTime.Id; await carsRepo.Update(car.Id, car); } Track track = await tracksRepo.GetById(car?.TrackId); var trackBestLap = track?.BestLapTime?.LapTime?.Time; if (track?.BestLapTimeId == null || fastestLap < trackBestLap) { track.BestLapTimeId = bestLapTime.Id; await tracksRepo.Update(track.Id, track); } } } } return(new HttpResponseMessage(HttpStatusCode.OK)); }
public override string ToString() { return($"Car {CarNumber} Lap {LapNumber} - {LapTime.ToString("#0.00")}"); }
void Awake() { laptime = txtLapTime.GetComponent <LapTime>(); }
public async Task <ActionResult <LapTime> > Put(int id, [FromBody] LapTime value) { return(await this.baseController.Put(id, value)); }
public async Task <ActionResult <LapTime> > Post([FromBody] LapTime value) { return(await this.baseController.Post(value)); }