mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 01:00:05 +00:00
Adjust number of stored/cached products based on loop time
This commit is contained in:
parent
3d42ca9e12
commit
11e74b46ec
3 changed files with 70 additions and 19 deletions
|
|
@ -216,6 +216,7 @@ public:
|
||||||
bool level3ProductsInitialized_;
|
bool level3ProductsInitialized_;
|
||||||
|
|
||||||
std::shared_ptr<config::RadarSite> radarSite_;
|
std::shared_ptr<config::RadarSite> radarSite_;
|
||||||
|
std::size_t cacheLimit_ {6u};
|
||||||
|
|
||||||
std::vector<float> coordinates0_5Degree_;
|
std::vector<float> coordinates0_5Degree_;
|
||||||
std::vector<float> coordinates1Degree_;
|
std::vector<float> coordinates1Degree_;
|
||||||
|
|
@ -1135,7 +1136,7 @@ void RadarProductManagerImpl::UpdateRecentRecords(
|
||||||
RadarProductRecordList& recentList,
|
RadarProductRecordList& recentList,
|
||||||
std::shared_ptr<types::RadarProductRecord> record)
|
std::shared_ptr<types::RadarProductRecord> record)
|
||||||
{
|
{
|
||||||
static constexpr std::size_t kRecentListMaxSize_ {2u};
|
const std::size_t recentListMaxSize {cacheLimit_};
|
||||||
|
|
||||||
auto it = std::find(recentList.cbegin(), recentList.cend(), record);
|
auto it = std::find(recentList.cbegin(), recentList.cend(), record);
|
||||||
if (it != recentList.cbegin() && it != recentList.cend())
|
if (it != recentList.cbegin() && it != recentList.cend())
|
||||||
|
|
@ -1150,7 +1151,7 @@ void RadarProductManagerImpl::UpdateRecentRecords(
|
||||||
recentList.push_front(record);
|
recentList.push_front(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (recentList.size() > kRecentListMaxSize_)
|
while (recentList.size() > recentListMaxSize)
|
||||||
{
|
{
|
||||||
// Remove from the end of the list while it's too big
|
// Remove from the end of the list while it's too big
|
||||||
recentList.pop_back();
|
recentList.pop_back();
|
||||||
|
|
@ -1215,6 +1216,11 @@ std::vector<std::string> RadarProductManager::GetLevel3Products()
|
||||||
return level3ProviderManager->provider_->GetAvailableProducts();
|
return level3ProviderManager->provider_->GetAvailableProducts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadarProductManager::SetCacheLimit(size_t cacheLimit)
|
||||||
|
{
|
||||||
|
p->cacheLimit_ = cacheLimit;
|
||||||
|
}
|
||||||
|
|
||||||
void RadarProductManager::UpdateAvailableProducts()
|
void RadarProductManager::UpdateAvailableProducts()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(p->level3ProductsInitializeMutex_);
|
std::lock_guard<std::mutex> guard(p->level3ProductsInitializeMutex_);
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,14 @@ public:
|
||||||
|
|
||||||
common::Level3ProductCategoryMap GetAvailableLevel3Categories();
|
common::Level3ProductCategoryMap GetAvailableLevel3Categories();
|
||||||
std::vector<std::string> GetLevel3Products();
|
std::vector<std::string> GetLevel3Products();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the maximum number of products of each type that may be cached.
|
||||||
|
*
|
||||||
|
* @param [in] cacheLimit The maximum number of products of each type
|
||||||
|
*/
|
||||||
|
void SetCacheLimit(std::size_t cacheLimit);
|
||||||
|
|
||||||
void UpdateAvailableProducts();
|
void UpdateAvailableProducts();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,13 @@ public:
|
||||||
|
|
||||||
TimelineManager* self_;
|
TimelineManager* self_;
|
||||||
|
|
||||||
|
std::pair<std::chrono::system_clock::time_point,
|
||||||
|
std::chrono::system_clock::time_point>
|
||||||
|
GetLoopStartAndEndTimes();
|
||||||
|
void UpdateCacheLimit(
|
||||||
|
std::shared_ptr<manager::RadarProductManager> radarProductManager,
|
||||||
|
const std::set<std::chrono::system_clock::time_point>& volumeTimes);
|
||||||
|
|
||||||
void Pause();
|
void Pause();
|
||||||
void Play();
|
void Play();
|
||||||
void SelectTime(std::chrono::system_clock::time_point selectedTime = {});
|
void SelectTime(std::chrono::system_clock::time_point selectedTime = {});
|
||||||
|
|
@ -223,6 +230,45 @@ void TimelineManager::Impl::Pause()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<std::chrono::system_clock::time_point,
|
||||||
|
std::chrono::system_clock::time_point>
|
||||||
|
TimelineManager::Impl::GetLoopStartAndEndTimes()
|
||||||
|
{
|
||||||
|
// Determine loop end time
|
||||||
|
std::chrono::system_clock::time_point endTime;
|
||||||
|
|
||||||
|
if (viewType_ == types::MapTime::Live ||
|
||||||
|
pinnedTime_ == std::chrono::system_clock::time_point {})
|
||||||
|
{
|
||||||
|
endTime = std::chrono::floor<std::chrono::minutes>(
|
||||||
|
std::chrono::system_clock::now());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
endTime = pinnedTime_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine loop start time and current position in the loop
|
||||||
|
std::chrono::system_clock::time_point startTime = endTime - loopTime_;
|
||||||
|
|
||||||
|
return {startTime, endTime};
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimelineManager::Impl::UpdateCacheLimit(
|
||||||
|
std::shared_ptr<manager::RadarProductManager> radarProductManager,
|
||||||
|
const std::set<std::chrono::system_clock::time_point>& volumeTimes)
|
||||||
|
{
|
||||||
|
// Calculate the number of volume scans in the loop
|
||||||
|
auto [startTime, endTime] = GetLoopStartAndEndTimes();
|
||||||
|
auto startIter = util::GetBoundedElementIterator(volumeTimes, startTime);
|
||||||
|
auto endIter = util::GetBoundedElementIterator(volumeTimes, endTime);
|
||||||
|
std::size_t numVolumeScans = std::distance(startIter, endIter) + 1;
|
||||||
|
|
||||||
|
// Dynamically update maximum cached volume scans to 1.5x the loop length
|
||||||
|
radarProductManager->SetCacheLimit(
|
||||||
|
static_cast<std::size_t>(numVolumeScans * 1.5));
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineManager::Impl::Play()
|
void TimelineManager::Impl::Play()
|
||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
@ -244,22 +290,7 @@ void TimelineManager::Impl::Play()
|
||||||
// Take a lock for time selection
|
// Take a lock for time selection
|
||||||
std::unique_lock lock {selectTimeMutex_};
|
std::unique_lock lock {selectTimeMutex_};
|
||||||
|
|
||||||
// Determine loop end time
|
auto [startTime, endTime] = GetLoopStartAndEndTimes();
|
||||||
std::chrono::system_clock::time_point endTime;
|
|
||||||
|
|
||||||
if (viewType_ == types::MapTime::Live ||
|
|
||||||
pinnedTime_ == std::chrono::system_clock::time_point {})
|
|
||||||
{
|
|
||||||
endTime = std::chrono::floor<std::chrono::minutes>(
|
|
||||||
std::chrono::system_clock::now());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
endTime = pinnedTime_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine loop start time and current position in the loop
|
|
||||||
std::chrono::system_clock::time_point startTime = endTime - loopTime_;
|
|
||||||
std::chrono::system_clock::time_point currentTime = selectedTime_;
|
std::chrono::system_clock::time_point currentTime = selectedTime_;
|
||||||
std::chrono::system_clock::time_point newTime;
|
std::chrono::system_clock::time_point newTime;
|
||||||
|
|
||||||
|
|
@ -353,6 +384,9 @@ void TimelineManager::Impl::SelectTime(
|
||||||
auto volumeTimes =
|
auto volumeTimes =
|
||||||
radarProductManager->GetActiveVolumeTimes(selectedTime);
|
radarProductManager->GetActiveVolumeTimes(selectedTime);
|
||||||
|
|
||||||
|
// Dynamically update maximum cached volume scans
|
||||||
|
UpdateCacheLimit(radarProductManager, volumeTimes);
|
||||||
|
|
||||||
// Find the best match bounded time
|
// Find the best match bounded time
|
||||||
auto elementPtr =
|
auto elementPtr =
|
||||||
util::GetBoundedElementPointer(volumeTimes, selectedTime);
|
util::GetBoundedElementPointer(volumeTimes, selectedTime);
|
||||||
|
|
@ -418,6 +452,9 @@ void TimelineManager::Impl::Step(Direction direction)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dynamically update maximum cached volume scans
|
||||||
|
UpdateCacheLimit(radarProductManager, volumeTimes);
|
||||||
|
|
||||||
std::set<std::chrono::system_clock::time_point>::const_iterator it;
|
std::set<std::chrono::system_clock::time_point>::const_iterator it;
|
||||||
|
|
||||||
if (adjustedTime_ == std::chrono::system_clock::time_point {})
|
if (adjustedTime_ == std::chrono::system_clock::time_point {})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue