mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:10:04 +00:00 
			
		
		
		
	Don't display stale storm tracking information
This commit is contained in:
		
							parent
							
								
									09cb64b84f
								
							
						
					
					
						commit
						b493a8d013
					
				
					 1 changed files with 52 additions and 6 deletions
				
			
		|  | @ -142,24 +142,70 @@ void OverlayProductView::Impl::LoadProduct( | ||||||
|               self_, |               self_, | ||||||
|               [=, this](std::shared_ptr<request::NexradFileRequest> request) |               [=, this](std::shared_ptr<request::NexradFileRequest> request) | ||||||
|               { |               { | ||||||
|  |                  using namespace std::chrono_literals; | ||||||
|  | 
 | ||||||
|                  // Select loaded record
 |                  // Select loaded record
 | ||||||
|                  const auto& record = request->radar_product_record(); |                  const auto& record = request->radar_product_record(); | ||||||
| 
 | 
 | ||||||
|                  // Validate record
 |                  // Validate record
 | ||||||
|                  if (record != nullptr) |                  if (record != nullptr) | ||||||
|                  { |                  { | ||||||
|                     // Store loaded record
 |                     auto productTime = record->time(); | ||||||
|                     std::unique_lock lock {recordMutex_}; |                     auto level3File  = record->level3_file(); | ||||||
| 
 |                     if (level3File != nullptr) | ||||||
|                     auto it = recordMap_.find(product); |  | ||||||
|                     if (it == recordMap_.cend() || it->second != record) |  | ||||||
|                     { |                     { | ||||||
|                        recordMap_.insert_or_assign(product, record); |                        const auto& header = level3File->message()->header(); | ||||||
|  |                        productTime = | ||||||
|  |                           util::TimePoint(header.date_of_message(), | ||||||
|  |                                           header.time_of_message() * 1000); | ||||||
|  |                     } | ||||||
| 
 | 
 | ||||||
|  |                     // If the record is from the last 30 minutes
 | ||||||
|  |                     if (productTime + 30min >= time || | ||||||
|  |                         productTime + 30min >= std::chrono::system_clock::now()) | ||||||
|  |                     { | ||||||
|  |                        // Store loaded record
 | ||||||
|  |                        std::unique_lock lock {recordMutex_}; | ||||||
|  | 
 | ||||||
|  |                        auto it = recordMap_.find(product); | ||||||
|  |                        if (it == recordMap_.cend() || it->second != record) | ||||||
|  |                        { | ||||||
|  |                           recordMap_.insert_or_assign(product, record); | ||||||
|  | 
 | ||||||
|  |                           lock.unlock(); | ||||||
|  | 
 | ||||||
|  |                           Q_EMIT self_->ProductUpdated(product); | ||||||
|  |                        } | ||||||
|  |                     } | ||||||
|  |                     else | ||||||
|  |                     { | ||||||
|  |                        // If product is more than 30 minutes old, discard
 | ||||||
|  |                        std::unique_lock lock {recordMutex_}; | ||||||
|  |                        std::size_t elementsRemoved = recordMap_.erase(product); | ||||||
|                        lock.unlock(); |                        lock.unlock(); | ||||||
| 
 | 
 | ||||||
|  |                        if (elementsRemoved > 0) | ||||||
|  |                        { | ||||||
|  |                           Q_EMIT self_->ProductUpdated(product); | ||||||
|  |                        } | ||||||
|  | 
 | ||||||
|  |                        logger_->trace("Discarding stale data: {}", | ||||||
|  |                                       util::TimeString(productTime)); | ||||||
|  |                     } | ||||||
|  |                  } | ||||||
|  |                  else | ||||||
|  |                  { | ||||||
|  |                     // If the product doesn't exist, erase the stale product
 | ||||||
|  |                     std::unique_lock lock {recordMutex_}; | ||||||
|  |                     std::size_t elementsRemoved = recordMap_.erase(product); | ||||||
|  |                     lock.unlock(); | ||||||
|  | 
 | ||||||
|  |                     if (elementsRemoved > 0) | ||||||
|  |                     { | ||||||
|                        Q_EMIT self_->ProductUpdated(product); |                        Q_EMIT self_->ProductUpdated(product); | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     logger_->trace("Removing stale product"); | ||||||
|                  } |                  } | ||||||
|               }); |               }); | ||||||
|    } |    } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat