diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 71f4d00c..d213b4fd 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -1018,6 +1018,7 @@ void MainWindowImpl::ConnectAnimationSignals() for (auto map : maps_) { map->SelectTime(dateTime); + textEventManager_->SelectTime(dateTime); QMetaObject::invokeMethod( map, static_cast(&QWidget::update)); } 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 d76212fd..dffdb6bf 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,9 @@ static constexpr std::chrono::hours kInitialLoadHistoryDuration_ = static constexpr std::chrono::hours kDefaultLoadHistoryDuration_ = std::chrono::hours {1}; +static const std::array kPils_ = { + "TOR", "SVR", "SVS", "FFW", "FFS"}; + class TextEventManager::Impl { public: @@ -82,10 +86,17 @@ public: void HandleMessage(const std::shared_ptr& message); + void LoadArchive(std::chrono::sys_days date, const std::string& pil); + void LoadArchives(std::chrono::sys_days date); void RefreshAsync(); void Refresh(); - boost::asio::thread_pool threadPool_ {1u}; + // Thread pool sized for: + // - Live Refresh (1x) + // - Archive Loading (15x) + // - 3 day window (3x) + // - TOR, SVR, SVS, FFW, FFS (5x) + boost::asio::thread_pool threadPool_ {16u}; TextEventManager* self_; @@ -98,6 +109,8 @@ public: textEventMap_; std::shared_mutex textEventMutex_; + std::unique_ptr iemApiProvider_ { + std::make_unique()}; std::shared_ptr warningsProvider_ {nullptr}; std::chrono::hours loadHistoryDuration_ {kInitialLoadHistoryDuration_}; std::chrono::sys_time prevLoadTime_ {}; @@ -171,6 +184,20 @@ void TextEventManager::LoadFile(const std::string& filename) }); } +void TextEventManager::SelectTime( + std::chrono::system_clock::time_point dateTime) +{ + const auto today = std::chrono::floor(dateTime); + const auto yesterday = today - std::chrono::days {1}; + const auto tomorrow = today + std::chrono::days {1}; + const auto dates = {yesterday, today, tomorrow}; + + for (auto& date : dates) + { + p->LoadArchives(date); + } +} + void TextEventManager::Impl::HandleMessage( const std::shared_ptr& message) { @@ -249,6 +276,32 @@ void TextEventManager::Impl::HandleMessage( } } +void TextEventManager::Impl::LoadArchive(std::chrono::sys_days date, + const std::string& pil) +{ + const auto& productIds = iemApiProvider_->ListTextProducts(date, {}, pil); + const auto& products = iemApiProvider_->LoadTextProducts(productIds); + + for (auto& product : products) + { + const auto& messages = product->messages(); + + for (auto& message : messages) + { + HandleMessage(message); + } + } +} + +void TextEventManager::Impl::LoadArchives(std::chrono::sys_days date) +{ + for (auto& pil : kPils_) + { + boost::asio::post(threadPool_, + [this, date, &pil]() { LoadArchive(date, pil); }); + } +} + void TextEventManager::Impl::RefreshAsync() { boost::asio::post(threadPool_, diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp index 30748781..312dece0 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -29,6 +30,7 @@ public: message_list(const types::TextEventKey& key) const; void LoadFile(const std::string& filename); + void SelectTime(std::chrono::system_clock::time_point dateTime); static std::shared_ptr Instance();