diff --git a/wxdata/include/scwx/awips/text_product_file.hpp b/wxdata/include/scwx/awips/text_product_file.hpp index 478a93b4..80eda9c8 100644 --- a/wxdata/include/scwx/awips/text_product_file.hpp +++ b/wxdata/include/scwx/awips/text_product_file.hpp @@ -29,7 +29,7 @@ public: std::shared_ptr message(size_t i) const; bool LoadFile(const std::string& filename); - bool LoadData(std::istream& is); + bool LoadData(std::string_view filename, std::istream& is); private: std::unique_ptr p; diff --git a/wxdata/source/scwx/awips/text_product_file.cpp b/wxdata/source/scwx/awips/text_product_file.cpp index 3edc7b2d..cd23516c 100644 --- a/wxdata/source/scwx/awips/text_product_file.cpp +++ b/wxdata/source/scwx/awips/text_product_file.cpp @@ -3,6 +3,8 @@ #include +#include + 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 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 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); } } diff --git a/wxdata/source/scwx/provider/iem_api_provider.cpp b/wxdata/source/scwx/provider/iem_api_provider.cpp index 1d5781f0..66cdc5d6 100644 --- a/wxdata/source/scwx/provider/iem_api_provider.cpp +++ b/wxdata/source/scwx/provider/iem_api_provider.cpp @@ -163,10 +163,11 @@ IemApiProvider::LoadTextProducts(const std::vector& textProducts) if (response.status_code == cpr::status::HTTP_OK) { // Load file + auto productId = asyncResponse.first; std::shared_ptr textProductFile { std::make_shared()}; std::istringstream responseBody {response.text}; - if (textProductFile->LoadData(responseBody)) + if (textProductFile->LoadData(productId, responseBody)) { textProductFiles.push_back(textProductFile); } diff --git a/wxdata/source/scwx/provider/warnings_provider.cpp b/wxdata/source/scwx/provider/warnings_provider.cpp index 6ef7e237..f0d6b8dd 100644 --- a/wxdata/source/scwx/provider/warnings_provider.cpp +++ b/wxdata/source/scwx/provider/warnings_provider.cpp @@ -176,7 +176,7 @@ WarningsProvider::LoadUpdatedFiles( std::shared_ptr textProductFile { std::make_shared()}; std::istringstream responseBody {response.text}; - if (textProductFile->LoadData(responseBody)) + if (textProductFile->LoadData(filename, responseBody)) { updatedFiles.push_back(textProductFile); }