public InstanceResultViewModel(string instanceName, RaceResult result, RaceTime time, bool isPresented = false) { this.InstanceName = instanceName; this.Result = result; this.Time = time; this.IsPresented = isPresented; }
public bool AddRaceTime(RaceTime raceTime) { if (!IsOpen()) { throw new Exception("No excel link"); } try { if (raceTime.Departure != null) { _sheet.Cells[raceTime.Order, 1] = raceTime.Order; _sheet.Cells[raceTime.Order, 2] = raceTime.Departure; } else if (raceTime.Arrival != null) { _sheet.Cells[raceTime.Order, 3] = raceTime.Order; _sheet.Cells[raceTime.Order, 4] = raceTime.Arrival; } return(true); } catch (Exception) { throw new RaceTimeNotAddedException(raceTime); } }
public override RaceTime Interpret(SerialPort serialPort) { RaceTime raceTime = new RaceTime(); var message = serialPort.ReadLine(); int command = message[0]; if (command != 'T') { return(raceTime); } var content = message.Substring(1); var orderNumber = content.Substring(7, 3); raceTime.Order = int.Parse(orderNumber); string canal = content.Substring(12, 1); //'Canal.Text = Canal //var time = content.Substring(4, 6) + "." + content.Substring(10, 3); var time = content.Substring(14, 2) + content.Substring(17, 2) + content.Substring(20, 9); //time = string.Format("{0:00:00:00.000}", time); time = time.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)); time = string.Format("{0:00:00:00.000}", double.Parse(time)); if (canal == "1") { raceTime.Departure = time; } else if (canal == "2") { raceTime.Arrival = time; } /* * while (serialPort.ReadBufferSize > 0)// '** Exécute tant que le buffer série en plein * { * switch (IdTrame)// '** Affiche les résultats dans la liste selon la fonction active * { * case "A": * case "S": * break; * default: * MsgBox("Ce chronomètre n'est pas en mode (Split)" & Chr(13) & "ou ce n'est pas un TAG HEUER CP520", MsgBoxStyle.Critical, "Erreur"); * M_Chrono_com_Click(M_Chrono_com.Item((1)), New System.EventArgs()); * Exit Sub; * break; * } * } */ return(raceTime); }
public override int GetHashCode() { unchecked { var hashCode = Age; hashCode = (hashCode * 397) ^ (int)Gender; hashCode = (hashCode * 397) ^ RaceTime.GetHashCode(); hashCode = (hashCode * 397) ^ CorralId.GetHashCode(); hashCode = (hashCode * 397) ^ BIBNumber; hashCode = (hashCode * 397) ^ (CorralName != null ? CorralName.GetHashCode() : 0); return(hashCode); } }
public RaceTimeViewModel(RaceTime raceTime) { RaceTime = raceTime; if (IsInDesignMode) { RaceTime = new RaceTime { Order = 3, Departure = "00:01:20.6" }; } }
private void RaceTime_Tick(object sender, EventArgs e) { for (int i = 0; i < Data.chevilries.Length; i++) { Data.chevilries[Data.rand.Next(0, 4)].isAccelerating(); if (Data.chevilries[i].isAccelerating()) { RaceTime.Stop(); RaceTime.Enabled = false; StartRace.Enabled = true; announceWinner(i + 1); } } }
private void RaceTime_Tick(object sender, EventArgs e) { for (int i = 0; i < Storage.shuriken.Length; i++) { Storage.shuriken[Storage.rand.Next(0, 4)].isAccelerating(); if (Storage.shuriken[i].isAccelerating()) { RaceTime.Stop(); RaceTime.Enabled = false; BeginRace.Enabled = true; announceWinner(i + 1); } } }
private static void CommitRace(IDistance distance, IEnumerable <DistanceCombination> combinations, Race race, IDistanceDisciplineCalculator calculator, string headerLine, int timeInfoOffset) { TimeInfo timeInfo; if (!TryParseTimeInfo(headerLine.Substring(timeInfoOffset, 2), out timeInfo)) { timeInfo = TimeInfo.None; } race.PresentedInstanceName = ResultInstanceName; var result = race.Results?.SingleOrDefault(r => r.InstanceName == ResultInstanceName); var finalLap = race.Laps?.Presented().ElementAtOrDefault(calculator.Laps(distance) - 1); if (result == null || finalLap == null) { return; } var time = new RaceTime { Race = race, InstanceName = ResultInstanceName, PresentationSource = finalLap.PresentationSource, Time = finalLap.Time, TimeInfo = timeInfo }; if (race.Times == null) { race.Times = new Collection <RaceTime>(); } race.Times.Add(time); var classificationWeight = combinations.FirstOrDefault()?.ClassificationWeight ?? DefaultClassificationWeight; if (calculator.CanCalculateRacePoints(distance, classificationWeight, distance.ClassificationPrecision, result, time)) { result.Points = calculator.CalculateRacePoints(distance, classificationWeight, distance.ClassificationPrecision, result, time); } }
public override string ToString() { return(EventId.ToString() + "," + MarketId.ToString() + "," + (MeetingDate > DateTime.MinValue ? MeetingDate.ToString("yyyy-MM-dd") : @"\N") + "," + DayOfWeek.ToString() + "," + CountryCode.ToString() + "," + Track.ToString() + "," + (RaceTime > DateTime.MinValue ? RaceTime.ToString("yyyy-MM-dd HH:mm:ss") : @"\N") + "," + (OffTime > DateTime.MinValue ? OffTime.ToString("yyyy-MM-dd HH:mm:ss") : @"\N") + "," + MarketName.ToString() + "," + Entries.ToString() + "," + Runners.ToString() + "," + SelectionId.ToString() + "," + SelectionName.ToString() + "," + (Bsp > 1 ? Bsp.ToString() : @"\N") + "," + (NonRunner ? "1" : "0") + "," + (RemovalTime > DateTime.MinValue ? RemovalTime.ToString("yyyy-MM-dd HH:mm:ss") : @"\N") + "," + (NonRunner ? ReductionFactor.ToString() : @"\N") ); }
public async Task UpdatePointsAsync(RaceResult result, RaceTime raceTime) { // TODO: The first DC is selected when a competitor is part of multiple distance combinations that use this distance. This is an unwanted edge case anyway var distance = result.Race.Distance; var distanceCombination = await DistanceCombinations(distance.CompetitionId, result.Race.DistanceId, result.Race.CompetitorId).FirstOrDefaultAsync(); if (distanceCombination != null) { var expert = expertManager.Find(distance.Discipline); if (expert != null) { var canCalculateRacePoints = expert.Calculator.CanCalculateRacePoints(distance, distanceCombination.ClassificationWeight, distance.ClassificationPrecision, result, raceTime); if (canCalculateRacePoints) { result.Points = expert.Calculator.CalculateRacePoints(distance, distanceCombination.ClassificationWeight, distance.ClassificationPrecision, result, raceTime); return; } } } result.Points = null; }
private void StartRace_Click(object sender, EventArgs e) { RaceTime.Start(); StartRace.Enabled = false; }
public async Task PresentUserResultAsync(Race race, RaceStatus status, TimeInvalidReason?timeInvalidReason, TimeSpan?time, TimeInfo timeInfo, IList <TimeSpan> lapTimes) { Debug.Assert(race.Distance != null, "race.Distance != null"); if (status == RaceStatus.Done && !timeInvalidReason.HasValue && !time.HasValue) { throw new InvalidRaceResultException(); } using (var transaction = context.BeginTransaction(IsolationLevel.RepeatableRead)) try { foreach (var raceResult in race.Results.Where(r => r.InstanceName == UserInstanceName).ToList()) { context.RaceResults.Remove(raceResult); } foreach (var raceTime in race.Times.Where(r => r.InstanceName == UserInstanceName).ToList()) { context.RaceTimes.Remove(raceTime); } foreach (var raceLap in race.Laps.Where(l => l.InstanceName == UserInstanceName).ToList()) { context.RaceLaps.Remove(raceLap); } race.PresentedInstanceName = UserInstanceName; var result = new RaceResult { Race = race, InstanceName = UserInstanceName, Status = status, TimeInvalidReason = timeInvalidReason }; if (time.HasValue) { var raceTime = new RaceTime { Race = race, PresentationSource = PresentationSource.User, InstanceName = UserInstanceName, Time = time.Value, TimeInfo = timeInfo }; race.Times.Add(raceTime); await UpdatePointsAsync(result, raceTime); if (lapTimes != null) { var now = DateTime.UtcNow; foreach (var lapTime in lapTimes) { race.Laps.Add(new RaceLap { Race = race, PresentationSource = PresentationSource.User, InstanceName = UserInstanceName, Time = lapTime, When = now - time.Value + lapTime, Flags = RaceEventFlags.Inserted | RaceEventFlags.Present }); } } } race.Results.Add(result); race.Distance.LastRaceCommitted = DateTime.UtcNow; await context.SaveChangesAsync(); foreach (var combination in await DistanceCombinations(race.Distance.CompetitionId, race.DistanceId).ToListAsync()) { recorder.RecordEvent(new DistanceCombinationClassificationChangedEvent(combination)); } transaction.Commit(); } catch { transaction.Rollback(); throw; } }
public RaceTimeNotAddedException(RaceTime raceTime) { _raceTime = raceTime; }