This commit is contained in:
2024-12-03 20:20:05 +01:00
parent 034c7231ef
commit 767835c62c
3 changed files with 165 additions and 86 deletions

View File

@@ -429,22 +429,42 @@ void test_getMetrics()
// initialize a matrix of readings
float **readings = (float **)malloc(NUMBER_OF_SENSORS * sizeof(float *));
for (int i = 0; i < NUMBER_OF_SENSORS; i++)
for (int sensor = 0; sensor < NUMBER_OF_SENSORS; sensor++)
{
readings[i] = (float *)malloc(SLIDING_WINDOW_SIZE * sizeof(float));
for (int j = 0; j < SLIDING_WINDOW_SIZE; j++)
readings[sensor] = (float *)malloc(10000 * sizeof(float));
}
// fill the matrix with normal distribution data
for (int i = 0; i < 10000; i++)
{
for (int sensor = 0; sensor < NUMBER_OF_SENSORS; sensor++)
{
readings[i][j] = j + 1;
float u1 = (float)rand() / RAND_MAX;
float u2 = (float)rand() / RAND_MAX;
float z0 = sqrt(-2.0 * log(u1)) * cos(2.0 * M_PI * u2);
readings[sensor][i] = NORMAL_DISTRIBUTION_MEAN + z0 * NORMAL_DISTRIBUTION_STDDEV;
}
}
// get metrics
Metrics metrics = getMetrics(readings, NUMBER_OF_SENSORS, SLIDING_WINDOW_SIZE);
// add a broken sensor
for (int i = 0; i < 100; i++)
{
readings[0][i] = 1000;
}
printf("Metrics:\n");
// get metrics
Metrics metrics = getMetrics(readings, NUMBER_OF_SENSORS, 10000);
printf("\nMetrics:\n") ;
printf("Mean: %f\n", metrics.mean);
printf("Standard Deviation: %f\n", metrics.standardDeviation);
printf("Possible Faulty Sensor: %d\n", metrics.possibleFaultySensor);
// print the faulty sensors
printf("Possible faulty sensors: ");
for (int i = 0; i < NUMBER_OF_SENSORS; i++)
{
printf("%d ", metrics.possibleFaultySensor[i]);
}
}