diff --git a/src/mtconnect/pipeline/shdr_token_mapper.cpp b/src/mtconnect/pipeline/shdr_token_mapper.cpp index 9af7bde7..7d9fcebe 100644 --- a/src/mtconnect/pipeline/shdr_token_mapper.cpp +++ b/src/mtconnect/pipeline/shdr_token_mapper.cpp @@ -243,7 +243,12 @@ namespace mtconnect { entity::Requirements *reqs {nullptr}; // Extract the remaining tokens - if (dataItem->isSample()) + if ((dataItem->isDataSet() || dataItem->isTable()) && + (dataItem->isSample() || dataItem->isEvent())) + { + reqs = &s_dataSet; + } + else if (dataItem->isSample()) { if (dataItem->isTimeSeries()) reqs = &s_timeseries; @@ -258,8 +263,6 @@ namespace mtconnect { reqs = &s_message; else if (dataItem->isAlarm()) reqs = &s_alarm; - else if (dataItem->isDataSet() || dataItem->isTable()) - reqs = &s_dataSet; else if (dataItem->isAssetChanged() || dataItem->isAssetRemoved()) reqs = &s_assetEvent; else diff --git a/test_package/data_item_mapping_test.cpp b/test_package/data_item_mapping_test.cpp index 56f518b8..ad36974f 100644 --- a/test_package/data_item_mapping_test.cpp +++ b/test_package/data_item_mapping_test.cpp @@ -107,7 +107,7 @@ class DataItemMappingTest : public testing::Test inline DataSetEntry operator"" _E(const char *c, std::size_t) { return DataSetEntry(c); } -TEST_F(DataItemMappingTest, SimpleEvent) +TEST_F(DataItemMappingTest, should_map_simple_sample) { Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}}; auto di = makeDataItem(props); @@ -128,7 +128,7 @@ TEST_F(DataItemMappingTest, SimpleEvent) ASSERT_EQ("READY", event->getValue()); } -TEST_F(DataItemMappingTest, SimpleUnavailableEvent) +TEST_F(DataItemMappingTest, should_map_simple_unavailable_event) { Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}}; auto di = makeDataItem(props); @@ -148,7 +148,7 @@ TEST_F(DataItemMappingTest, SimpleUnavailableEvent) ASSERT_TRUE(event->isUnavailable()); } -TEST_F(DataItemMappingTest, TwoSimpleEvents) +TEST_F(DataItemMappingTest, should_map_two_simple_events) { Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}}; auto di = makeDataItem(props); @@ -178,7 +178,7 @@ TEST_F(DataItemMappingTest, TwoSimpleEvents) } } -TEST_F(DataItemMappingTest, Message) +TEST_F(DataItemMappingTest, should_map_a_message) { Properties props {{"id", "a"s}, {"type", "MESSAGE"s}, {"category", "EVENT"s}}; auto di = makeDataItem(props); @@ -201,7 +201,7 @@ TEST_F(DataItemMappingTest, Message) } } -TEST_F(DataItemMappingTest, SampleTest) +TEST_F(DataItemMappingTest, should_map_a_sample_and_validate_type) { auto di = makeDataItem( {{"id", "a"s}, {"type", "POSITION"s}, {"category", "SAMPLE"s}, {"units", "MILLIMETER"}}); @@ -220,7 +220,7 @@ TEST_F(DataItemMappingTest, SampleTest) ASSERT_EQ(1.23456, sample->getValue()); } -TEST_F(DataItemMappingTest, SampleTestFormatIssue) +TEST_F(DataItemMappingTest, should_map_a_sample_with_invalid_data_to_unavailable) { makeDataItem( {{"id", "a"s}, {"type", "POSITION"s}, {"category", "SAMPLE"s}, {"units", "MILLIMETER"s}}); @@ -234,7 +234,7 @@ TEST_F(DataItemMappingTest, SampleTestFormatIssue) ASSERT_TRUE(sample->isUnavailable()); } -TEST_F(DataItemMappingTest, SampleTimeseries) +TEST_F(DataItemMappingTest, should_map_a_timeseries_sample) { auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, @@ -255,7 +255,7 @@ TEST_F(DataItemMappingTest, SampleTimeseries) ASSERT_EQ(100.0, sample->get("sampleRate")); } -TEST_F(DataItemMappingTest, SampleResetTrigger) +TEST_F(DataItemMappingTest, should_map_a_reset_trigger_for_a_sample) { auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, @@ -276,7 +276,7 @@ TEST_F(DataItemMappingTest, SampleResetTrigger) ASSERT_EQ("MANUAL", sample->get("resetTriggered")); } -TEST_F(DataItemMappingTest, Condition) +TEST_F(DataItemMappingTest, should_map_a_simple_condition) { auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}}); // ||||| @@ -297,7 +297,7 @@ TEST_F(DataItemMappingTest, Condition) ASSERT_EQ("Fault", cond->getName()); } -TEST_F(DataItemMappingTest, ConditionNormal) +TEST_F(DataItemMappingTest, should_map_a_simple_condition_normal) { auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}}); // ||||| @@ -319,7 +319,7 @@ TEST_F(DataItemMappingTest, ConditionNormal) ASSERT_EQ("Normal", cond->getName()); } -TEST_F(DataItemMappingTest, ConditionNormalPartial) +TEST_F(DataItemMappingTest, should_map_a_partial_condition_normal) { auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}}); // ||||| @@ -340,7 +340,7 @@ TEST_F(DataItemMappingTest, ConditionNormalPartial) ASSERT_EQ("Normal", cond->getName()); } -TEST_F(DataItemMappingTest, DataSet) +TEST_F(DataItemMappingTest, should_map_an_event_data_set) { auto di = makeDataItem({{"id", "a"s}, {"type", "SOMETHING"s}, @@ -365,7 +365,33 @@ TEST_F(DataItemMappingTest, DataSet) ASSERT_EQ("abc", get(ds.find("c"_E)->m_value)); } -TEST_F(DataItemMappingTest, Table) +TEST_F(DataItemMappingTest, should_map_a_sample_data_set) +{ + auto di = makeDataItem({{"id", "a"s}, + {"type", "SOMETHING"s}, + {"category", "SAMPLE"s}, + {"representation", "DATA_SET"s}}); + + auto ts = makeTimestamped({"a", "a=1 b=2 c={3}"}); + auto observations = (*m_mapper)(ts); + auto oblist = observations->getValue(); + ASSERT_EQ(1, oblist.size()); + + auto set = dynamic_pointer_cast(oblist.front()); + ASSERT_TRUE(set); + ASSERT_EQ("SomethingDataSet", set->getName()); + + ASSERT_EQ(di, set->getDataItem()); + + auto &ds = set->getValue(); + ASSERT_EQ(3, ds.size()); + ASSERT_EQ(1, get(ds.find("a"_E)->m_value)); + ASSERT_EQ(2, get(ds.find("b"_E)->m_value)); + ASSERT_EQ("3", get(ds.find("c"_E)->m_value)); +} + + +TEST_F(DataItemMappingTest, should_map_an_event_table) { auto di = makeDataItem( {{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "EVENT"s}, {"representation", "TABLE"s}}); @@ -399,7 +425,42 @@ TEST_F(DataItemMappingTest, Table) ASSERT_EQ("def", get(c.find("y"_E)->m_value)); } -TEST_F(DataItemMappingTest, DataSetResetTriggered) +TEST_F(DataItemMappingTest, should_map_an_sample_table) +{ + auto di = makeDataItem( + {{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "SAMPLE"s}, {"representation", "TABLE"s}}); + + auto ts = makeTimestamped({"a", "a={c=1 n=3.0} b={d=2 e=3} c={x=abc y=def}"}); + auto observations = (*m_mapper)(ts); + auto oblist = observations->getValue(); + ASSERT_EQ(1, oblist.size()); + + auto set = dynamic_pointer_cast(oblist.front()); + ASSERT_TRUE(set); + + ASSERT_EQ(di, set->getDataItem()); + ASSERT_EQ("SomethingTable", set->getName()); + + auto &ds = set->getValue(); + ASSERT_EQ(3, ds.size()); + auto a = get(ds.find("a"_E)->m_value); + ASSERT_EQ(2, a.size()); + ASSERT_EQ(1, get(a.find("c"_E)->m_value)); + ASSERT_EQ(3.0, get(a.find("n"_E)->m_value)); + + auto b = get(ds.find("b"_E)->m_value); + ASSERT_EQ(2, a.size()); + ASSERT_EQ(2, get(b.find("d"_E)->m_value)); + ASSERT_EQ(3, get(b.find("e"_E)->m_value)); + + auto c = get(ds.find("c"_E)->m_value); + ASSERT_EQ(2, c.size()); + ASSERT_EQ("abc", get(c.find("x"_E)->m_value)); + ASSERT_EQ("def", get(c.find("y"_E)->m_value)); +} + + +TEST_F(DataItemMappingTest, should_handle_data_set_reset_trigger) { makeDataItem({{"id", "a"s}, {"type", "SOMETHING"s}, @@ -420,7 +481,7 @@ TEST_F(DataItemMappingTest, DataSetResetTriggered) ASSERT_EQ(3, ds.size()); } -TEST_F(DataItemMappingTest, TableResetTriggered) +TEST_F(DataItemMappingTest, should_handle_table_reset_trigger) { makeDataItem( {{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "EVENT"s}, {"representation", "TABLE"s}});