Handle alert audio when location method is county

This commit is contained in:
Dan Paulat 2023-12-08 06:00:51 -06:00
parent bdb859480f
commit e2c8b3c7db

View file

@ -48,7 +48,8 @@ public:
~Impl() { threadPool_.join(); } ~Impl() { threadPool_.join(); }
common::Coordinate CurrentCoordinate() const; common::Coordinate
CurrentCoordinate(types::LocationMethod locationMethod) const;
void HandleAlert(const types::TextEventKey& key, size_t messageIndex) const; void HandleAlert(const types::TextEventKey& key, size_t messageIndex) const;
void UpdateLocationTracking(const std::string& value) const; void UpdateLocationTracking(const std::string& value) const;
@ -68,14 +69,12 @@ public:
AlertManager::AlertManager() : p(std::make_unique<Impl>(this)) {} AlertManager::AlertManager() : p(std::make_unique<Impl>(this)) {}
AlertManager::~AlertManager() = default; AlertManager::~AlertManager() = default;
common::Coordinate AlertManager::Impl::CurrentCoordinate() const common::Coordinate AlertManager::Impl::CurrentCoordinate(
types::LocationMethod locationMethod) const
{ {
settings::AudioSettings& audioSettings = settings::AudioSettings::Instance(); settings::AudioSettings& audioSettings = settings::AudioSettings::Instance();
common::Coordinate coordinate {}; common::Coordinate coordinate {};
types::LocationMethod locationMethod = types::GetLocationMethod(
audioSettings.alert_location_method().GetValue());
if (locationMethod == types::LocationMethod::Fixed) if (locationMethod == types::LocationMethod::Fixed)
{ {
coordinate.latitude_ = audioSettings.alert_latitude().GetValue(); coordinate.latitude_ = audioSettings.alert_latitude().GetValue();
@ -105,7 +104,10 @@ void AlertManager::Impl::HandleAlert(const types::TextEventKey& key,
} }
settings::AudioSettings& audioSettings = settings::AudioSettings::Instance(); settings::AudioSettings& audioSettings = settings::AudioSettings::Instance();
common::Coordinate currentCoordinate = CurrentCoordinate(); types::LocationMethod locationMethod = types::GetLocationMethod(
audioSettings.alert_location_method().GetValue());
common::Coordinate currentCoordinate = CurrentCoordinate(locationMethod);
std::string alertCounty = audioSettings.alert_county().GetValue();
auto message = textEventManager_->message_list(key).at(messageIndex); auto message = textEventManager_->message_list(key).at(messageIndex);
@ -130,11 +132,27 @@ void AlertManager::Impl::HandleAlert(const types::TextEventKey& key,
continue; continue;
} }
// Determine if the alert is active at the current coordinte bool activeAtLocation = false;
auto alertCoordinates = segment->codedLocation_->coordinates();
if (util::GeographicLib::AreaContainsPoint(alertCoordinates, if (locationMethod == types::LocationMethod::Fixed ||
currentCoordinate)) locationMethod == types::LocationMethod::Track)
{
// Determine if the alert is active at the current coordinte
auto alertCoordinates = segment->codedLocation_->coordinates();
activeAtLocation = util::GeographicLib::AreaContainsPoint(
alertCoordinates, currentCoordinate);
}
else if (locationMethod == types::LocationMethod::County)
{
// Determine if the alert contains the current county
auto fipsIds = segment->header_->ugc_.fips_ids();
auto it = std::find(fipsIds.cbegin(), fipsIds.cend(), alertCounty);
activeAtLocation = it != fipsIds.cend();
}
if (activeAtLocation)
{ {
logger_->info("Alert active at current location: {} {}.{} {}", logger_->info("Alert active at current location: {} {}.{} {}",
vtec.pVtec_.office_id(), vtec.pVtec_.office_id(),