mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 18:10:05 +00:00 
			
		
		
		
	Populate level 3 product times prior to loading, don't require an exact time match
- Consistent with level 2, will allow choosing of the correct level 3 product if an exact time isn't given - Fixes step begin/end when not all products have the same volume times - Expected to help when switching radar sites, and attempting to save selected time from previous site
This commit is contained in:
		
							parent
							
								
									ea1569cb76
								
							
						
					
					
						commit
						93ae58424c
					
				
					 1 changed files with 56 additions and 21 deletions
				
			
		|  | @ -206,6 +206,14 @@ public: | ||||||
|                          std::mutex&                           loadDataMutex, |                          std::mutex&                           loadDataMutex, | ||||||
|                          std::shared_ptr<request::NexradFileRequest> request); |                          std::shared_ptr<request::NexradFileRequest> request); | ||||||
|    void PopulateLevel2ProductTimes(std::chrono::system_clock::time_point time); |    void PopulateLevel2ProductTimes(std::chrono::system_clock::time_point time); | ||||||
|  |    void PopulateLevel3ProductTimes(const std::string& product, | ||||||
|  |                                    std::chrono::system_clock::time_point time); | ||||||
|  | 
 | ||||||
|  |    static void | ||||||
|  |    PopulateProductTimes(std::shared_ptr<ProviderManager> providerManager, | ||||||
|  |                         RadarProductRecordMap&           productRecordMap, | ||||||
|  |                         std::shared_mutex&               productRecordMutex, | ||||||
|  |                         std::chrono::system_clock::time_point time); | ||||||
| 
 | 
 | ||||||
|    static void |    static void | ||||||
|    LoadNexradFile(CreateNexradFileFunction                    load, |    LoadNexradFile(CreateNexradFileFunction                    load, | ||||||
|  | @ -969,6 +977,35 @@ void RadarProductManagerImpl::LoadNexradFile( | ||||||
| 
 | 
 | ||||||
| void RadarProductManagerImpl::PopulateLevel2ProductTimes( | void RadarProductManagerImpl::PopulateLevel2ProductTimes( | ||||||
|    std::chrono::system_clock::time_point time) |    std::chrono::system_clock::time_point time) | ||||||
|  | { | ||||||
|  |    PopulateProductTimes(level2ProviderManager_, | ||||||
|  |                         level2ProductRecords_, | ||||||
|  |                         level2ProductRecordMutex_, | ||||||
|  |                         time); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RadarProductManagerImpl::PopulateLevel3ProductTimes( | ||||||
|  |    const std::string& product, std::chrono::system_clock::time_point time) | ||||||
|  | { | ||||||
|  |    // Get provider manager
 | ||||||
|  |    auto level3ProviderManager = GetLevel3ProviderManager(product); | ||||||
|  | 
 | ||||||
|  |    // Get product records
 | ||||||
|  |    std::unique_lock level3ProductRecordLock {level3ProductRecordMutex_}; | ||||||
|  |    auto&            level3ProductRecords = level3ProductRecordsMap_[product]; | ||||||
|  |    level3ProductRecordLock.unlock(); | ||||||
|  | 
 | ||||||
|  |    PopulateProductTimes(level3ProviderManager, | ||||||
|  |                         level3ProductRecords, | ||||||
|  |                         level3ProductRecordMutex_, | ||||||
|  |                         time); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void RadarProductManagerImpl::PopulateProductTimes( | ||||||
|  |    std::shared_ptr<ProviderManager>      providerManager, | ||||||
|  |    RadarProductRecordMap&                productRecordMap, | ||||||
|  |    std::shared_mutex&                    productRecordMutex, | ||||||
|  |    std::chrono::system_clock::time_point time) | ||||||
| { | { | ||||||
|    const auto today     = std::chrono::floor<std::chrono::days>(time); |    const auto today     = std::chrono::floor<std::chrono::days>(time); | ||||||
|    const auto yesterday = today - std::chrono::days {1}; |    const auto yesterday = today - std::chrono::days {1}; | ||||||
|  | @ -982,7 +1019,7 @@ void RadarProductManagerImpl::PopulateLevel2ProductTimes( | ||||||
|    std::for_each(std::execution::par_unseq, |    std::for_each(std::execution::par_unseq, | ||||||
|                  dates.begin(), |                  dates.begin(), | ||||||
|                  dates.end(), |                  dates.end(), | ||||||
|                  [&, this](const auto& date) |                  [&](const auto& date) | ||||||
|                  { |                  { | ||||||
|                     // Don't query for a time point in the future
 |                     // Don't query for a time point in the future
 | ||||||
|                     if (date > std::chrono::system_clock::now()) |                     if (date > std::chrono::system_clock::now()) | ||||||
|  | @ -992,8 +1029,7 @@ void RadarProductManagerImpl::PopulateLevel2ProductTimes( | ||||||
| 
 | 
 | ||||||
|                     // Query the provider for volume time points
 |                     // Query the provider for volume time points
 | ||||||
|                     auto timePoints = |                     auto timePoints = | ||||||
|                        level2ProviderManager_->provider_->GetTimePointsByDate( |                        providerManager->provider_->GetTimePointsByDate(date); | ||||||
|                           date); |  | ||||||
| 
 | 
 | ||||||
|                     // Lock the merged volume time list
 |                     // Lock the merged volume time list
 | ||||||
|                     std::unique_lock volumeTimesLock {volumeTimesMutex}; |                     std::unique_lock volumeTimesLock {volumeTimesMutex}; | ||||||
|  | @ -1004,14 +1040,13 @@ void RadarProductManagerImpl::PopulateLevel2ProductTimes( | ||||||
|                               std::inserter(volumeTimes, volumeTimes.end())); |                               std::inserter(volumeTimes, volumeTimes.end())); | ||||||
|                  }); |                  }); | ||||||
| 
 | 
 | ||||||
|    // Lock the level 2 product record map
 |    // Lock the product record map
 | ||||||
|    std::unique_lock lock {level2ProductRecordMutex_}; |    std::unique_lock lock {productRecordMutex}; | ||||||
| 
 | 
 | ||||||
|    // Merge volume times into map
 |    // Merge volume times into map
 | ||||||
|    std::transform( |    std::transform(volumeTimes.cbegin(), | ||||||
|       volumeTimes.cbegin(), |  | ||||||
|                   volumeTimes.cend(), |                   volumeTimes.cend(), | ||||||
|       std::inserter(level2ProductRecords_, level2ProductRecords_.begin()), |                   std::inserter(productRecordMap, productRecordMap.begin()), | ||||||
|                   [](const std::chrono::system_clock::time_point& time) |                   [](const std::chrono::system_clock::time_point& time) | ||||||
|                   { |                   { | ||||||
|                      return std::pair<std::chrono::system_clock::time_point, |                      return std::pair<std::chrono::system_clock::time_point, | ||||||
|  | @ -1085,6 +1120,9 @@ RadarProductManagerImpl::GetLevel3ProductRecord( | ||||||
|    RadarProductRecordMap::const_pointer       recordPtr {nullptr}; |    RadarProductRecordMap::const_pointer       recordPtr {nullptr}; | ||||||
|    std::chrono::system_clock::time_point      recordTime {time}; |    std::chrono::system_clock::time_point      recordTime {time}; | ||||||
| 
 | 
 | ||||||
|  |    // Ensure Level 3 product records are updated
 | ||||||
|  |    PopulateLevel3ProductTimes(product, time); | ||||||
|  | 
 | ||||||
|    std::unique_lock lock {level3ProductRecordMutex_}; |    std::unique_lock lock {level3ProductRecordMutex_}; | ||||||
| 
 | 
 | ||||||
|    auto it = level3ProductRecordsMap_.find(product); |    auto it = level3ProductRecordsMap_.find(product); | ||||||
|  | @ -1108,13 +1146,10 @@ RadarProductManagerImpl::GetLevel3ProductRecord( | ||||||
| 
 | 
 | ||||||
|    if (recordPtr != nullptr) |    if (recordPtr != nullptr) | ||||||
|    { |    { | ||||||
|       if (time == std::chrono::system_clock::time_point {} || |       // Don't check for an exact time match for level 3 products
 | ||||||
|           time == recordPtr->first) |  | ||||||
|       { |  | ||||||
|       recordTime = recordPtr->first; |       recordTime = recordPtr->first; | ||||||
|       record     = recordPtr->second.lock(); |       record     = recordPtr->second.lock(); | ||||||
|    } |    } | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    if (recordPtr != nullptr && record == nullptr && |    if (recordPtr != nullptr && record == nullptr && | ||||||
|        recordTime != std::chrono::system_clock::time_point {}) |        recordTime != std::chrono::system_clock::time_point {}) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat