Skip to content

Commit 33d8e5b

Browse files
authored
Merge pull request mtconnect#501 from mtconnect/500_data_set_samples
2 parents 5b941a1 + ba09b66 commit 33d8e5b

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set(AGENT_VERSION_MAJOR 2)
33
set(AGENT_VERSION_MINOR 4)
44
set(AGENT_VERSION_PATCH 0)
5-
set(AGENT_VERSION_BUILD 6)
5+
set(AGENT_VERSION_BUILD 7)
66
set(AGENT_VERSION_RC "")
77

88
# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent

src/mtconnect/pipeline/shdr_token_mapper.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ namespace mtconnect {
243243
entity::Requirements *reqs {nullptr};
244244

245245
// Extract the remaining tokens
246-
if (dataItem->isSample())
246+
if ((dataItem->isDataSet() || dataItem->isTable()) &&
247+
(dataItem->isSample() || dataItem->isEvent()))
248+
{
249+
reqs = &s_dataSet;
250+
}
251+
else if (dataItem->isSample())
247252
{
248253
if (dataItem->isTimeSeries())
249254
reqs = &s_timeseries;
@@ -258,8 +263,6 @@ namespace mtconnect {
258263
reqs = &s_message;
259264
else if (dataItem->isAlarm())
260265
reqs = &s_alarm;
261-
else if (dataItem->isDataSet() || dataItem->isTable())
262-
reqs = &s_dataSet;
263266
else if (dataItem->isAssetChanged() || dataItem->isAssetRemoved())
264267
reqs = &s_assetEvent;
265268
else

test_package/data_item_mapping_test.cpp

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class DataItemMappingTest : public testing::Test
107107

108108
inline DataSetEntry operator"" _E(const char *c, std::size_t) { return DataSetEntry(c); }
109109

110-
TEST_F(DataItemMappingTest, SimpleEvent)
110+
TEST_F(DataItemMappingTest, should_map_simple_sample)
111111
{
112112
Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}};
113113
auto di = makeDataItem(props);
@@ -128,7 +128,7 @@ TEST_F(DataItemMappingTest, SimpleEvent)
128128
ASSERT_EQ("READY", event->getValue<string>());
129129
}
130130

131-
TEST_F(DataItemMappingTest, SimpleUnavailableEvent)
131+
TEST_F(DataItemMappingTest, should_map_simple_unavailable_event)
132132
{
133133
Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}};
134134
auto di = makeDataItem(props);
@@ -148,7 +148,7 @@ TEST_F(DataItemMappingTest, SimpleUnavailableEvent)
148148
ASSERT_TRUE(event->isUnavailable());
149149
}
150150

151-
TEST_F(DataItemMappingTest, TwoSimpleEvents)
151+
TEST_F(DataItemMappingTest, should_map_two_simple_events)
152152
{
153153
Properties props {{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}};
154154
auto di = makeDataItem(props);
@@ -178,7 +178,7 @@ TEST_F(DataItemMappingTest, TwoSimpleEvents)
178178
}
179179
}
180180

181-
TEST_F(DataItemMappingTest, Message)
181+
TEST_F(DataItemMappingTest, should_map_a_message)
182182
{
183183
Properties props {{"id", "a"s}, {"type", "MESSAGE"s}, {"category", "EVENT"s}};
184184
auto di = makeDataItem(props);
@@ -201,7 +201,7 @@ TEST_F(DataItemMappingTest, Message)
201201
}
202202
}
203203

204-
TEST_F(DataItemMappingTest, SampleTest)
204+
TEST_F(DataItemMappingTest, should_map_a_sample_and_validate_type)
205205
{
206206
auto di = makeDataItem(
207207
{{"id", "a"s}, {"type", "POSITION"s}, {"category", "SAMPLE"s}, {"units", "MILLIMETER"}});
@@ -220,7 +220,7 @@ TEST_F(DataItemMappingTest, SampleTest)
220220
ASSERT_EQ(1.23456, sample->getValue<double>());
221221
}
222222

223-
TEST_F(DataItemMappingTest, SampleTestFormatIssue)
223+
TEST_F(DataItemMappingTest, should_map_a_sample_with_invalid_data_to_unavailable)
224224
{
225225
makeDataItem(
226226
{{"id", "a"s}, {"type", "POSITION"s}, {"category", "SAMPLE"s}, {"units", "MILLIMETER"s}});
@@ -234,7 +234,7 @@ TEST_F(DataItemMappingTest, SampleTestFormatIssue)
234234
ASSERT_TRUE(sample->isUnavailable());
235235
}
236236

237-
TEST_F(DataItemMappingTest, SampleTimeseries)
237+
TEST_F(DataItemMappingTest, should_map_a_timeseries_sample)
238238
{
239239
auto di = makeDataItem({{"id", "a"s},
240240
{"type", "POSITION"s},
@@ -255,7 +255,7 @@ TEST_F(DataItemMappingTest, SampleTimeseries)
255255
ASSERT_EQ(100.0, sample->get<double>("sampleRate"));
256256
}
257257

258-
TEST_F(DataItemMappingTest, SampleResetTrigger)
258+
TEST_F(DataItemMappingTest, should_map_a_reset_trigger_for_a_sample)
259259
{
260260
auto di = makeDataItem({{"id", "a"s},
261261
{"type", "POSITION"s},
@@ -276,7 +276,7 @@ TEST_F(DataItemMappingTest, SampleResetTrigger)
276276
ASSERT_EQ("MANUAL", sample->get<string>("resetTriggered"));
277277
}
278278

279-
TEST_F(DataItemMappingTest, Condition)
279+
TEST_F(DataItemMappingTest, should_map_a_simple_condition)
280280
{
281281
auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}});
282282
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
@@ -297,7 +297,7 @@ TEST_F(DataItemMappingTest, Condition)
297297
ASSERT_EQ("Fault", cond->getName());
298298
}
299299

300-
TEST_F(DataItemMappingTest, ConditionNormal)
300+
TEST_F(DataItemMappingTest, should_map_a_simple_condition_normal)
301301
{
302302
auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}});
303303
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
@@ -319,7 +319,7 @@ TEST_F(DataItemMappingTest, ConditionNormal)
319319
ASSERT_EQ("Normal", cond->getName());
320320
}
321321

322-
TEST_F(DataItemMappingTest, ConditionNormalPartial)
322+
TEST_F(DataItemMappingTest, should_map_a_partial_condition_normal)
323323
{
324324
auto di = makeDataItem({{"id", "a"s}, {"type", "POSITION"s}, {"category", "CONDITION"s}});
325325
// <data_item_name>|<level>|<native_code>|<native_severity>|<qualifier>|<message>
@@ -340,7 +340,7 @@ TEST_F(DataItemMappingTest, ConditionNormalPartial)
340340
ASSERT_EQ("Normal", cond->getName());
341341
}
342342

343-
TEST_F(DataItemMappingTest, DataSet)
343+
TEST_F(DataItemMappingTest, should_map_an_event_data_set)
344344
{
345345
auto di = makeDataItem({{"id", "a"s},
346346
{"type", "SOMETHING"s},
@@ -365,7 +365,33 @@ TEST_F(DataItemMappingTest, DataSet)
365365
ASSERT_EQ("abc", get<string>(ds.find("c"_E)->m_value));
366366
}
367367

368-
TEST_F(DataItemMappingTest, Table)
368+
TEST_F(DataItemMappingTest, should_map_a_sample_data_set)
369+
{
370+
auto di = makeDataItem({{"id", "a"s},
371+
{"type", "SOMETHING"s},
372+
{"category", "SAMPLE"s},
373+
{"representation", "DATA_SET"s}});
374+
375+
auto ts = makeTimestamped({"a", "a=1 b=2 c={3}"});
376+
auto observations = (*m_mapper)(ts);
377+
auto oblist = observations->getValue<EntityList>();
378+
ASSERT_EQ(1, oblist.size());
379+
380+
auto set = dynamic_pointer_cast<DataSetEvent>(oblist.front());
381+
ASSERT_TRUE(set);
382+
ASSERT_EQ("SomethingDataSet", set->getName());
383+
384+
ASSERT_EQ(di, set->getDataItem());
385+
386+
auto &ds = set->getValue<DataSet>();
387+
ASSERT_EQ(3, ds.size());
388+
ASSERT_EQ(1, get<int64_t>(ds.find("a"_E)->m_value));
389+
ASSERT_EQ(2, get<int64_t>(ds.find("b"_E)->m_value));
390+
ASSERT_EQ("3", get<string>(ds.find("c"_E)->m_value));
391+
}
392+
393+
394+
TEST_F(DataItemMappingTest, should_map_an_event_table)
369395
{
370396
auto di = makeDataItem(
371397
{{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "EVENT"s}, {"representation", "TABLE"s}});
@@ -399,7 +425,42 @@ TEST_F(DataItemMappingTest, Table)
399425
ASSERT_EQ("def", get<string>(c.find("y"_E)->m_value));
400426
}
401427

402-
TEST_F(DataItemMappingTest, DataSetResetTriggered)
428+
TEST_F(DataItemMappingTest, should_map_an_sample_table)
429+
{
430+
auto di = makeDataItem(
431+
{{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "SAMPLE"s}, {"representation", "TABLE"s}});
432+
433+
auto ts = makeTimestamped({"a", "a={c=1 n=3.0} b={d=2 e=3} c={x=abc y=def}"});
434+
auto observations = (*m_mapper)(ts);
435+
auto oblist = observations->getValue<EntityList>();
436+
ASSERT_EQ(1, oblist.size());
437+
438+
auto set = dynamic_pointer_cast<DataSetEvent>(oblist.front());
439+
ASSERT_TRUE(set);
440+
441+
ASSERT_EQ(di, set->getDataItem());
442+
ASSERT_EQ("SomethingTable", set->getName());
443+
444+
auto &ds = set->getValue<DataSet>();
445+
ASSERT_EQ(3, ds.size());
446+
auto a = get<DataSet>(ds.find("a"_E)->m_value);
447+
ASSERT_EQ(2, a.size());
448+
ASSERT_EQ(1, get<int64_t>(a.find("c"_E)->m_value));
449+
ASSERT_EQ(3.0, get<double>(a.find("n"_E)->m_value));
450+
451+
auto b = get<DataSet>(ds.find("b"_E)->m_value);
452+
ASSERT_EQ(2, a.size());
453+
ASSERT_EQ(2, get<int64_t>(b.find("d"_E)->m_value));
454+
ASSERT_EQ(3, get<int64_t>(b.find("e"_E)->m_value));
455+
456+
auto c = get<DataSet>(ds.find("c"_E)->m_value);
457+
ASSERT_EQ(2, c.size());
458+
ASSERT_EQ("abc", get<string>(c.find("x"_E)->m_value));
459+
ASSERT_EQ("def", get<string>(c.find("y"_E)->m_value));
460+
}
461+
462+
463+
TEST_F(DataItemMappingTest, should_handle_data_set_reset_trigger)
403464
{
404465
makeDataItem({{"id", "a"s},
405466
{"type", "SOMETHING"s},
@@ -420,7 +481,7 @@ TEST_F(DataItemMappingTest, DataSetResetTriggered)
420481
ASSERT_EQ(3, ds.size());
421482
}
422483

423-
TEST_F(DataItemMappingTest, TableResetTriggered)
484+
TEST_F(DataItemMappingTest, should_handle_table_reset_trigger)
424485
{
425486
makeDataItem(
426487
{{"id", "a"s}, {"type", "SOMETHING"s}, {"category", "EVENT"s}, {"representation", "TABLE"s}});

0 commit comments

Comments
 (0)