changes to see how its faulty

This commit is contained in:
2024-06-07 12:36:21 +02:00
parent 8aa8c674d9
commit 2ffc391032

View File

@@ -17,6 +17,7 @@ import com.google.gson.JsonParser;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3f;
import org.json.JSONArray;
import java.util.ArrayList;
import java.util.List;
@@ -418,30 +419,31 @@ public class InputProcessor {
* Function for checking whether the last movement was faulty
*/
public boolean isFaultyMovement() {
// Calculate the index of the reference rotation vector
// This is done by calculating the closest index of the last received vector
// to the current time.
// i = | (t % T) / T * N |
int i, referenceIndex;
float distance;
for (i = 0; i < selfRotationVectorPaths.length; i++) {
referenceIndex = (int) (Math.round(
((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) /
(this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length))
% this.targetRotationVectorPaths[i].length;
referenceIndex = Math.min(1, Math.max(0, referenceIndex));
// If distance is greater than the threshold, return true
distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance(
this.targetRotationVectorPaths[i][referenceIndex]);
if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN) {
Log.i("MotionProcessor", "Faulty movement detected: " + distance + " > " + ExerciseManager.EXERCISE_ERROR_MARGIN);
return true;
boolean upMovementDetected = false;
boolean downMovementDetected = false;
for (List<Vector3f> path : selfRotationVectorPaths) {
if (path.size() < 2) {
continue; // Skip if there are not enough points to compare
}
Vector3f firstPoint = path.get(0);
Vector3f lastPoint = path.get(path.size() - 1);
float y1 = firstPoint.y;
float y2 = lastPoint.y;
if (y2 > y1) {
upMovementDetected = true;
} else if (y2 < y1) {
downMovementDetected = true;
}
if (upMovementDetected && downMovementDetected) {
return false; // Return false for faulty movement if both up and down movements are detected
}
}
return false;
return true; // Return true for faulty movement if only up or down movement is detected
}
}