Skip to content

Commit 6fe66eb

Browse files
authored
Merge pull request #532 from mtconnect/531_verify_conversion_of_kW_h_to_W_s
2 parents 40c3d72 + 3f415d7 commit 6fe66eb

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set(AGENT_VERSION_MAJOR 2)
33
set(AGENT_VERSION_MINOR 5)
44
set(AGENT_VERSION_PATCH 0)
5-
set(AGENT_VERSION_BUILD 2)
5+
set(AGENT_VERSION_BUILD 3)
66
set(AGENT_VERSION_RC "")
77

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

src/mtconnect/device_model/data_item/unit_conversion.cpp

+23-9
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,31 @@ namespace mtconnect::device_model::data_item {
171171

172172
factor = sscale / tscale;
173173

174-
key = source;
175-
key = key.append("-").append(target);
174+
vector<string> sunits;
175+
boost::split(sunits, source, boost::is_any_of("_"));
176176

177-
const auto &conversion = m_conversions.find(string(key));
178-
// Check for no support units and not power or factor scaling.
179-
if (conversion == m_conversions.end() && factor == 1.0)
180-
return nullptr;
181-
else if (conversion != m_conversions.end())
177+
vector<string> tunits;
178+
boost::split(tunits, target, boost::is_any_of("_"));
179+
180+
if (sunits.size() == tunits.size())
182181
{
183-
factor *= conversion->second.factor();
184-
offset = conversion->second.offset();
182+
for (auto si = sunits.begin(), ti = tunits.begin();
183+
si != sunits.end() && ti != tunits.end(); si++, ti++)
184+
{
185+
key = *si;
186+
key = key.append("-").append(*ti);
187+
188+
const auto &conversion = m_conversions.find(string(key));
189+
190+
// Check for no support units and not power or factor scaling.
191+
if (conversion == m_conversions.end() && factor == 1.0)
192+
return nullptr;
193+
else if (conversion != m_conversions.end())
194+
{
195+
factor *= conversion->second.factor();
196+
offset = conversion->second.offset();
197+
}
198+
}
185199
}
186200

187201
if (tpower != 1.0)

src/mtconnect/entity/xml_parser.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ namespace mtconnect::entity {
123123
}
124124
}
125125

126-
/// TODO: Add support for tables
127126
DataSetValue value;
128127
auto valueNode = child->children;
129128
if (valueNode)

test_package/unit_conversion_test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,8 @@ TEST(UnitConversionTest, check_conversion_from_kw_h_to_watt_second)
142142
auto conv = UnitConversion::make("KILOWATT/HOUR", "WATT/SECOND");
143143
EXPECT_NEAR(0.16666, conv->convert(0.6), 0.001);
144144
EXPECT_NEAR(0.25556, conv->convert(0.92), 0.001);
145+
146+
conv = UnitConversion::make("KILOWATT_HOUR", "WATT_SECOND");
147+
EXPECT_NEAR(2160000.0, conv->convert(0.6), 0.001);
148+
EXPECT_NEAR(3312000.0, conv->convert(0.92), 0.001);
145149
}

0 commit comments

Comments
 (0)