Passing array of possible faulty sensors
This commit is contained in:
Vincenzo Pio Florio 2024-12-05 12:21:54 +01:00
parent 767835c62c
commit 6aec8d0d45
2 changed files with 15 additions and 5 deletions

View File

@ -8,7 +8,7 @@
typedef struct {
float mean;
float standardDeviation;
bool *possibleFaultySensor;
int *possibleFaultySensor;
} Metrics;
typedef struct {

View File

@ -442,12 +442,10 @@ Metrics getMetrics(float **readings, int sensorNumber, int slidingWindow)
float standardDeviation = 0;
int outlierCount = 0;
int *faultySensors = (int *)malloc(sensorNumber * sizeof(int));
bool *possiblyFaultySensors = (bool *)malloc(sensorNumber * sizeof(bool));
for (int i = 0; i < sensorNumber; i++)
{
faultySensors[i] = 0;
possiblyFaultySensors[i] = false;
}
float sum = 0;
@ -483,11 +481,23 @@ Metrics getMetrics(float **readings, int sensorNumber, int slidingWindow)
}
}
for (int i = 0; i < sensorNumber; i++)
int faultySensorsCount = 0;
for(int i = 0; i < sensorNumber; i++)
{
if(faultySensors[i] >= 0.001 * slidingWindow)
{
faultySensorsCount++;
}
}
int *possiblyFaultySensors = (int *)malloc(faultySensorsCount * sizeof(int));
int j = 0;
for (int i = 0; i < faultySensorsCount; i++)
{
if (faultySensors[i] >= 0.001 * slidingWindow)
{
possiblyFaultySensors[i] = true;
possiblyFaultySensors[j] = i;
}
}