65 assert(
nullptr != group);
77 printf(
"vibe_off: %f \n", (
double)vibe_off);
81 printf(
"vibe_fact: %f \n", (
double)vibe_fact);
82 assert(0.0
f == vibe_fact);
91 *sibling_count = num_siblings;
107 uint64_t error_count = 0;
108 float last_best_val = 0.0f;
110 for (uint32_t i = 0; i < num_samples; i++) {
111 float val = ((float) rand() / (float) RAND_MAX);
113 group->
put(val1_idx, timestamp, data, error_count, 100);
118 float *best_data = group->
get_best(timestamp, &best_idx);
119 assert(last_best_val == best_data[0]);
120 assert(best_idx == val1_idx);
138 uint64_t error_count = 0;
139 float last_best_val = 0.0f;
141 for (uint32_t i = 0; i < num_samples; i++) {
142 float val = ((float) rand() / (float) RAND_MAX);
145 group->
put(val1_idx, timestamp, data, error_count, 100);
146 group->
put(val2_idx, timestamp, data, error_count, 10);
151 float *best_data = group->
get_best(timestamp, &best_idx);
152 assert(last_best_val == best_data[0]);
153 assert(best_idx == val1_idx);
185 unsigned *sibling_count)
200 unsigned num_siblings = 0;
217 unsigned num_siblings = 0;
224 printf(
"num_siblings: %d \n", num_siblings);
225 unsigned val1_idx = num_siblings - 2;
226 unsigned val2_idx = num_siblings - 1;
230 float *best_data = group->
get_best(timestamp, &best_idx);
231 assert(
nullptr != best_data);
232 float best_val = best_data[0];
234 float *cur_val1 = validator1->
value();
235 assert(
nullptr != cur_val1);
237 assert(best_val == cur_val1[0]);
239 float *cur_val2 = validator2->
value();
240 assert(
nullptr != cur_val2);
242 assert(best_val == cur_val2[0]);
253 unsigned num_siblings = 0;
261 int val1_idx = (int)num_siblings - 2;
262 int val2_idx = (int)num_siblings - 1;
263 uint64_t error_count = 0;
268 float *best_data =
nullptr;
270 float new_best_val = 3.14159f;
273 group->
put(val1_idx, timestamp, data, error_count, 1);
274 group->
put(val2_idx, timestamp, data, error_count, 100);
275 best_data = group->
get_best(timestamp, &best_idx);
276 assert(new_best_val == best_data[0]);
278 assert(best_idx == val2_idx);
290 unsigned num_siblings = 0;
298 int val1_idx = (int)num_siblings - 2;
299 int val2_idx = (int)num_siblings - 1;
305 float *best_data =
nullptr;
308 float new_best_val = 3.14159f;
311 unsigned val1_err_count = 0;
313 for (
int i = 0; i < 25; i++) {
314 group->
put(val1_idx, timestamp, data, ++val1_err_count, 100);
315 group->
put(val2_idx, timestamp, data, 0, 10);
318 assert(validator1->
error_count() == val1_err_count);
321 best_data = group->
get_best(timestamp + 1, &best_idx);
322 assert(
nullptr != best_data);
323 assert(new_best_val == best_data[0]);
324 assert(best_idx == val2_idx);
334 assert(-1 == fail_idx);
348 unsigned num_siblings = 0;
355 assert(
nullptr != validator);
358 assert(
nullptr != vibes);
361 assert(0 == vibes[0]);
366 assert(-1.0
f == vibe_o);
368 float rms_err = 0.0f;
372 assert(
nullptr != vibes);
373 printf(
"val1 vibes: %f rms_err: %f \n", vibes[0], (
double)rms_err);
376 printf(
"group vibe_o %f \n", vibe_o);
378 assert(vibes[0] == vibe_o);
382 float val1_rms = (validator->
rms())[0];
383 printf(
"group_vibe_fact: %f val1_rms: %f\n", (
double)group_vibe_fact, (
double)val1_rms);
384 assert(group_vibe_fact == val1_rms);
393 unsigned num_siblings = 0;
395 const float sufficient_incr_value = (1.1f * 1E-6
f);
396 const uint32_t timeout_usec = 2000;
398 float val = 3.14159f;
404 assert(
nullptr != validator);
406 int val_idx = num_siblings - 1;
412 float *best_data = group->
get_best(timestamp, &best_idx);
413 assert(
nullptr != best_data);
415 assert(best_idx == val_idx);
418 validator->
confidence(timestamp + (1.1 * timeout_usec));
423 assert(val_idx == fail_idx);
428 int main(
int argc,
char *argv[])
uint32_t get_timeout() const
Get the timeout value.
DataValidatorGroup * setup_base_group(unsigned *sibling_count)
Initialize a DataValidatorGroup with some common settings;.
static constexpr uint32_t ERROR_FLAG_NO_ERROR
Data validator error states.
void test_sensor_failure()
Force once sensor to fail and ensure that we detect it.
DataValidatorGroup * setup_group_with_two_validator_handles(DataValidator **validator1_handle, DataValidator **validator2_handle, unsigned *sibling_count)
Create a DataValidatorGroup and tack on two additional DataValidators.
void put(unsigned index, uint64_t timestamp, const float val[3], uint64_t error_count, int priority)
Put an item into the validator group.
void set_timeout(uint32_t timeout_interval_us)
Set the timeout value for the whole group.
DataValidator * add_validator_to_group(DataValidatorGroup *group)
Dynamically add a validator to the group after construction.
const uint32_t base_timeout_usec
static constexpr uint32_t ERROR_FLAG_TIMEOUT
int main(int argc, char *argv[])
int failover_index()
Get the index of the failed sensor in the group.
void test_vibration()
Verify that we get expected vibration values after injecting samples.
const uint64_t base_timestamp
void print()
Print the validator value.
uint32_t failover_state()
Get the error state of the failed sensor in the group.
const unsigned base_num_siblings
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
float * get_best(uint64_t timestamp, int *index)
Get the best data triplet of the group.
float get_vibration_offset(uint64_t timestamp, int axis)
Get the vibration offset in the sensor unit.
float get_vibration_factor(uint64_t timestamp)
Get the RMS / vibration factor.
void test_simple_failover()
Verify that the DataGroupValidator will prefer a sensor with no errors over a sensor with high errors...
void test_put()
Happy path test of put method – ensure the "best" sensor selected is the one with highest priority...
void set_equal_value_threshold(uint32_t threshold)
Set the equal count threshold for the whole group.
DataValidator * add_new_validator()
Create a new Validator (with index equal to the number of currently existing validators) ...
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
A data validation group to identify anomalies in data streams.
uint32_t state() const
Get the error state of this validator.
float * rms()
Get the RMS values of this validator.
float * value()
Get the values of this validator.
unsigned failover_count() const
Get the number of failover events.
void set_equal_value_threshold(uint32_t threshold)
Set the equal count threshold.
void fill_one_with_valid_data(DataValidatorGroup *group, int val1_idx, uint32_t num_samples)
Fill one DataValidator with samples, by index.
float * vibration_offset()
Get the vibration offset.
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.
void fill_two_with_valid_data(DataValidatorGroup *group, int val1_idx, int val2_idx, uint32_t num_samples)
Fill two validators in the group with samples, by index.
A data validation class to identify anomalies in data streams.
float confidence(uint64_t timestamp)
Get the confidence of this validator.
uint64_t error_count() const
Get the error count of this validator.
static const unsigned dimensions
void test_priority_switch()
Verify that the DataValidatorGroup will select the sensor with the latest higher priority as "best"...