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 d062e67a..b036fb8d 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if defined(_MSC_VER) # pragma warning(push, 0) @@ -244,8 +245,8 @@ public: std::unordered_map, boost::hash> - refreshMap_ {}; - std::mutex refreshMapMutex_ {}; + refreshMap_ {}; + std::shared_mutex refreshMapMutex_ {}; }; RadarProductManager::RadarProductManager(const std::string& radarId) : @@ -676,6 +677,66 @@ void RadarProductManagerImpl::RefreshData( }); } +std::set +RadarProductManager::GetActiveVolumeTimes( + std::chrono::system_clock::time_point time) +{ + std::unordered_set> + providers {}; + std::set volumeTimes; + std::mutex volumeTimesMutex {}; + + // Lock the refresh map + std::shared_lock refreshLock {p->refreshMapMutex_}; + + // For each entry in the refresh map (refresh is enabled) + for (auto& refreshEntry : p->refreshMap_) + { + // Add the provider for the current entry + providers.insert(refreshEntry.second->provider_); + } + + // Unlock the refresh map + refreshLock.unlock(); + + // For each provider (in parallel) + std::for_each( + std::execution::par_unseq, + providers.begin(), + providers.end(), + [&](const std::shared_ptr& provider) + { + const auto today = std::chrono::floor(time); + const auto yesterday = today - std::chrono::days {1}; + const auto dates = {yesterday, today}; + + // For today and yesterday (in parallel) + std::for_each(std::execution::par_unseq, + dates.begin(), + dates.end(), + [&](const auto& date) + { + // Query the provider for volume time points + auto timePoints = provider->GetTimePointsByDate(date); + + // TODO: Note, this will miss volume times present in + // Level 2 products with a second scan + + // Lock the merged volume time list + std::unique_lock volumeTimesLock {volumeTimesMutex}; + + // Copy time points to the merged list + std::copy( + timePoints.begin(), + timePoints.end(), + std::inserter(volumeTimes, volumeTimes.end())); + }); + }); + + // Return merged volume times list + return volumeTimes; +} + void RadarProductManagerImpl::LoadProviderData( std::chrono::system_clock::time_point time, std::shared_ptr providerManager, diff --git a/scwx-qt/source/scwx/qt/manager/radar_product_manager.hpp b/scwx-qt/source/scwx/qt/manager/radar_product_manager.hpp index 54a57499..9e74f95b 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_product_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/radar_product_manager.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -63,6 +64,17 @@ public: bool enabled, boost::uuids::uuid uuid = boost::uuids::nil_uuid()); + /** + * @brief Gets a merged list of the volume times for products with refresh + * enabled. The volume times will be for the current and previous day. + * + * @param [in] time Current date to provide to volume time query + * + * @return Merged list of active volume times + */ + std::set + GetActiveVolumeTimes(std::chrono::system_clock::time_point time); + /** * @brief Get level 2 radar data for a data block type, elevation, and time. *