mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 11:00:06 +00:00 
			
		
		
		
	Provide year/month hint to WMO header parser based on filename
This commit is contained in:
		
							parent
							
								
									46972e8769
								
							
						
					
					
						commit
						a6ba312f6b
					
				
					 4 changed files with 31 additions and 5 deletions
				
			
		|  | @ -3,6 +3,8 @@ | |||
| 
 | ||||
| #include <fstream> | ||||
| 
 | ||||
| #include <re2/re2.h> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace awips | ||||
|  | @ -59,16 +61,34 @@ bool TextProductFile::LoadFile(const std::string& filename) | |||
| 
 | ||||
|    if (fileValid) | ||||
|    { | ||||
|       fileValid = LoadData(f); | ||||
|       fileValid = LoadData(filename, f); | ||||
|    } | ||||
| 
 | ||||
|    return fileValid; | ||||
| } | ||||
| 
 | ||||
| bool TextProductFile::LoadData(std::istream& is) | ||||
| bool TextProductFile::LoadData(std::string_view filename, std::istream& is) | ||||
| { | ||||
|    static constexpr LazyRE2 kDateTimePattern_ = { | ||||
|       R"(((?:19|20)\d{2}))"      // Year (YYYY)
 | ||||
|       R"((0[1-9]|1[0-2]))"       // Month (MM)
 | ||||
|       R"((0[1-9]|[12]\d|3[01]))" // Day (DD)
 | ||||
|       R"(_?)"                    // Optional separator (not captured)
 | ||||
|       R"(([01]\d|2[0-3]))"       // Hour (HH)
 | ||||
|    }; | ||||
| 
 | ||||
|    logger_->trace("Loading Data"); | ||||
| 
 | ||||
|    // Attempt to parse the date from the filename
 | ||||
|    std::optional<std::chrono::year_month> yearMonth; | ||||
|    int                                    year {}; | ||||
|    unsigned int                           month {}; | ||||
| 
 | ||||
|    if (RE2::PartialMatch(filename, *kDateTimePattern_, &year, &month)) | ||||
|    { | ||||
|       yearMonth = std::chrono::year {year} / std::chrono::month {month}; | ||||
|    } | ||||
| 
 | ||||
|    while (!is.eof()) | ||||
|    { | ||||
|       std::shared_ptr<TextProductMessage> message = | ||||
|  | @ -88,6 +108,11 @@ bool TextProductFile::LoadData(std::istream& is) | |||
| 
 | ||||
|          if (!duplicate) | ||||
|          { | ||||
|             if (yearMonth.has_value()) | ||||
|             { | ||||
|                message->wmo_header()->SetDateHint(yearMonth.value()); | ||||
|             } | ||||
| 
 | ||||
|             p->messages_.push_back(message); | ||||
|          } | ||||
|       } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat