From c87a77795d31c20139ba694096955475d2f713c1 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 27 Oct 2022 23:19:08 -0500 Subject: [PATCH] County display for alerts, alert cleanup --- scwx-qt/source/scwx/qt/config/county_database.cpp | 8 ++++++++ .../source/scwx/qt/manager/resource_manager.cpp | 3 +++ .../source/scwx/qt/manager/text_event_manager.cpp | 4 ++-- scwx-qt/source/scwx/qt/map/alert_layer.cpp | 2 +- scwx-qt/source/scwx/qt/model/alert_model.cpp | 15 +++++++++++++-- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/scwx-qt/source/scwx/qt/config/county_database.cpp b/scwx-qt/source/scwx/qt/config/county_database.cpp index 28c4aa6d..99bed961 100644 --- a/scwx-qt/source/scwx/qt/config/county_database.cpp +++ b/scwx-qt/source/scwx/qt/config/county_database.cpp @@ -25,11 +25,17 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_); static const std::string countyDatabaseFilename_ = ":/res/db/counties.db"; +static bool initialized_ {false}; static std::unordered_map countyMap_; static std::shared_mutex countyMutex_; void CountyDatabase::Initialize() { + if (initialized_) + { + return; + } + logger_->debug("Loading database"); // Generate UUID for temporary file @@ -124,6 +130,8 @@ void CountyDatabase::Initialize() // Remove temporary file std::filesystem::remove(countyDatabaseCache); + + initialized_ = true; } std::string GetCountyName(const std::string& id) diff --git a/scwx-qt/source/scwx/qt/manager/resource_manager.cpp b/scwx-qt/source/scwx/qt/manager/resource_manager.cpp index 748a1194..c8cceb1d 100644 --- a/scwx-qt/source/scwx/qt/manager/resource_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/resource_manager.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -19,6 +20,8 @@ void PreLoad() static void LoadFonts() { + config::CountyDatabase::Initialize(); + util::Font::Create(":/res/fonts/din1451alt.ttf"); util::Font::Create(":/res/fonts/din1451alt_g.ttf"); diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp index 3774f293..f2c364c0 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -31,7 +31,7 @@ public: TextEventManager* self_; std::unordered_map>, + std::vector>, types::TextEventHash> textEventMap_; std::shared_mutex textEventMutex_; @@ -131,7 +131,7 @@ void TextEventManager::Impl::HandleMessage( if (it == textEventMap_.cend()) { // If there was no matching event, add the message to a new event - textEventMap_.emplace(key, std::list {message}); + textEventMap_.emplace(key, std::vector {message}); messageIndex = 0; updated = true; } diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index a5231ac2..81379562 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -32,7 +32,7 @@ static QString GetSuffix(awips::Phenomenon phenomenon, bool alertActive); static const QVariantMap kEmptyFeatureCollection_ { {"type", "geojson"}, {"data", QVariant::fromValue(std::list {})}}; -static const std::list kAlertPhenomena_ { +static const std::vector kAlertPhenomena_ { awips::Phenomenon::Marine, awips::Phenomenon::FlashFlood, awips::Phenomenon::SevereThunderstorm, diff --git a/scwx-qt/source/scwx/qt/model/alert_model.cpp b/scwx-qt/source/scwx/qt/model/alert_model.cpp index c14ce460..902e5ac7 100644 --- a/scwx-qt/source/scwx/qt/model/alert_model.cpp +++ b/scwx-qt/source/scwx/qt/model/alert_model.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -174,7 +175,7 @@ AlertModel::headerData(int section, Qt::Orientation orientation, int role) const case kColumnState: return tr("State"); case kColumnCounties: - return tr("Counties"); + return tr("Counties / Areas"); case kColumnStartTime: return tr("Start Time"); case kColumnEndTime: @@ -287,7 +288,17 @@ std::string AlertModelImpl::GetCounties(const types::TextEventKey& key) auto& lastMessage = messageList.back(); size_t segmentCount = lastMessage->segment_count(); auto lastSegment = lastMessage->segment(segmentCount - 1); - return util::ToString(lastSegment->header_->ugc_.fips_ids()); + auto fipsIds = lastSegment->header_->ugc_.fips_ids(); + + std::vector counties; + counties.reserve(fipsIds.size()); + for (auto& id : fipsIds) + { + counties.push_back(config::CountyDatabase::GetCountyName(id)); + } + std::sort(counties.begin(), counties.end()); + + return util::ToString(counties); } std::string AlertModelImpl::GetState(const types::TextEventKey& key)