mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
refs #395, improved synchronization of booked and online stations
* moved sync functionality into CAtcStation * consolidated function names
This commit is contained in:
committed by
Mathew Sutcliffe
parent
f7158f17f9
commit
79e2a7b805
@@ -180,12 +180,88 @@ namespace BlackMisc
|
||||
|
||||
void CAtcStation::syncronizeControllerData(CAtcStation &otherStation)
|
||||
{
|
||||
if (this->m_controller == otherStation.getController()) return;
|
||||
if (this->m_controller == otherStation.getController()) { return; }
|
||||
CUser otherController = otherStation.getController();
|
||||
this->m_controller.syncronizeData(otherController);
|
||||
otherStation.setController(otherController);
|
||||
}
|
||||
|
||||
void CAtcStation::syncronizeWithBookedStation(CAtcStation &bookedStation)
|
||||
{
|
||||
if (bookedStation.getCallsign() != this->getCallsign()) { return; }
|
||||
|
||||
// from online to booking
|
||||
bookedStation.setOnline(true);
|
||||
bookedStation.setFrequency(this->getFrequency());
|
||||
|
||||
// Logoff Zulu Time set?
|
||||
// comes directly from the online controller and is most likely more accurate
|
||||
if (!this->getBookedUntilUtc().isNull())
|
||||
{
|
||||
bookedStation.setBookedUntilUtc(this->getBookedUntilUtc());
|
||||
}
|
||||
|
||||
// from booking to online
|
||||
// booked now stations have valid data and need no update
|
||||
if (!this->isBookedNow() && bookedStation.hasValidBookingTimes())
|
||||
{
|
||||
if (this->hasValidBookingTimes())
|
||||
{
|
||||
if (bookedStation.isBookedNow())
|
||||
{
|
||||
// can't get any better, we just copy from / to over
|
||||
this->setBookedFromUntil(bookedStation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we already have some booking dates, we will verify those now
|
||||
// and will set the most appropriate booking dates
|
||||
CTime timeDiffBooking(bookedStation.bookedWhen());
|
||||
CTime timeDiffOnline(this->bookedWhen()); // diff to now
|
||||
if (timeDiffBooking.isNegativeWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||
{
|
||||
// both in past
|
||||
if (timeDiffBooking > timeDiffOnline)
|
||||
{
|
||||
this->setBookedFromUntil(bookedStation);
|
||||
}
|
||||
}
|
||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isPositiveWithEpsilonConsidered())
|
||||
{
|
||||
// both in future
|
||||
if (timeDiffBooking < timeDiffOnline)
|
||||
{
|
||||
this->setBookedFromUntil(bookedStation);
|
||||
}
|
||||
}
|
||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||
{
|
||||
// future booking is better than past booking
|
||||
this->setBookedFromUntil(bookedStation);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no booking info so far, so we just copy over
|
||||
this->setBookedFromUntil(bookedStation);
|
||||
}
|
||||
}
|
||||
|
||||
// both ways
|
||||
this->syncronizeControllerData(bookedStation);
|
||||
if (this->hasValidDistance())
|
||||
{
|
||||
bookedStation.setDistanceToOwnAircraft(this->getDistanceToOwnAircraft());
|
||||
bookedStation.setBearingToOwnAircraft(this->getBearingToOwnAircraft());
|
||||
}
|
||||
else if (bookedStation.hasValidDistance())
|
||||
{
|
||||
this->setDistanceToOwnAircraft(bookedStation.getDistanceToOwnAircraft());
|
||||
this->setBearingToOwnAircraft(bookedStation.getBearingToOwnAircraft());
|
||||
}
|
||||
}
|
||||
|
||||
bool CAtcStation::isInRange() const
|
||||
{
|
||||
if (m_range.isNull() || !hasValidDistance()) { return false; }
|
||||
@@ -206,10 +282,10 @@ namespace BlackMisc
|
||||
|
||||
bool CAtcStation::isBookedNow() const
|
||||
{
|
||||
if (!this->hasValidBookingTimes()) return false;
|
||||
if (!this->hasValidBookingTimes()) { return false; }
|
||||
QDateTime now = QDateTime::currentDateTimeUtc();
|
||||
if (this->m_bookedFromUtc > now) return false;
|
||||
if (now > this->m_bookedUntilUtc) return false;
|
||||
if (this->m_bookedFromUtc > now) { return false; }
|
||||
if (now > this->m_bookedUntilUtc) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,9 +134,15 @@ namespace BlackMisc
|
||||
void setPosition(const BlackMisc::Geo::CCoordinateGeodetic &position) { this->m_position = position; }
|
||||
|
||||
//! Syncronize controller data
|
||||
//! Updates two stations (namely a booked and online ATC station) with complementary data
|
||||
//! Updates two stations (normally a booked and online ATC station) with complementary data
|
||||
void syncronizeControllerData(CAtcStation &otherStation);
|
||||
|
||||
|
||||
//! Syncronize station data
|
||||
//! Updates the two stations (a booked and online ATC station) with complementary data
|
||||
//! \pre this object is the online station, the passed station the booked station
|
||||
void syncronizeWithBookedStation(CAtcStation &bookedStation);
|
||||
|
||||
//! Get the radius of the controller's area of visibility.
|
||||
const BlackMisc::PhysicalQuantities::CLength &getRange() const { return m_range; }
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackMisc
|
||||
return this->findBy(Predicates::MemberValid(&CAtcStation::getController)).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||
}
|
||||
|
||||
int CAtcStationList::mergeWithBooking(CAtcStation &bookedAtcStation)
|
||||
int CAtcStationList::syncronizeWithBookedStation(CAtcStation &bookedAtcStation)
|
||||
{
|
||||
int c = 0;
|
||||
bookedAtcStation.setOnline(false); // reset
|
||||
@@ -61,105 +61,16 @@ namespace BlackMisc
|
||||
|
||||
for (auto i = this->begin(); i != this->end(); ++i)
|
||||
{
|
||||
CAtcStation onlineAtcStation = *i;
|
||||
if (onlineAtcStation.getCallsign() != bookedAtcStation.getCallsign()) continue;
|
||||
|
||||
// from online to booking
|
||||
bookedAtcStation.setOnline(true);
|
||||
bookedAtcStation.setFrequency(onlineAtcStation.getFrequency());
|
||||
|
||||
// Logoff Zulu Time set?
|
||||
// comes directly from the online controller and is most likely more accurate
|
||||
if (!onlineAtcStation.getBookedUntilUtc().isNull())
|
||||
bookedAtcStation.setBookedUntilUtc(onlineAtcStation.getBookedUntilUtc());
|
||||
|
||||
// from booking to online
|
||||
if (!onlineAtcStation.isBookedNow() && bookedAtcStation.hasValidBookingTimes())
|
||||
{
|
||||
if (onlineAtcStation.hasValidBookingTimes())
|
||||
{
|
||||
if (bookedAtcStation.isBookedNow())
|
||||
{
|
||||
// can't get any better
|
||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we already have some booking dates
|
||||
CTime timeDiffBooking = bookedAtcStation.bookedWhen();
|
||||
CTime timeDiffOnline = onlineAtcStation.bookedWhen();
|
||||
if (timeDiffBooking.isNegativeWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||
{
|
||||
// both in past
|
||||
if (timeDiffBooking > timeDiffOnline)
|
||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
||||
}
|
||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isPositiveWithEpsilonConsidered())
|
||||
{
|
||||
// both in future
|
||||
if (timeDiffBooking < timeDiffOnline)
|
||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
||||
}
|
||||
else if (timeDiffBooking.isPositiveWithEpsilonConsidered() && timeDiffOnline.isNegativeWithEpsilonConsidered())
|
||||
{
|
||||
// future booking is better than past booking
|
||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no booking info so far
|
||||
onlineAtcStation.setBookedFromUntil(bookedAtcStation);
|
||||
}
|
||||
}
|
||||
|
||||
// both ways
|
||||
onlineAtcStation.syncronizeControllerData(bookedAtcStation);
|
||||
if (onlineAtcStation.hasValidDistance())
|
||||
{
|
||||
bookedAtcStation.setDistanceToOwnAircraft(onlineAtcStation.getDistanceToOwnAircraft());
|
||||
bookedAtcStation.setBearingToOwnAircraft(onlineAtcStation.getBearingToOwnAircraft());
|
||||
}
|
||||
else if (bookedAtcStation.hasValidDistance())
|
||||
{
|
||||
onlineAtcStation.setDistanceToOwnAircraft(bookedAtcStation.getDistanceToOwnAircraft());
|
||||
onlineAtcStation.setBearingToOwnAircraft(bookedAtcStation.getBearingToOwnAircraft());
|
||||
}
|
||||
|
||||
// update
|
||||
*i = onlineAtcStation;
|
||||
if (i->getCallsign() != bookedAtcStation.getCallsign()) { continue; }
|
||||
i->syncronizeWithBookedStation(bookedAtcStation);
|
||||
c++;
|
||||
}
|
||||
|
||||
// normally 1 expected, as I should find
|
||||
// only one online station for this booking
|
||||
Q_ASSERT(c == 0 || c == 1);
|
||||
Q_ASSERT_X(c == 0 || c == 1, Q_FUNC_INFO, "Found >1 matching station");
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CAtcStationList::updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const
|
||||
{
|
||||
if (this->isEmpty()) return false;
|
||||
if (stationToBeUpdated.hasValidRealName() && stationToBeUpdated.hasValidId() && stationToBeUpdated.hasValidFrequency()) return 0;
|
||||
|
||||
CAtcStation dataFileStation = this->findFirstByCallsign(stationToBeUpdated.getCallsign());
|
||||
if (dataFileStation.getCallsign().isEmpty()) return false; // not found
|
||||
|
||||
if (!stationToBeUpdated.hasValidRealName() || !stationToBeUpdated.hasValidId())
|
||||
{
|
||||
CUser user = stationToBeUpdated.getController();
|
||||
if (!stationToBeUpdated.hasValidRealName()) user.setRealName(dataFileStation.getControllerRealName());
|
||||
if (!stationToBeUpdated.hasValidId()) user.setId(dataFileStation.getControllerId());
|
||||
stationToBeUpdated.setController(user);
|
||||
}
|
||||
|
||||
if (!stationToBeUpdated.hasValidFrequency())
|
||||
{
|
||||
stationToBeUpdated.setFrequency(dataFileStation.getFrequency());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -50,14 +50,10 @@ namespace BlackMisc
|
||||
//! All controllers (with valid data)
|
||||
BlackMisc::Network::CUserList getControllers() const;
|
||||
|
||||
//! Merge with ATC station representing booking information.
|
||||
//! Syncronize with ATC station representing booking information.
|
||||
//! Both sides (booking, online station) will be updated.
|
||||
//! \remarks Can be used if the stored data in this list are online ATC stations
|
||||
int mergeWithBooking(CAtcStation &bookedAtcStation);
|
||||
|
||||
//! Merge with the data from the VATSIM data file
|
||||
//! \remarks Can be used if the stored data in this list are VATSIM data file stations
|
||||
bool updateFromVatsimDataFileStation(CAtcStation &stationToBeUpdated) const;
|
||||
//! \pre Can be used only if the stored data in this list are online ATC stations
|
||||
int syncronizeWithBookedStation(CAtcStation &bookedAtcStation);
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
QVariant toQVariant() const { return QVariant::fromValue(*this); }
|
||||
|
||||
Reference in New Issue
Block a user