FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
serial::rotation_warning_utils Namespace Reference

Classes

struct  InferenceResult
 

Enumerations

enum class  ValueKind { Angle , Rate }
 
enum class  Confidence { None , Low , Medium , High }
 
enum class  WarningSensitivity { HighConfidence , MediumOrHigh , Aggressive }
 

Functions

InferenceResult infer_unit_from_value (const RealType value, const ValueKind kind) noexcept
 
bool should_warn (const Confidence confidence, const WarningSensitivity sensitivity) noexcept
 
void clear_captured_warnings () noexcept
 
std::vector< std::string > take_captured_warnings ()
 
void maybe_warn_about_rotation_value (const RealType value, const params::RotationAngleUnit declared_unit, const ValueKind kind, const std::string_view source, const std::string_view owner, const std::string_view field)
 

Variables

constexpr WarningSensitivity kWarningSensitivity = WarningSensitivity::MediumOrHigh
 

Enumeration Type Documentation

◆ Confidence

◆ ValueKind

◆ WarningSensitivity

Function Documentation

◆ clear_captured_warnings()

void serial::rotation_warning_utils::clear_captured_warnings ( )
noexcept

Definition at line 260 of file rotation_warning_utils.cpp.

260{ captured_warnings.clear(); }

Referenced by begin_warning_capture(), discard_warning_capture(), and fers_get_interpolated_rotation_path().

+ Here is the caller graph for this function:

◆ infer_unit_from_value()

InferenceResult serial::rotation_warning_utils::infer_unit_from_value ( const RealType  value,
const ValueKind  kind 
)
noexcept

Definition at line 139 of file rotation_warning_utils.cpp.

140 {
141 const RealType abs_value = std::abs(value);
142 const RealType pi = std::numbers::pi_v<RealType>;
143 const RealType two_pi = 2.0 * pi;
144
145 InferenceResult result;
146 if (abs_value <= kEpsilon)
147 {
148 return result;
149 }
150
151 if (abs_value > 360.0)
152 {
153 result.degree_score += 8;
154 }
155 else if (abs_value > 180.0)
156 {
157 result.degree_score += 7;
158 }
159 else if (abs_value > two_pi)
160 {
161 result.degree_score += abs_value < 10.0 ? 3 : 6;
162 }
163 else if (abs_value > pi)
164 {
165 result.degree_score += 2;
166 }
167
168 const bool degree_famous = matches_common_angle(abs_value, common_degree_angles);
169 const bool radian_famous = matches_common_angle(abs_value, common_radian_angles);
170 if (degree_famous && !radian_famous)
171 {
172 result.degree_score += 3;
173 }
174 else if (radian_famous && !degree_famous)
175 {
176 result.radian_score += 3;
177 }
178
179 if (is_near_integer(abs_value))
180 {
181 const RealType rounded = std::round(abs_value);
182 if ((std::fmod(rounded, 45.0) == 0.0) || (std::fmod(rounded, 30.0) == 0.0) ||
183 (std::fmod(rounded, 15.0) == 0.0) || (std::fmod(rounded, 10.0) == 0.0) ||
184 (std::fmod(rounded, 5.0) == 0.0))
185 {
186 result.degree_score += 2;
187 }
188 else
189 {
190 result.degree_score += 1;
191 }
192 }
193 else if ((abs_value <= two_pi + 1.0) && !is_near_tenth(abs_value))
194 {
195 result.radian_score += 1;
196 }
197
198 if (matches_simple_pi_ratio(abs_value))
199 {
200 result.radian_score += 3;
201 }
202
203 if ((kind == ValueKind::Angle) && (abs_value <= two_pi + 0.5) &&
204 (std::abs(result.degree_score - result.radian_score) <= 1))
205 {
206 const RealType degree_distance = best_clean_trig_distance(value * pi / 180.0);
207 const RealType radian_distance = best_clean_trig_distance(value);
208 if (degree_distance + 1e-4 < radian_distance)
209 {
210 ++result.degree_score;
211 }
212 else if (radian_distance + 1e-4 < degree_distance)
213 {
214 ++result.radian_score;
215 }
216 }
217
218 if (result.degree_score == result.radian_score)
219 {
220 result.confidence = Confidence::None;
221 return result;
222 }
223
226 const int lead = std::abs(result.degree_score - result.radian_score);
227 const int max_score = std::max(result.degree_score, result.radian_score);
228
229 if ((lead >= 5) || ((max_score >= 7) && (lead >= 3)))
230 {
231 result.confidence = Confidence::High;
232 }
233 else if ((lead >= 3) || ((max_score >= 5) && (lead >= 2)))
234 {
235 result.confidence = Confidence::Medium;
236 }
237 else if ((lead >= 2) || (max_score >= 4))
238 {
239 result.confidence = Confidence::Low;
240 }
241
242 return result;
243 }
double RealType
Type for real numbers.
Definition config.h:27
@ Radians
Compass azimuth and elevation expressed in radians.
@ Degrees
Compass azimuth and elevation expressed in degrees.

References Angle, serial::rotation_warning_utils::InferenceResult::confidence, serial::rotation_warning_utils::InferenceResult::degree_score, params::Degrees, High, serial::rotation_warning_utils::InferenceResult::inferred_unit, Low, Medium, None, serial::rotation_warning_utils::InferenceResult::radian_score, and params::Radians.

Referenced by maybe_warn_about_rotation_value().

+ Here is the caller graph for this function:

◆ maybe_warn_about_rotation_value()

void serial::rotation_warning_utils::maybe_warn_about_rotation_value ( const RealType  value,
const params::RotationAngleUnit  declared_unit,
const ValueKind  kind,
const std::string_view  source,
const std::string_view  owner,
const std::string_view  field 
)

Definition at line 269 of file rotation_warning_utils.cpp.

272 {
273 const InferenceResult inference = infer_unit_from_value(value, kind);
274 if ((inference.inferred_unit == declared_unit) || !should_warn(inference.confidence, kWarningSensitivity))
275 {
276 return;
277 }
278
279 const std::string message =
280 std::format("{} rotation {} '{}' looks like {} but '{}' was declared (confidence: {}, value: {}). "
281 "Change rotationangleunit or convert existing values.",
282 source, owner, field, unit_token(inference.inferred_unit), unit_token(declared_unit),
283 confidence_token(inference.confidence), value);
284
285 if (std::ranges::find(captured_warnings, message) == captured_warnings.end())
286 {
287 captured_warnings.push_back(message);
288 }
289
290 LOG(logging::Level::WARNING, "{}", message);
291 }
#define LOG(level,...)
Definition logging.h:19
@ WARNING
Warning level for potentially harmful situations.
bool should_warn(const Confidence confidence, const WarningSensitivity sensitivity) noexcept
InferenceResult infer_unit_from_value(const RealType value, const ValueKind kind) noexcept

References serial::rotation_warning_utils::InferenceResult::confidence, infer_unit_from_value(), serial::rotation_warning_utils::InferenceResult::inferred_unit, kWarningSensitivity, LOG, should_warn(), and logging::WARNING.

Referenced by fers_get_interpolated_rotation_path(), serial::xml_parser_utils::parseFixedRotation(), serial::xml_parser_utils::parseRotationPath(), and serial::update_platform_paths_from_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ should_warn()

bool serial::rotation_warning_utils::should_warn ( const Confidence  confidence,
const WarningSensitivity  sensitivity 
)
noexcept

Definition at line 245 of file rotation_warning_utils.cpp.

246 {
247 switch (sensitivity)
248 {
249 case WarningSensitivity::HighConfidence:
250 return confidence == Confidence::High;
251 case WarningSensitivity::MediumOrHigh:
252 return (confidence == Confidence::Medium) || (confidence == Confidence::High);
253 case WarningSensitivity::Aggressive:
254 return confidence != Confidence::None;
255 default:
256 return false;
257 }
258 }

References Aggressive, High, HighConfidence, Medium, MediumOrHigh, and None.

Referenced by maybe_warn_about_rotation_value().

+ Here is the caller graph for this function:

◆ take_captured_warnings()

std::vector< std::string > serial::rotation_warning_utils::take_captured_warnings ( )

Definition at line 262 of file rotation_warning_utils.cpp.

263 {
264 std::vector<std::string> warnings = std::move(captured_warnings);
265 captured_warnings.clear();
266 return warnings;
267 }

Referenced by complete_warning_capture().

+ Here is the caller graph for this function:

Variable Documentation

◆ kWarningSensitivity

constexpr WarningSensitivity serial::rotation_warning_utils::kWarningSensitivity = WarningSensitivity::MediumOrHigh
constexpr

Definition at line 47 of file rotation_warning_utils.h.

Referenced by maybe_warn_about_rotation_value().