void DriverData::addInLap(const EventData &ed) { if (lastLap.lapNum <= 0) return; lapData.append(lastLap); if (outLap == true) lapData.last().lapTime = LapTime("INST. LAP"); else lapData.last().lapTime = LapTime("IN LAP"); lapData.last().qualiLapExtraData.sessionTime = ed.getRemainingTime(); lapData.last().practiceLapExtraData.sessionTime = ed.getRemainingTime(); if (ed.getEventType() == LTPackets::QUALI_EVENT) { int qPeriod = ed.getQualiPeriod() > 0 ? ed.getQualiPeriod() : 1; lastLap.qualiLapExtraData.qualiPeriod = qPeriod; lapData.last().qualiLapExtraData.qualiPeriod = qPeriod; } updateSectorRecords(); }
void DriverData::addFPQLap(const EventData &ed) { //during practice and quali we only save timed laps if ((lastLap.lapTime.toString() != "") && (lapData.empty() || (/*(lastLap.numLap > lapData.last().numLap) &&*/ lastLap.getSectorTime(1).toString() != "" && lastLap.getSectorTime(2).toString() != "" && lastLap.getSectorTime(3).toString() != ""))) { bool correction = false; //sometimes servers messes up with lap numbers, we catch this if the numlap is <= than the last one if (!lapData.isEmpty() && lastLap.lapNum+1 <= lapData.last().lapNum) { correction = true; bool approx = lapData.last().qualiLapExtraData.approxLap || lapData.last().practiceLapExtraData.approxLap; int numlap = lapData.last().lapNum-1; lapData.last() = LapData(lastLap); lapData.last().qualiLapExtraData.approxLap = approx; lapData.last().practiceLapExtraData.approxLap = approx; if (lapData.size() > 1) lapData.last().lapNum = numlap; if (sessionRecords.bestLap.lapNum == numlap) sessionRecords.bestLap.lapNum = lapData.last().lapNum; } else { //if decryption fails, replace the garbage we obtained with the best lap time if (lastLap.lapTime.toString() != "" && !lastLap.lapTime.isValid()) lastLap.lapTime = sessionRecords.bestLap.lapTime; lastLap.qualiLapExtraData.sessionTime = ed.getRemainingTime(); lastLap.practiceLapExtraData.sessionTime = ed.getRemainingTime(); lapData.append(lastLap); lapData.last().lapNum--; if (ed.getEventType() == LTPackets::QUALI_EVENT) { int qPeriod = ed.getQualiPeriod() > 0 ? ed.getQualiPeriod() : 1; lastLap.qualiLapExtraData.qualiPeriod = qPeriod; lapData.last().qualiLapExtraData.qualiPeriod = qPeriod; } updateSectorRecords(); } if (!correction) { if (ed.getEventType() == LTPackets::PRACTICE_EVENT) { if (lastLap < sessionRecords.bestLap) sessionRecords.bestLap = lapData.last(); else if (lastLap.lapTime == sessionRecords.bestLap.lapTime) { lapData.last().lapTime = LapData::sumSectors(lapData.last().getSectorTime(1).toString(), lapData.last().getSectorTime(2).toString(), lapData.last().getSectorTime(3).toString()); lapData.last().practiceLapExtraData.approxLap = true; } else lapData.last().practiceLapExtraData.approxLap = false; } else if (ed.getEventType() == LTPackets::QUALI_EVENT) { if (lastLap < sessionRecords.bestLap) sessionRecords.bestLap = lapData.last(); if (lastLap < sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] || !sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1].getTime().isValid()) { sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] = lapData.last(); if (sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1] < sessionRecords.bestLap) sessionRecords.bestLap = sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1]; } //if the current lap time is the same as the best lap, probably the driver hasn't improved so we have to calculate the real lap time from the sectors time else if (lastLap.lapTime == sessionRecords.bestQLaps[lastLap.qualiLapExtraData.qualiPeriod-1].lapTime) { lapData.last().lapTime = LapData::sumSectors(lapData.last().getSectorTime(1).toString(), lapData.last().getSectorTime(2).toString(), lapData.last().getSectorTime(3).toString()); lapData.last().qualiLapExtraData.approxLap = true; } else lapData.last().qualiLapExtraData.approxLap = false; correctPosition(ed); } } lapData.last().gap = QString::number((lapData.last().lapTime - ed.getSessionRecords().getFastestLap().getTime()).toDouble()); posHistory.append(lastLap.pos); outLap = false; } //saving in and out laps else if (lastLap.lapNum > 1) { if (lapData.isEmpty() || (!lapData.isEmpty() && lapData.last().lapNum < lastLap.lapNum-1)) { if (outLap == true || inPits == false) { lapData.append(lastLap); lapData.last().lapTime = LapTime("OUT LAP"); if (inPits == true) lapData.last().lapTime = LapTime("INST. LAP"); lapData.last().lapNum--; outLap = false; } else { lapData.append(lastLap); lapData.last().lapTime = LapTime("IN LAP"); lapData.last().lapNum--; } lapData.last().qualiLapExtraData.sessionTime = ed.getRemainingTime(); lapData.last().practiceLapExtraData.sessionTime = ed.getRemainingTime(); if (ed.getEventType() == LTPackets::QUALI_EVENT) { int qPeriod = ed.getQualiPeriod() > 0 ? ed.getQualiPeriod() : 1; lastLap.qualiLapExtraData.qualiPeriod = qPeriod; lapData.last().qualiLapExtraData.qualiPeriod = qPeriod; } updateSectorRecords(); } } }