From fc74a977d74161335203b61c4d06478b8185cd4b Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Tue, 4 Oct 2022 16:35:27 +0800 Subject: [PATCH 1/4] Adds an API to retrieve keys. This is useful for when we perform visualization. Signed-off-by: Arjo Chakravarty --- io/include/gz/common/DataFrame.hh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/io/include/gz/common/DataFrame.hh b/io/include/gz/common/DataFrame.hh index b5a124dc6..02eda18a1 100644 --- a/io/include/gz/common/DataFrame.hh +++ b/io/include/gz/common/DataFrame.hh @@ -68,6 +68,18 @@ namespace gz return this->storage.at(_key); } + /// \brief Retrieve all keys + /// \return A vector with keys + public: const std::vector Keys() const + { + std::vector keyList; + for (auto &[k, _]: this->storage) + { + keyList.push_back(k); + } + return keyList; + } + /// \brief Data frame storage private: std::unordered_map storage; }; From 6330789fc22326d1e1f139776d09520401253baf Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 6 Oct 2022 16:14:39 +0800 Subject: [PATCH 2/4] Adds a unit test. Signed-off-by: Arjo Chakravarty --- io/src/DataFrame_TEST.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/io/src/DataFrame_TEST.cc b/io/src/DataFrame_TEST.cc index 9100ae6db..c89527782 100644 --- a/io/src/DataFrame_TEST.cc +++ b/io/src/DataFrame_TEST.cc @@ -58,6 +58,9 @@ TEST(DataFrameTests, SimpleCSV) auto temperature = temperatureData.LookUp( temperatureSession.value(), position); ASSERT_TRUE(temperature.has_value()); + auto keys = df.Keys(); + ASSERT_EQ(keys.size(), 1); + ASSERT_EQ(keys[0], "temperature"); EXPECT_DOUBLE_EQ(25.1, temperature.value()); } @@ -80,7 +83,7 @@ TEST(DataFrameTests, ComplexCSV) EXPECT_TRUE(df.Has("temperature")); EXPECT_TRUE(df.Has("humidity")); ASSERT_TRUE(df.Has("pressure")); - + ASSERT_EQ(keys.size(), 3); const DataT &pressureData = df["pressure"]; auto pressureSession = pressureData.CreateSession(); const math::Vector3d position{36.80079505, -121.789472517, 0.8}; From 534eb3212a0694f989e5b65a208e7371297cd2b8 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 6 Oct 2022 16:23:45 +0800 Subject: [PATCH 3/4] Fix compile error. Signed-off-by: Arjo Chakravarty --- io/src/DataFrame_TEST.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/io/src/DataFrame_TEST.cc b/io/src/DataFrame_TEST.cc index c89527782..a03719493 100644 --- a/io/src/DataFrame_TEST.cc +++ b/io/src/DataFrame_TEST.cc @@ -83,6 +83,7 @@ TEST(DataFrameTests, ComplexCSV) EXPECT_TRUE(df.Has("temperature")); EXPECT_TRUE(df.Has("humidity")); ASSERT_TRUE(df.Has("pressure")); + auto keys = df.Keys(); ASSERT_EQ(keys.size(), 3); const DataT &pressureData = df["pressure"]; auto pressureSession = pressureData.CreateSession(); From ff72afbc2d02394e65b0e9125bd333804f873671 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 6 Oct 2022 22:41:59 +0800 Subject: [PATCH 4/4] Fix test expectations. Signed-off-by: Arjo Chakravarty --- io/src/DataFrame_TEST.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/io/src/DataFrame_TEST.cc b/io/src/DataFrame_TEST.cc index 43f9a7e96..fd2e8a215 100644 --- a/io/src/DataFrame_TEST.cc +++ b/io/src/DataFrame_TEST.cc @@ -58,11 +58,17 @@ TEST(DataFrameTests, SimpleCSV) auto temperature = temperatureData.LookUp( temperatureSession.value(), position); ASSERT_TRUE(temperature.has_value()); + EXPECT_DOUBLE_EQ(25.2, temperature.value()); + temperatureSession = temperatureData.StepTo( + temperatureData.CreateSession(), 0.5); + ASSERT_TRUE(temperatureSession.has_value()); + temperature = temperatureData.LookUp( + temperatureSession.value(), position); + ASSERT_TRUE(temperature.has_value()); + EXPECT_DOUBLE_EQ(25.1, temperature.value()); auto keys = df.Keys(); ASSERT_EQ(keys.size(), 1); ASSERT_EQ(keys[0], "temperature"); - - EXPECT_DOUBLE_EQ(25.1, temperature.value()); } /////////////////////////////////////////////////