51 printf(
"\n--- test_init ---\n");
53 uint64_t fake_timestamp = 666;
54 const uint32_t timeout_usec = 2000;
58 assert(
nullptr == validator->
sibling());
60 assert(0.0
f == validator->
confidence(fake_timestamp));
64 assert(!validator->
used());
73 assert(sibling_validator == validator->
sibling());
76 assert(0.0
f == validator->
confidence(fake_timestamp + 1));
84 assert(0.0
f == vibe_offset[0]);
92 printf(
"\n--- test_put ---\n");
94 uint64_t timestamp = 500;
95 const uint32_t timeout_usec = 2000;
98 const float sufficient_incr_value = (1.1f * 1E-6
f);
103 assert(validator->
used());
105 float last_val = val - sufficient_incr_value;
106 assert(validator->
value()[0] == last_val);
109 float conf = validator->
confidence(timestamp);
112 printf(
"conf: %f\n", (
double)conf);
116 assert(1.0
f == conf);
118 assert(0 == validator->
state());
121 conf = validator->
confidence(timestamp + (1.1 * timeout_usec));
124 printf(
"conf: %f\n", (
double)conf);
128 assert(0.0
f == conf);
140 printf(
"\n--- test_stale_detector ---\n");
142 uint64_t timestamp = 500;
143 float val = 3.14159f;
145 const float insufficient_incr_value = (0.99 * 1E-6
f);
171 printf(
"\n--- test_rms_calculation ---\n");
173 const float mean_value = 3.14159f;
174 const uint32_t sample_count = 1000;
175 float expected_rms_err = 0.0f;
176 uint64_t timestamp = 500;
182 float *rms = validator->
rms();
183 assert(
nullptr != rms);
184 float calc_rms_err = rms[0];
185 float diff = fabsf(calc_rms_err - expected_rms_err);
186 float diff_frac = (diff / expected_rms_err);
187 printf(
"rms: %f expect: %f diff: %f frac: %f\n", (
double)calc_rms_err, (
double)expected_rms_err,
188 (
double)diff, (
double)diff_frac);
189 assert(diff_frac < 0.03
f);
192 float vibe_diff = fabsf(0.01005
f - vibe_offset[0]);
193 printf(
"vibe: %f", (
double)vibe_offset[0]);
194 assert(vibe_diff < 1E-3
f);
205 printf(
"\n--- test_error_tracking ---\n");
206 uint64_t timestamp = 500;
207 uint64_t timestamp_incr = 5;
208 const uint32_t timeout_usec = 2000;
209 float val = 3.14159f;
210 uint64_t error_count = 0;
211 int expected_error_density = 0;
214 const float sufficient_incr_value = (1.1f * 1E-6
f);
218 const int total_iterations = 1000;
225 for (
int i = 0; i < total_iterations; i++, val += sufficient_incr_value) {
226 timestamp += timestamp_incr;
229 if ((((
float)rand() / (
float)RAND_MAX)) < 0.500
f) {
231 expected_error_density += 1;
233 }
else if (expected_error_density > 0) {
234 expected_error_density -= 1;
237 validator->
put(timestamp, val, error_count, priority);
240 assert(validator->
used());
246 float conf = validator->
confidence(timestamp);
247 printf(
"error_count: %u validator confidence: %f\n", (uint32_t)error_count, (
double)conf);
248 assert(1.0
f != conf);
249 assert(0.0
f != conf);
251 assert(0 == validator->
state());
255 float reduced_conf = 1.0f - ((float)expected_error_density / 100.0
f);
256 double diff = fabs(reduced_conf - conf);
258 if (reduced_conf != conf) {
259 printf(
"conf: %f reduced_conf: %f diff: %f\n",
260 (
double)conf, (
double)reduced_conf, diff);
264 assert(diff < 1E-6
f);
267 for (
int i = 0; i < 250; i++, val += sufficient_incr_value) {
268 timestamp += timestamp_incr;
271 expected_error_density += 1;
272 validator->
put(timestamp, val, error_count, priority);
276 assert(0.0
f == conf);
284 for (
int i = 0; i < 10000; i++, val += sufficient_incr_value) {
285 timestamp += timestamp_incr;
288 expected_error_density += 1;
289 validator->
put(timestamp, val, error_count, priority);
293 assert(0.0
f == conf);
301 int main(
int argc,
char *argv[])
int priority() const
Get the priority of this validator.
uint32_t get_timeout() const
Get the timeout value.
bool used() const
Get the used status of this validator.
void reset_state()
Reset the error state of this validator.
static constexpr uint32_t ERROR_FLAG_TIMEOUT
void dump_validator_state(DataValidator *validator)
Print out the state of a DataValidator.
void insert_values_around_mean(DataValidator *validator, const float mean, uint32_t count, float *rms_err, uint64_t *timestamp_io)
Insert a series of samples around a mean value.
const int equal_value_count
static constexpr uint32_t ERROR_FLAG_STALE_DATA
void test_stale_detector()
Verify that the DataValidator detects sensor data that does not vary sufficiently.
static constexpr uint32_t ERROR_FLAG_HIGH_ERRCOUNT
void print()
Print the validator value.
void set_timeout(uint32_t timeout_interval_us)
Set the timeout value.
void setSibling(DataValidator *new_sibling)
Set the sibling to the next node in the group.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
uint32_t state() const
Get the error state of this validator.
float * rms()
Get the RMS values of this validator.
static constexpr uint32_t ERROR_FLAG_NO_DATA
float * value()
Get the values of this validator.
DataValidator * sibling()
Get the next sibling in the group.
static constexpr uint32_t ERROR_FLAG_HIGH_ERRDENSITY
void set_equal_value_threshold(uint32_t threshold)
Set the equal count threshold.
void test_rms_calculation()
Verify the RMS error calculated by the DataValidator for a series of samples.
float * vibration_offset()
Get the vibration offset.
void test_error_tracking()
Verify error tracking performed by DataValidator::put.
void put(uint64_t timestamp, float val, uint64_t error_count, int priority)
Put an item into the validator.
void fill_validator_with_samples(DataValidator *validator, const float incr_value, float *value_io, uint64_t *timestamp_io)
Insert a time series of samples into the validator.
A data validation class to identify anomalies in data streams.
float confidence(uint64_t timestamp)
Get the confidence of this validator.
int main(int argc, char *argv[])
uint64_t error_count() const
Get the error count of this validator.