public static ParticipantLapTimes InsertIfNewTime(PCars2ParticipantStatsInfo newTime, ParticipantLapTimes currentTimes) { if (IsOutLap(newTime)) { return(currentTimes); } else if (IsFirstSector(currentTimes)) { var toInsert = new ParticipantLapTime(-1, newTime.lastSectorTime, -1, -1); var newLapTimes = currentTimes.lapTimes.Concat(0, toInsert); return(new ParticipantLapTimes(currentTimes.Id, currentTimes.SessionId, currentTimes.SessionType, currentTimes.participantIndex, newLapTimes)); } else if (IsNewSector1(newTime, currentTimes)) { var toInsert = new ParticipantLapTime(-1, newTime.lastSectorTime, -1, -1); var newLapTimes = currentTimes.lapTimes.Concat(currentTimes.lapTimes.Keys.Max() + 1, toInsert); return(new ParticipantLapTimes(currentTimes.Id, currentTimes.SessionId, currentTimes.SessionType, currentTimes.participantIndex, newLapTimes)); } else if (IsNewSector2(newTime, currentTimes)) { var toUpdate = new ParticipantLapTime(-1, CurrentLap(currentTimes).sector1Time, newTime.lastSectorTime, -1); var newLapTimes = currentTimes.lapTimes.Except(currentTimes.lapTimes.Keys.Max()).Concat(currentTimes.lapTimes.Keys.Max(), toUpdate); return(new ParticipantLapTimes(currentTimes.Id, currentTimes.SessionId, currentTimes.SessionType, currentTimes.participantIndex, newLapTimes)); } else if (IsNewSector3(newTime, currentTimes)) { var toUpdate = new ParticipantLapTime(newTime.lastLapTime, CurrentLap(currentTimes).sector1Time, CurrentLap(currentTimes).sector2Time, newTime.lastSectorTime); var newLapTimes = currentTimes.lapTimes.Except(currentTimes.lapTimes.Keys.Max()).Concat(currentTimes.lapTimes.Keys.Max(), toUpdate); return(new ParticipantLapTimes(currentTimes.Id, currentTimes.SessionId, currentTimes.SessionType, currentTimes.participantIndex, newLapTimes)); } else { return(currentTimes); } }
private static bool IsNewSector3(PCars2ParticipantStatsInfo time, ParticipantLapTimes currentTime) { var lapTimes = currentTime.lapTimes; return(lapTimes[lapTimes.Keys.Max()].sector2Time > 0 && lapTimes[lapTimes.Keys.Max()].sector3Time <= 0 && lapTimes[lapTimes.Keys.Max()].sector2Time != time.lastSectorTime); }
private static bool IsOutLap(PCars2ParticipantStatsInfo time) { return(time.lastSectorTime < 0); }