//during quali and free practice - gap for all laps is calculated to the best session time void DriverData::updateGaps(const EventData &ed) { for (int i = 0; i < lapData.size(); ++i) lapData[i].gap = QString::number((lapData[i].lapTime - ed.getSessionRecords().getFastestLap().getTime()).toDouble()); }
//during Q1 when the drivers time is worse than 107% lt server doesn't update his position, we have to do this manually void DriverData::correctPosition(const EventData &ed) { if (ed.getQualiPeriod() == 1 && ed.getSessionRecords().getFastestLap().getTime().isValid() && ((ed.getSessionRecords().getFastestLap().getTime().calc107p() < qualiTimes[0]) || !qualiTimes[0].isValid())) { int position = ed.correctPosition(qualiTimes[0]); if (position >= 1) { pos = position; lastLap.pos = position; sessionRecords.bestQLaps[0].pos = position; int idx = lapData.indexOf(sessionRecords.getBestQualiLap(1)); if (idx >= 0) lapData[idx].pos = position; } // colorData.positionColor() = LTPackets::RED; } }
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(); } } }