From a202e0e2a0a74df0b40f275bd97958006edda7ce Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 23 Jan 2022 16:53:45 -0600 Subject: [PATCH] Support text product updates --- test/data | 2 +- .../scwx/awips/text_product_file.test.cpp | 21 +++++++++++++++++++ .../scwx/awips/text_product_message.hpp | 3 +++ wxdata/include/scwx/awips/wmo_header.hpp | 2 ++ .../source/scwx/awips/text_product_file.cpp | 15 ++++++++++++- .../scwx/awips/text_product_message.cpp | 6 +++++- wxdata/source/scwx/awips/wmo_header.cpp | 20 ++++++++++++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) diff --git a/test/data b/test/data index 9d377550..b8c76bd2 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 9d377550477ba00b9da3b594b838ba08d3ebcaaf +Subproject commit b8c76bd23f636f9dad08efafa348dcbfe878f0b1 diff --git a/test/source/scwx/awips/text_product_file.test.cpp b/test/source/scwx/awips/text_product_file.test.cpp index 30991b8f..52426a1d 100644 --- a/test/source/scwx/awips/text_product_file.test.cpp +++ b/test/source/scwx/awips/text_product_file.test.cpp @@ -35,5 +35,26 @@ INSTANTIATE_TEST_SUITE_P( "/warnings/warnings_20210606_22-59.txt", "/nexrad/level3/KLSX_NOUS63_FTMLSX_202201041404")); +TEST(TextProductFile, Update) +{ + const std::string filename1 {std::string(SCWX_TEST_DATA_DIR) + + "/warnings/warnings_20210606_22-08.txt"}; + const std::string filename2 {std::string(SCWX_TEST_DATA_DIR) + + "/warnings/warnings_20210606_22-19.txt"}; + const std::string filename3 {std::string(SCWX_TEST_DATA_DIR) + + "/warnings/warnings_20210606_22-59.txt"}; + + TextProductFile file; + + file.LoadFile(filename1); + EXPECT_EQ(file.message_count(), 2); + + file.LoadFile(filename2); + EXPECT_EQ(file.message_count(), 4); + + file.LoadFile(filename3); + EXPECT_EQ(file.message_count(), 13); +} + } // namespace awips } // namespace scwx diff --git a/wxdata/include/scwx/awips/text_product_message.hpp b/wxdata/include/scwx/awips/text_product_message.hpp index c336dac7..bdfe630c 100644 --- a/wxdata/include/scwx/awips/text_product_message.hpp +++ b/wxdata/include/scwx/awips/text_product_message.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -24,6 +25,8 @@ public: TextProductMessage(TextProductMessage&&) noexcept; TextProductMessage& operator=(TextProductMessage&&) noexcept; + std::shared_ptr wmo_header() const; + size_t data_size() const; bool Parse(std::istream& is) override; diff --git a/wxdata/include/scwx/awips/wmo_header.hpp b/wxdata/include/scwx/awips/wmo_header.hpp index e7094fc4..c209b0e9 100644 --- a/wxdata/include/scwx/awips/wmo_header.hpp +++ b/wxdata/include/scwx/awips/wmo_header.hpp @@ -33,6 +33,8 @@ public: WmoHeader(WmoHeader&&) noexcept; WmoHeader& operator=(WmoHeader&&) noexcept; + bool operator==(const WmoHeader& o) const; + const std::string& sequence_number() const; const std::string& data_type() const; const std::string& geographic_designator() const; diff --git a/wxdata/source/scwx/awips/text_product_file.cpp b/wxdata/source/scwx/awips/text_product_file.cpp index 847e643c..724c258c 100644 --- a/wxdata/source/scwx/awips/text_product_file.cpp +++ b/wxdata/source/scwx/awips/text_product_file.cpp @@ -68,10 +68,23 @@ bool TextProductFile::LoadData(std::istream& is) { std::shared_ptr message = TextProductMessage::Create(is); + bool duplicate = false; if (message != nullptr) { - p->messages_.push_back(message); + for (auto m : p->messages_) + { + if (*m->wmo_header().get() == *message->wmo_header().get()) + { + duplicate = true; + break; + } + } + + if (!duplicate) + { + p->messages_.push_back(message); + } } else { diff --git a/wxdata/source/scwx/awips/text_product_message.cpp b/wxdata/source/scwx/awips/text_product_message.cpp index 7a3ab4ae..e205c066 100644 --- a/wxdata/source/scwx/awips/text_product_message.cpp +++ b/wxdata/source/scwx/awips/text_product_message.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -100,6 +99,11 @@ TextProductMessage::TextProductMessage(TextProductMessage&&) noexcept = default; TextProductMessage& TextProductMessage::operator=(TextProductMessage&&) noexcept = default; +std::shared_ptr TextProductMessage::wmo_header() const +{ + return p->wmoHeader_; +} + size_t TextProductMessage::data_size() const { return 0; diff --git a/wxdata/source/scwx/awips/wmo_header.cpp b/wxdata/source/scwx/awips/wmo_header.cpp index f2dc92b9..d2f1e192 100644 --- a/wxdata/source/scwx/awips/wmo_header.cpp +++ b/wxdata/source/scwx/awips/wmo_header.cpp @@ -37,6 +37,8 @@ public: } ~WmoHeaderImpl() = default; + bool operator==(const WmoHeaderImpl& o) const; + std::string sequenceNumber_; std::string dataType_; std::string geographicDesignator_; @@ -54,6 +56,24 @@ WmoHeader::~WmoHeader() = default; WmoHeader::WmoHeader(WmoHeader&&) noexcept = default; WmoHeader& WmoHeader::operator=(WmoHeader&&) noexcept = default; +bool WmoHeader::operator==(const WmoHeader& o) const +{ + return (*p.get() == *o.p.get()); +} + +bool WmoHeaderImpl::operator==(const WmoHeaderImpl& o) const +{ + return (sequenceNumber_ == o.sequenceNumber_ && // + dataType_ == o.dataType_ && // + geographicDesignator_ == o.geographicDesignator_ && // + bulletinId_ == o.bulletinId_ && // + icao_ == o.icao_ && // + dateTime_ == o.dateTime_ && // + bbbIndicator_ == o.bbbIndicator_ && // + productCategory_ == o.productCategory_ && // + productDesignator_ == o.productDesignator_); +} + const std::string& WmoHeader::sequence_number() const { return p->sequenceNumber_;