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

Classes

struct  InferenceResult
 Result of inferring likely units from a rotation value. More...
 

Enumerations

enum class  ValueKind : std::uint8_t { Angle , Rate }
 Kind of rotation value being inspected for unit mistakes. More...
 
enum class  Confidence : std::uint8_t { None , Low , Medium , High }
 Confidence level for an inferred rotation unit. More...
 
enum class  WarningSensitivity : std::uint8_t { HighConfidence , MediumOrHigh , Aggressive }
 Minimum confidence threshold for emitting rotation-unit warnings. More...
 

Functions

InferenceResult infer_unit_from_value (RealType value, ValueKind kind) noexcept
 Infers the likely unit of a rotation value.
 
bool should_warn (Confidence confidence, WarningSensitivity sensitivity) noexcept
 Returns true when a warning should be emitted for the confidence and sensitivity.
 
void clear_captured_warnings () noexcept
 Clears the thread-local captured rotation warnings.
 
std::vector< std::string > take_captured_warnings ()
 Returns and clears the thread-local captured rotation warnings.
 
void maybe_warn_about_rotation_value (RealType value, params::RotationAngleUnit declared_unit, ValueKind kind, std::string_view source, std::string_view owner, std::string_view field)
 Emits or captures a warning when a rotation value likely uses the wrong unit.
 

Variables

constexpr WarningSensitivity kWarningSensitivity = WarningSensitivity::MediumOrHigh
 Default warning sensitivity used by parser and serializer warnings.
 

Enumeration Type Documentation

◆ Confidence

Confidence level for an inferred rotation unit.

Enumerator
None 

No useful inference could be made.

Low 

Weak evidence for the inferred unit.

Medium 

Moderate evidence for the inferred unit.

High 

Strong evidence for the inferred unit.

Definition at line 27 of file rotation_warning_utils.h.

28 {
29 None, ///< No useful inference could be made.
30 Low, ///< Weak evidence for the inferred unit.
31 Medium, ///< Moderate evidence for the inferred unit.
32 High ///< Strong evidence for the inferred unit.
33 };
@ Low
Weak evidence for the inferred unit.
@ High
Strong evidence for the inferred unit.
@ None
No useful inference could be made.
@ Medium
Moderate evidence for the inferred unit.

◆ ValueKind

Kind of rotation value being inspected for unit mistakes.

Enumerator
Angle 

Absolute rotation angle.

Rate 

Rotation rate.

Definition at line 20 of file rotation_warning_utils.h.

21 {
22 Angle, ///< Absolute rotation angle.
23 Rate ///< Rotation rate.
24 };

◆ WarningSensitivity

Minimum confidence threshold for emitting rotation-unit warnings.

Enumerator
HighConfidence 

Warn only on high-confidence mismatches.

MediumOrHigh 

Warn on medium or high-confidence mismatches.

Aggressive 

Warn on any non-low mismatch.

Definition at line 36 of file rotation_warning_utils.h.

37 {
38 HighConfidence, ///< Warn only on high-confidence mismatches.
39 MediumOrHigh, ///< Warn on medium or high-confidence mismatches.
40 Aggressive ///< Warn on any non-low mismatch.
41 };
@ HighConfidence
Warn only on high-confidence mismatches.
@ MediumOrHigh
Warn on medium or high-confidence mismatches.

Function Documentation

◆ clear_captured_warnings()

void serial::rotation_warning_utils::clear_captured_warnings ( )
noexcept

Clears the thread-local captured rotation warnings.

Definition at line 301 of file rotation_warning_utils.cpp.

301{ captured_warnings.clear(); }
math::Vec3 max

References max.

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

Infers the likely unit of a rotation value.

Definition at line 266 of file rotation_warning_utils.cpp.

267 {
268 const RealType abs_value = std::abs(value);
269
271 if (abs_value <= kEpsilon)
272 {
273 return result;
274 }
275
282
283 return result;
284 }
double RealType
Type for real numbers.
Definition config.h:27
Result of inferring likely units from a rotation value.

References max.

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 
)

Emits or captures a warning when a rotation value likely uses the wrong unit.

Definition at line 310 of file rotation_warning_utils.cpp.

313 {
315 if ((inference.inferred_unit == declared_unit) || !should_warn(inference.confidence, kWarningSensitivity))
316 {
317 return;
318 }
319
320 const std::string message =
321 std::format("{} rotation {} '{}' looks like {} but '{}' was declared (confidence: {}, value: {}). "
322 "Change rotationangleunit or convert existing values.",
323 source, owner, field, unit_token(inference.inferred_unit), unit_token(declared_unit),
324 confidence_token(inference.confidence), value);
325
326 if (std::ranges::find(captured_warnings, message) == captured_warnings.end())
327 {
328 captured_warnings.push_back(message);
329 }
330
332 }
#define LOG(level,...)
Definition logging.h:19
@ WARNING
Warning level for potentially harmful situations.
InferenceResult infer_unit_from_value(const RealType value, const ValueKind kind) noexcept
Infers the likely unit of a rotation value.
bool should_warn(const Confidence confidence, const WarningSensitivity sensitivity) noexcept
Returns true when a warning should be emitted for the confidence and sensitivity.

References infer_unit_from_value(), kWarningSensitivity, LOG, max, 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

Returns true when a warning should be emitted for the confidence and sensitivity.

Definition at line 286 of file rotation_warning_utils.cpp.

287 {
288 switch (sensitivity)
289 {
290 case WarningSensitivity::HighConfidence:
291 return confidence == Confidence::High;
292 case WarningSensitivity::MediumOrHigh:
293 return (confidence == Confidence::Medium) || (confidence == Confidence::High);
294 case WarningSensitivity::Aggressive:
295 return confidence != Confidence::None;
296 default:
297 return false;
298 }
299 }

References Aggressive, High, HighConfidence, max, 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 ( )

Returns and clears the thread-local captured rotation warnings.

Definition at line 303 of file rotation_warning_utils.cpp.

304 {
305 std::vector<std::string> warnings = std::move(captured_warnings);
306 captured_warnings.clear();
307 return warnings;
308 }

References max.

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

Default warning sensitivity used by parser and serializer warnings.

Definition at line 53 of file rotation_warning_utils.h.

Referenced by maybe_warn_about_rotation_value().