util.cpp (31058fd3fcc5b8b2d09282d89cef64a18e20b5da) util.cpp (3f0f7bc35831d467d912698dc5dbd9dcf9ad10f3)
1/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0

--- 89 unchanged lines hidden (view full) ---

98 }
99 std::cout << "\t},\n";
100 }
101 std::cout << "}\n\n";
102}
103
104std::vector<conf::SensorInput>
105 spliceInputs(const std::vector<std::string>& inputNames,
1/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0

--- 89 unchanged lines hidden (view full) ---

98 }
99 std::cout << "\t},\n";
100 }
101 std::cout << "}\n\n";
102}
103
104std::vector<conf::SensorInput>
105 spliceInputs(const std::vector<std::string>& inputNames,
106 const std::vector<double>& inputTempToMargin)
106 const std::vector<double>& inputTempToMargin,
107 const std::vector<std::string>& missingAcceptableNames)
107{
108 std::vector<conf::SensorInput> results;
109
108{
109 std::vector<conf::SensorInput> results;
110
110 // Default to the TempToMargin feature disabled
111 // Default to TempToMargin and MissingIsAcceptable disabled
111 for (const auto& inputName : inputNames)
112 {
113 conf::SensorInput newInput{
112 for (const auto& inputName : inputNames)
113 {
114 conf::SensorInput newInput{
114 inputName, std::numeric_limits<double>::quiet_NaN(), false};
115 inputName, std::numeric_limits<double>::quiet_NaN(), false, false};
115
116 results.emplace_back(newInput);
117 }
118
119 size_t resultSize = results.size();
120 size_t marginSize = inputTempToMargin.size();
121
122 for (size_t index = 0; index < resultSize; ++index)

--- 4 unchanged lines hidden (view full) ---

127 break;
128 }
129
130 // Both vectors have this index, combine both into SensorInput
131 results[index].convertMarginZero = inputTempToMargin[index];
132 results[index].convertTempToMargin = true;
133 }
134
116
117 results.emplace_back(newInput);
118 }
119
120 size_t resultSize = results.size();
121 size_t marginSize = inputTempToMargin.size();
122
123 for (size_t index = 0; index < resultSize; ++index)

--- 4 unchanged lines hidden (view full) ---

128 break;
129 }
130
131 // Both vectors have this index, combine both into SensorInput
132 results[index].convertMarginZero = inputTempToMargin[index];
133 results[index].convertTempToMargin = true;
134 }
135
136 std::set<std::string> acceptableSet;
137
138 // Copy vector to set, to avoid O(n^2) runtime below
139 for (const auto& name : missingAcceptableNames)
140 {
141 acceptableSet.emplace(name);
142 }
143
144 // Flag missingIsAcceptable true if name found in that set
145 for (auto& result : results)
146 {
147 if (acceptableSet.find(result.name) != acceptableSet.end())
148 {
149 result.missingIsAcceptable = true;
150 }
151 }
152
135 return results;
136}
137
138std::vector<std::string>
139 splitNames(const std::vector<conf::SensorInput>& sensorInputs)
140{
141 std::vector<std::string> results;
142
143 for (const auto& sensorInput : sensorInputs)
144 {
145 results.emplace_back(sensorInput.name);
146 }
147
148 return results;
149}
150
151} // namespace pid_control
153 return results;
154}
155
156std::vector<std::string>
157 splitNames(const std::vector<conf::SensorInput>& sensorInputs)
158{
159 std::vector<std::string> results;
160
161 for (const auto& sensorInput : sensorInputs)
162 {
163 results.emplace_back(sensorInput.name);
164 }
165
166 return results;
167}
168
169} // namespace pid_control