From f0ef6b35dd60c3ef20385f626100f0d40ae8402a Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Thu, 27 Mar 2025 11:20:01 -0400 Subject: [PATCH] Slight rework to nexrad data provider interface --- .../scwx/qt/manager/radar_product_manager.cpp | 13 +++------- .../provider/aws_nexrad_data_provider.hpp | 4 +++ .../scwx/provider/nexrad_data_provider.hpp | 25 +++++++++++++++++++ .../provider/aws_nexrad_data_provider.cpp | 24 ++++++++++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp index 48584a2d..c93dd78a 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp @@ -769,9 +769,7 @@ void RadarProductManagerImpl::RefreshDataSync( if (totalObjects > 0) { - std::string key = providerManager->provider_->FindLatestKey(); - auto latestTime = providerManager->provider_->GetTimePointByKey(key); - + auto latestTime = providerManager->provider_->FindLatestTime(); auto updatePeriod = providerManager->provider_->update_period(); auto lastModified = providerManager->provider_->last_modified(); auto sinceLastModified = std::chrono::system_clock::now() - lastModified; @@ -951,13 +949,8 @@ void RadarProductManagerImpl::LoadProviderData( if (existingRecord == nullptr) { - std::string key = providerManager->provider_->FindKey(time); - - if (!key.empty()) - { - nexradFile = providerManager->provider_->LoadObjectByKey(key); - } - else + nexradFile = providerManager->provider_->LoadObjectByTime(time); + if (nexradFile == nullptr) { logger_->warn("Attempting to load object without key: {}", scwx::util::TimeString(time)); diff --git a/wxdata/include/scwx/provider/aws_nexrad_data_provider.hpp b/wxdata/include/scwx/provider/aws_nexrad_data_provider.hpp index 462d293d..cb71f27b 100644 --- a/wxdata/include/scwx/provider/aws_nexrad_data_provider.hpp +++ b/wxdata/include/scwx/provider/aws_nexrad_data_provider.hpp @@ -39,12 +39,16 @@ public: std::string FindKey(std::chrono::system_clock::time_point time) override; std::string FindLatestKey() override; + std::chrono::system_clock::time_point FindLatestTime() override; std::vector GetTimePointsByDate(std::chrono::system_clock::time_point date) override; std::tuple ListObjects(std::chrono::system_clock::time_point date) override; std::shared_ptr LoadObjectByKey(const std::string& key) override; + std::shared_ptr + LoadObjectByTime(std::chrono::system_clock::time_point time) override; + std::shared_ptr LoadLatestObject() override; std::pair Refresh() override; protected: diff --git a/wxdata/include/scwx/provider/nexrad_data_provider.hpp b/wxdata/include/scwx/provider/nexrad_data_provider.hpp index 14a75815..81edc1eb 100644 --- a/wxdata/include/scwx/provider/nexrad_data_provider.hpp +++ b/wxdata/include/scwx/provider/nexrad_data_provider.hpp @@ -59,6 +59,13 @@ public: */ virtual std::string FindLatestKey() = 0; + /** + * Finds the most recent time in the cache. + * + * @return NEXRAD data key + */ + virtual std::chrono::system_clock::time_point FindLatestTime() = 0; + /** * Lists NEXRAD objects for the date supplied, and adds them to the cache. * @@ -81,6 +88,24 @@ public: virtual std::shared_ptr LoadObjectByKey(const std::string& key) = 0; + /** + * Loads a NEXRAD file object at the given time + * + * @param time NEXRAD time + * + * @return NEXRAD data + */ + virtual std::shared_ptr + LoadObjectByTime(std::chrono::system_clock::time_point time) = 0; + + /** + * Loads the latest NEXRAD file object + * + * @return NEXRAD data + */ + virtual std::shared_ptr + LoadLatestObject() = 0; + /** * Lists NEXRAD objects for the current date, and adds them to the cache. If * no objects have been added to the cache for the current date, the previous diff --git a/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp b/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp index c4ac523b..74740be0 100644 --- a/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp +++ b/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp @@ -170,6 +170,11 @@ std::string AwsNexradDataProvider::FindLatestKey() return key; } +std::chrono::system_clock::time_point AwsNexradDataProvider::FindLatestTime() +{ + return GetTimePointByKey(FindLatestKey()); +} + std::vector AwsNexradDataProvider::GetTimePointsByDate( std::chrono::system_clock::time_point date) @@ -327,6 +332,25 @@ AwsNexradDataProvider::LoadObjectByKey(const std::string& key) return nexradFile; } +std::shared_ptr AwsNexradDataProvider::LoadObjectByTime( + std::chrono::system_clock::time_point time) +{ + const std::string key = FindKey(time); + if (key.empty()) + { + return nullptr; + } + else + { + return LoadObjectByKey(key); + } +} + +std::shared_ptr AwsNexradDataProvider::LoadLatestObject() +{ + return LoadObjectByKey(FindLatestKey()); +} + std::pair AwsNexradDataProvider::Refresh() { using namespace std::chrono;