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); }
public static BsonDocument ToBson(ParticipantLapTimes entity) { var bsonDoc = new BsonDocument(); bsonDoc["_id"] = entity.Id.AsLiteDB(); bsonDoc["sessionId"] = entity.SessionId.AsLiteDB(); bsonDoc["sessionType"] = entity.SessionType.ToString(); bsonDoc["participantIndex"] = new BsonValue(entity.participantIndex); bsonDoc["lapTimes"] = new BsonArray(entity.lapTimes.Select(lapTime => { var lapTimeDoc = new BsonDocument(); lapTimeDoc["lapNumber"] = new BsonValue(lapTime.Key); lapTimeDoc["lapTime"] = new BsonValue(lapTime.Value.lapTime); lapTimeDoc["sector1Time"] = new BsonValue(lapTime.Value.sector1Time); lapTimeDoc["sector2Time"] = new BsonValue(lapTime.Value.sector2Time); lapTimeDoc["sector3Time"] = new BsonValue(lapTime.Value.sector3Time); return(lapTimeDoc); }).ToArray()); return(bsonDoc); }
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 IsFirstSector(ParticipantLapTimes currentTime) { return(!currentTime.lapTimes.Any()); }
private static ParticipantLapTime CurrentLap(ParticipantLapTimes currentTimes) { return(currentTimes.lapTimes[currentTimes.lapTimes.Keys.Max()]); }