mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 07:00:06 +00:00 
			
		
		
		
	Fix stale storm tracking information logic to use selected time
This commit is contained in:
		
							parent
							
								
									925f91995a
								
							
						
					
					
						commit
						6eb9caf819
					
				
					 1 changed files with 62 additions and 61 deletions
				
			
		|  | @ -137,77 +137,78 @@ void OverlayProductView::Impl::LoadProduct( | ||||||
| 
 | 
 | ||||||
|    if (autoUpdate) |    if (autoUpdate) | ||||||
|    { |    { | ||||||
|       connect(request.get(), |       connect( | ||||||
|               &request::NexradFileRequest::RequestComplete, |          request.get(), | ||||||
|               self_, |          &request::NexradFileRequest::RequestComplete, | ||||||
|               [=, this](std::shared_ptr<request::NexradFileRequest> request) |          self_, | ||||||
|               { |          [=, this](std::shared_ptr<request::NexradFileRequest> request) | ||||||
|                  using namespace std::chrono_literals; |          { | ||||||
|  |             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) | ||||||
|                  { |             { | ||||||
|                     auto productTime = record->time(); |                auto productTime = record->time(); | ||||||
|                     auto level3File  = record->level3_file(); |                auto level3File  = record->level3_file(); | ||||||
|                     if (level3File != nullptr) |                if (level3File != nullptr) | ||||||
|                     { |                { | ||||||
|                        const auto& header = level3File->message()->header(); |                   const auto& header = level3File->message()->header(); | ||||||
|                        productTime = |                   productTime        = util::TimePoint( | ||||||
|                           util::TimePoint(header.date_of_message(), |                      header.date_of_message(), header.time_of_message() * 1000); | ||||||
|                                           header.time_of_message() * 1000); |                } | ||||||
|                     } |  | ||||||
| 
 | 
 | ||||||
|                     // If the record is from the last 30 minutes
 |                // If the record is from the last 30 minutes
 | ||||||
|                     if (productTime + 30min >= time || |                if (productTime + 30min >= std::chrono::system_clock::now() || | ||||||
|                         productTime + 30min >= std::chrono::system_clock::now()) |                    (selectedTime_ != std::chrono::system_clock::time_point {} && | ||||||
|                     { |                     productTime + 30min >= selectedTime_)) | ||||||
|                        // Store loaded record
 |                { | ||||||
|                        std::unique_lock lock {recordMutex_}; |                   // Store loaded record
 | ||||||
|  |                   std::unique_lock lock {recordMutex_}; | ||||||
| 
 | 
 | ||||||
|                        auto it = recordMap_.find(product); |                   auto it = recordMap_.find(product); | ||||||
|                        if (it == recordMap_.cend() || it->second != record) |                   if (it == recordMap_.cend() || it->second != record) | ||||||
|                        { |                   { | ||||||
|                           recordMap_.insert_or_assign(product, record); |                      recordMap_.insert_or_assign(product, record); | ||||||
| 
 | 
 | ||||||
|                           lock.unlock(); |                      lock.unlock(); | ||||||
| 
 | 
 | ||||||
|                           Q_EMIT self_->ProductUpdated(product); |                      Q_EMIT self_->ProductUpdated(product); | ||||||
|                        } |                   } | ||||||
|                     } |                } | ||||||
|                     else |                else | ||||||
|                     { |                { | ||||||
|                        // If product is more than 30 minutes old, discard
 |                   // If product is more than 30 minutes old, discard
 | ||||||
|                        std::unique_lock lock {recordMutex_}; |                   std::unique_lock lock {recordMutex_}; | ||||||
|                        std::size_t elementsRemoved = recordMap_.erase(product); |                   std::size_t      elementsRemoved = recordMap_.erase(product); | ||||||
|                        lock.unlock(); |                   lock.unlock(); | ||||||
| 
 | 
 | ||||||
|                        if (elementsRemoved > 0) |                   if (elementsRemoved > 0) | ||||||
|                        { |                   { | ||||||
|                           Q_EMIT self_->ProductUpdated(product); |                      Q_EMIT self_->ProductUpdated(product); | ||||||
|                        } |                   } | ||||||
| 
 | 
 | ||||||
|                        logger_->trace("Discarding stale data: {}", |                   logger_->trace("Discarding stale data: {}", | ||||||
|                                       util::TimeString(productTime)); |                                  util::TimeString(productTime)); | ||||||
|                     } |                } | ||||||
|                  } |             } | ||||||
|                  else |             else | ||||||
|                  { |             { | ||||||
|                     // If the product doesn't exist, erase the stale product
 |                // If the product doesn't exist, erase the stale product
 | ||||||
|                     std::unique_lock lock {recordMutex_}; |                std::unique_lock lock {recordMutex_}; | ||||||
|                     std::size_t elementsRemoved = recordMap_.erase(product); |                std::size_t      elementsRemoved = recordMap_.erase(product); | ||||||
|                     lock.unlock(); |                lock.unlock(); | ||||||
| 
 | 
 | ||||||
|                     if (elementsRemoved > 0) |                if (elementsRemoved > 0) | ||||||
|                     { |                { | ||||||
|                        Q_EMIT self_->ProductUpdated(product); |                   Q_EMIT self_->ProductUpdated(product); | ||||||
|                     } |                } | ||||||
| 
 | 
 | ||||||
|                     logger_->trace("Removing stale product"); |                logger_->trace("Removing stale product"); | ||||||
|                  } |             } | ||||||
|               }); |          }); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    // Load file
 |    // Load file
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat