Setting up for merging last and current scan's, and having archive and chunks

This commit is contained in:
AdenKoperczak 2025-03-30 13:18:04 -04:00
parent fc83a7a36f
commit a754d66844
No known key found for this signature in database
GPG key ID: 9843017036F62EE7
8 changed files with 143 additions and 23 deletions

View file

@ -134,6 +134,8 @@ public:
level3ProductsInitialized_ {false}, level3ProductsInitialized_ {false},
radarSite_ {config::RadarSite::Get(radarId)}, radarSite_ {config::RadarSite::Get(radarId)},
level2ProviderManager_ {std::make_shared<ProviderManager>( level2ProviderManager_ {std::make_shared<ProviderManager>(
self_, radarId_, common::RadarProductGroup::Level2)},
level2ChunksProviderManager_ {std::make_shared<ProviderManager>(
self_, radarId_, common::RadarProductGroup::Level2)} self_, radarId_, common::RadarProductGroup::Level2)}
{ {
if (radarSite_ == nullptr) if (radarSite_ == nullptr)
@ -144,10 +146,14 @@ public:
level2ProviderManager_->provider_ = level2ProviderManager_->provider_ =
provider::NexradDataProviderFactory::CreateLevel2DataProvider(radarId); provider::NexradDataProviderFactory::CreateLevel2DataProvider(radarId);
level2ChunksProviderManager_->provider_ =
provider::NexradDataProviderFactory::CreateLevel2ChunksDataProvider(
radarId);
} }
~RadarProductManagerImpl() ~RadarProductManagerImpl()
{ {
level2ProviderManager_->Disable(); level2ProviderManager_->Disable();
level2ChunksProviderManager_->Disable();
std::shared_lock lock(level3ProviderManagerMutex_); std::shared_lock lock(level3ProviderManagerMutex_);
std::for_each(std::execution::par_unseq, std::for_each(std::execution::par_unseq,
@ -251,6 +257,7 @@ public:
std::shared_mutex level3ProductRecordMutex_ {}; std::shared_mutex level3ProductRecordMutex_ {};
std::shared_ptr<ProviderManager> level2ProviderManager_; std::shared_ptr<ProviderManager> level2ProviderManager_;
std::shared_ptr<ProviderManager> level2ChunksProviderManager_;
std::unordered_map<std::string, std::shared_ptr<ProviderManager>> std::unordered_map<std::string, std::shared_ptr<ProviderManager>>
level3ProviderManagerMap_ {}; level3ProviderManagerMap_ {};
std::shared_mutex level3ProviderManagerMutex_ {}; std::shared_mutex level3ProviderManagerMutex_ {};
@ -639,6 +646,7 @@ void RadarProductManager::EnableRefresh(common::RadarProductGroup group,
if (group == common::RadarProductGroup::Level2) if (group == common::RadarProductGroup::Level2)
{ {
p->EnableRefresh(uuid, p->level2ProviderManager_, enabled); p->EnableRefresh(uuid, p->level2ProviderManager_, enabled);
p->EnableRefresh(uuid, p->level2ChunksProviderManager_, enabled);
} }
else else
{ {
@ -986,6 +994,12 @@ void RadarProductManager::LoadLevel2Data(
p->level2ProductRecordMutex_, p->level2ProductRecordMutex_,
p->loadLevel2DataMutex_, p->loadLevel2DataMutex_,
request); request);
p->LoadProviderData(time,
p->level2ChunksProviderManager_,
p->level2ProductRecords_,
p->level2ProductRecordMutex_,
p->loadLevel2DataMutex_,
request);
} }
void RadarProductManager::LoadLevel3Data( void RadarProductManager::LoadLevel3Data(
@ -1162,6 +1176,10 @@ void RadarProductManagerImpl::PopulateLevel2ProductTimes(
level2ProductRecords_, level2ProductRecords_,
level2ProductRecordMutex_, level2ProductRecordMutex_,
time); time);
PopulateProductTimes(level2ChunksProviderManager_,
level2ProductRecords_,
level2ProductRecordMutex_,
time);
} }
void RadarProductManagerImpl::PopulateLevel3ProductTimes( void RadarProductManagerImpl::PopulateLevel3ProductTimes(
@ -1504,6 +1522,74 @@ RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
auto records = p->GetLevel2ProductRecords(time); auto records = p->GetLevel2ProductRecords(time);
//TODO decide when to use chunked vs archived data.
if (true)
{
auto currentFile = std::dynamic_pointer_cast<wsr88d::Ar2vFile>(
p->level2ChunksProviderManager_->provider_->LoadLatestObject());
std::shared_ptr<wsr88d::rda::ElevationScan> currentRadarData = nullptr;
float currentElevationCut = 0.0f;
std::vector<float> currentElevationCuts;
if (currentFile != nullptr)
{
std::tie(currentRadarData, currentElevationCut, currentElevationCuts) =
currentFile->GetElevationScan(dataBlockType, elevation, time);
}
std::shared_ptr<wsr88d::rda::ElevationScan> lastRadarData = nullptr;
float lastElevationCut = 0.0f;
std::vector<float> lastElevationCuts;
auto lastFile = std::dynamic_pointer_cast<wsr88d::Ar2vFile>(
p->level2ChunksProviderManager_->provider_->LoadSecondLatestObject());
if (lastFile != nullptr)
{
std::tie(lastRadarData, lastElevationCut, lastElevationCuts) =
lastFile->GetElevationScan(dataBlockType, elevation, time);
}
if (currentRadarData != nullptr)
{
if (lastRadarData != nullptr)
{
auto& radarData0 = (*currentRadarData)[0];
auto collectionTime = std::chrono::floor<std::chrono::seconds>(
scwx::util::TimePoint(radarData0->modified_julian_date(),
radarData0->collection_time()));
// TODO merge data
radarData = currentRadarData;
elevationCut = currentElevationCut;
elevationCuts = std::move(currentElevationCuts);
foundTime = collectionTime;
}
else
{
auto& radarData0 = (*currentRadarData)[0];
auto collectionTime = std::chrono::floor<std::chrono::seconds>(
scwx::util::TimePoint(radarData0->modified_julian_date(),
radarData0->collection_time()));
radarData = currentRadarData;
elevationCut = currentElevationCut;
elevationCuts = std::move(currentElevationCuts);
foundTime = collectionTime;
}
}
else if (lastRadarData != nullptr)
{
auto& radarData0 = (*lastRadarData)[0];
auto collectionTime = std::chrono::floor<std::chrono::seconds>(
scwx::util::TimePoint(radarData0->modified_julian_date(),
radarData0->collection_time()));
radarData = lastRadarData;
elevationCut = lastElevationCut;
elevationCuts = std::move(lastElevationCuts);
foundTime = collectionTime;
}
}
else
{
for (auto& recordPair : records) for (auto& recordPair : records)
{ {
auto& record = recordPair.second; auto& record = recordPair.second;
@ -1537,6 +1623,7 @@ RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
} }
} }
} }
}
return {radarData, elevationCut, elevationCuts, foundTime}; return {radarData, elevationCut, elevationCuts, foundTime};
} }

View file

@ -51,6 +51,7 @@ public:
std::shared_ptr<wsr88d::NexradFile> std::shared_ptr<wsr88d::NexradFile>
LoadObjectByTime(std::chrono::system_clock::time_point time) override; LoadObjectByTime(std::chrono::system_clock::time_point time) override;
std::shared_ptr<wsr88d::NexradFile> LoadLatestObject() override; std::shared_ptr<wsr88d::NexradFile> LoadLatestObject() override;
std::shared_ptr<wsr88d::NexradFile> LoadSecondLatestObject() override;
std::pair<size_t, size_t> Refresh() override; std::pair<size_t, size_t> Refresh() override;
void RequestAvailableProducts() override; void RequestAvailableProducts() override;

View file

@ -49,6 +49,7 @@ public:
std::shared_ptr<wsr88d::NexradFile> std::shared_ptr<wsr88d::NexradFile>
LoadObjectByTime(std::chrono::system_clock::time_point time) override; LoadObjectByTime(std::chrono::system_clock::time_point time) override;
std::shared_ptr<wsr88d::NexradFile> LoadLatestObject() override; std::shared_ptr<wsr88d::NexradFile> LoadLatestObject() override;
std::shared_ptr<wsr88d::NexradFile> LoadSecondLatestObject() override;
std::pair<size_t, size_t> Refresh() override; std::pair<size_t, size_t> Refresh() override;
protected: protected:

View file

@ -106,6 +106,15 @@ public:
virtual std::shared_ptr<wsr88d::NexradFile> virtual std::shared_ptr<wsr88d::NexradFile>
LoadLatestObject() = 0; LoadLatestObject() = 0;
/**
* Loads the second NEXRAD file object
*
* @return NEXRAD data
*/
virtual std::shared_ptr<wsr88d::NexradFile>
LoadSecondLatestObject() = 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

@ -27,6 +27,9 @@ public:
static std::shared_ptr<NexradDataProvider> static std::shared_ptr<NexradDataProvider>
CreateLevel2DataProvider(const std::string& radarSite); CreateLevel2DataProvider(const std::string& radarSite);
static std::shared_ptr<NexradDataProvider>
CreateLevel2ChunksDataProvider(const std::string& radarSite);
static std::shared_ptr<NexradDataProvider> static std::shared_ptr<NexradDataProvider>
CreateLevel3DataProvider(const std::string& radarSite, CreateLevel3DataProvider(const std::string& radarSite,
const std::string& product); const std::string& product);

View file

@ -603,7 +603,13 @@ AwsLevel2ChunksDataProvider::LoadObjectByTime(
std::shared_ptr<wsr88d::NexradFile> std::shared_ptr<wsr88d::NexradFile>
AwsLevel2ChunksDataProvider::LoadLatestObject() AwsLevel2ChunksDataProvider::LoadLatestObject()
{ {
return LoadObjectByTime(FindLatestTime()); return p->currentScan_.nexradFile_;
}
std::shared_ptr<wsr88d::NexradFile>
AwsLevel2ChunksDataProvider::LoadSecondLatestObject()
{
return p->lastScan_.nexradFile_;
} }
int AwsLevel2ChunksDataProvider::Impl::GetScanNumber(const std::string& prefix) int AwsLevel2ChunksDataProvider::Impl::GetScanNumber(const std::string& prefix)

View file

@ -351,6 +351,12 @@ std::shared_ptr<wsr88d::NexradFile> AwsNexradDataProvider::LoadLatestObject()
return LoadObjectByKey(FindLatestKey()); return LoadObjectByKey(FindLatestKey());
} }
std::shared_ptr<wsr88d::NexradFile>
AwsNexradDataProvider::LoadSecondLatestObject()
{
return nullptr;
}
std::pair<size_t, size_t> AwsNexradDataProvider::Refresh() std::pair<size_t, size_t> AwsNexradDataProvider::Refresh()
{ {
using namespace std::chrono; using namespace std::chrono;

View file

@ -1,5 +1,5 @@
#include <scwx/provider/nexrad_data_provider_factory.hpp> #include <scwx/provider/nexrad_data_provider_factory.hpp>
//#include <scwx/provider/aws_level2_data_provider.hpp> #include <scwx/provider/aws_level2_data_provider.hpp>
#include <scwx/provider/aws_level2_chunks_data_provider.hpp> #include <scwx/provider/aws_level2_chunks_data_provider.hpp>
#include <scwx/provider/aws_level3_data_provider.hpp> #include <scwx/provider/aws_level3_data_provider.hpp>
@ -14,6 +14,13 @@ static const std::string logPrefix_ =
std::shared_ptr<NexradDataProvider> std::shared_ptr<NexradDataProvider>
NexradDataProviderFactory::CreateLevel2DataProvider( NexradDataProviderFactory::CreateLevel2DataProvider(
const std::string& radarSite) const std::string& radarSite)
{
return std::make_unique<AwsLevel2DataProvider>(radarSite);
}
std::shared_ptr<NexradDataProvider>
NexradDataProviderFactory::CreateLevel2ChunksDataProvider(
const std::string& radarSite)
{ {
return std::make_unique<AwsLevel2ChunksDataProvider>(radarSite); return std::make_unique<AwsLevel2ChunksDataProvider>(radarSite);
} }