Skip to content

Commit

Permalink
Added support for sample data sets
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel committed Nov 25, 2024
1 parent 5b941a1 commit 1e8095d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/mtconnect/pipeline/shdr_token_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
91 changes: 76 additions & 15 deletions test_package/data_item_mapping_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -128,7 +128,7 @@ TEST_F(DataItemMappingTest, SimpleEvent)
ASSERT_EQ("READY", event->getValue<string>());
}

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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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"}});
Expand All @@ -220,7 +220,7 @@ TEST_F(DataItemMappingTest, SampleTest)
ASSERT_EQ(1.23456, sample->getValue<double>());
}

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}});
Expand All @@ -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},
Expand All @@ -255,7 +255,7 @@ TEST_F(DataItemMappingTest, SampleTimeseries)
ASSERT_EQ(100.0, sample->get<double>("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},
Expand All @@ -276,7 +276,7 @@ TEST_F(DataItemMappingTest, SampleResetTrigger)
ASSERT_EQ("MANUAL", sample->get<string>("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}});
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
Expand All @@ -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}});
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
Expand All @@ -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}});
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
Expand All @@ -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},
Expand All @@ -365,7 +365,33 @@ TEST_F(DataItemMappingTest, DataSet)
ASSERT_EQ("abc", get<string>(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<EntityList>();
ASSERT_EQ(1, oblist.size());

auto set = dynamic_pointer_cast<DataSetEvent>(oblist.front());
ASSERT_TRUE(set);
ASSERT_EQ("SomethingDataSet", set->getName());

ASSERT_EQ(di, set->getDataItem());

auto &ds = set->getValue<DataSet>();
ASSERT_EQ(3, ds.size());
ASSERT_EQ(1, get<int64_t>(ds.find("a"_E)->m_value));
ASSERT_EQ(2, get<int64_t>(ds.find("b"_E)->m_value));
ASSERT_EQ("3", get<string>(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}});
Expand Down Expand Up @@ -399,7 +425,42 @@ TEST_F(DataItemMappingTest, Table)
ASSERT_EQ("def", get<string>(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<EntityList>();
ASSERT_EQ(1, oblist.size());

auto set = dynamic_pointer_cast<DataSetEvent>(oblist.front());
ASSERT_TRUE(set);

ASSERT_EQ(di, set->getDataItem());
ASSERT_EQ("SomethingTable", set->getName());

auto &ds = set->getValue<DataSet>();
ASSERT_EQ(3, ds.size());
auto a = get<DataSet>(ds.find("a"_E)->m_value);
ASSERT_EQ(2, a.size());
ASSERT_EQ(1, get<int64_t>(a.find("c"_E)->m_value));
ASSERT_EQ(3.0, get<double>(a.find("n"_E)->m_value));

auto b = get<DataSet>(ds.find("b"_E)->m_value);
ASSERT_EQ(2, a.size());
ASSERT_EQ(2, get<int64_t>(b.find("d"_E)->m_value));
ASSERT_EQ(3, get<int64_t>(b.find("e"_E)->m_value));

auto c = get<DataSet>(ds.find("c"_E)->m_value);
ASSERT_EQ(2, c.size());
ASSERT_EQ("abc", get<string>(c.find("x"_E)->m_value));
ASSERT_EQ("def", get<string>(c.find("y"_E)->m_value));
}


TEST_F(DataItemMappingTest, should_handle_data_set_reset_trigger)
{
makeDataItem({{"id", "a"s},
{"type", "SOMETHING"s},
Expand All @@ -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}});
Expand Down

0 comments on commit 1e8095d

Please sign in to comment.