Slight rework to nexrad data provider interface

This commit is contained in:
AdenKoperczak 2025-03-27 11:20:01 -04:00
parent 4ddff43813
commit f0ef6b35dd
No known key found for this signature in database
GPG key ID: 9843017036F62EE7
4 changed files with 56 additions and 10 deletions

View file

@ -769,9 +769,7 @@ void RadarProductManagerImpl::RefreshDataSync(
if (totalObjects > 0) if (totalObjects > 0)
{ {
std::string key = providerManager->provider_->FindLatestKey(); auto latestTime = providerManager->provider_->FindLatestTime();
auto latestTime = providerManager->provider_->GetTimePointByKey(key);
auto updatePeriod = providerManager->provider_->update_period(); auto updatePeriod = providerManager->provider_->update_period();
auto lastModified = providerManager->provider_->last_modified(); auto lastModified = providerManager->provider_->last_modified();
auto sinceLastModified = std::chrono::system_clock::now() - lastModified; auto sinceLastModified = std::chrono::system_clock::now() - lastModified;
@ -951,13 +949,8 @@ void RadarProductManagerImpl::LoadProviderData(
if (existingRecord == nullptr) if (existingRecord == nullptr)
{ {
std::string key = providerManager->provider_->FindKey(time); nexradFile = providerManager->provider_->LoadObjectByTime(time);
if (nexradFile == nullptr)
if (!key.empty())
{
nexradFile = providerManager->provider_->LoadObjectByKey(key);
}
else
{ {
logger_->warn("Attempting to load object without key: {}", logger_->warn("Attempting to load object without key: {}",
scwx::util::TimeString(time)); scwx::util::TimeString(time));

View file

@ -39,12 +39,16 @@ public:
std::string FindKey(std::chrono::system_clock::time_point time) override; std::string FindKey(std::chrono::system_clock::time_point time) override;
std::string FindLatestKey() override; std::string FindLatestKey() override;
std::chrono::system_clock::time_point FindLatestTime() override;
std::vector<std::chrono::system_clock::time_point> std::vector<std::chrono::system_clock::time_point>
GetTimePointsByDate(std::chrono::system_clock::time_point date) override; GetTimePointsByDate(std::chrono::system_clock::time_point date) override;
std::tuple<bool, size_t, size_t> std::tuple<bool, size_t, size_t>
ListObjects(std::chrono::system_clock::time_point date) override; ListObjects(std::chrono::system_clock::time_point date) override;
std::shared_ptr<wsr88d::NexradFile> std::shared_ptr<wsr88d::NexradFile>
LoadObjectByKey(const std::string& key) override; LoadObjectByKey(const std::string& key) override;
std::shared_ptr<wsr88d::NexradFile>
LoadObjectByTime(std::chrono::system_clock::time_point time) override;
std::shared_ptr<wsr88d::NexradFile> LoadLatestObject() override;
std::pair<size_t, size_t> Refresh() override; std::pair<size_t, size_t> Refresh() override;
protected: protected:

View file

@ -59,6 +59,13 @@ public:
*/ */
virtual std::string FindLatestKey() = 0; 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. * Lists NEXRAD objects for the date supplied, and adds them to the cache.
* *
@ -81,6 +88,24 @@ public:
virtual std::shared_ptr<wsr88d::NexradFile> virtual std::shared_ptr<wsr88d::NexradFile>
LoadObjectByKey(const std::string& key) = 0; 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<wsr88d::NexradFile>
LoadObjectByTime(std::chrono::system_clock::time_point time) = 0;
/**
* Loads the latest NEXRAD file object
*
* @return NEXRAD data
*/
virtual std::shared_ptr<wsr88d::NexradFile>
LoadLatestObject() = 0;
/** /**
* Lists NEXRAD objects for the current date, and adds them to the cache. If * 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 * no objects have been added to the cache for the current date, the previous

View file

@ -170,6 +170,11 @@ std::string AwsNexradDataProvider::FindLatestKey()
return key; return key;
} }
std::chrono::system_clock::time_point AwsNexradDataProvider::FindLatestTime()
{
return GetTimePointByKey(FindLatestKey());
}
std::vector<std::chrono::system_clock::time_point> std::vector<std::chrono::system_clock::time_point>
AwsNexradDataProvider::GetTimePointsByDate( AwsNexradDataProvider::GetTimePointsByDate(
std::chrono::system_clock::time_point date) std::chrono::system_clock::time_point date)
@ -327,6 +332,25 @@ AwsNexradDataProvider::LoadObjectByKey(const std::string& key)
return nexradFile; return nexradFile;
} }
std::shared_ptr<wsr88d::NexradFile> 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<wsr88d::NexradFile> AwsNexradDataProvider::LoadLatestObject()
{
return LoadObjectByKey(FindLatestKey());
}
std::pair<size_t, size_t> AwsNexradDataProvider::Refresh() std::pair<size_t, size_t> AwsNexradDataProvider::Refresh()
{ {
using namespace std::chrono; using namespace std::chrono;