Renamed functions for clarity

This commit is contained in:
Luca Warmenhoven
2024-05-30 17:57:49 +02:00
parent 826ae8a9c7
commit 84bdc7ca59
5 changed files with 19 additions and 9 deletions

View File

@@ -28,6 +28,9 @@ public class ExerciseManager {
private static final String PROPERTY_PATH = "path";
private static final String PROPERTY_NAME = "name";
// The delimiter used to separate the paths of the sensors.
public static final String PATH_DELIMITER = ";";
public static final int SENSOR_COUNT = 2;
private static final String[] REQUIRED_PROPERTIES = {
@@ -80,7 +83,7 @@ public class ExerciseManager {
*
* @return The exercise, if it exists on the server. Otherwise null.
*/
public static Exercise retrieveExercise() {
public static Exercise fetchExerciseFromDatabase() {
String response = sendHTTP(
HOST_ADDRESS, "POST", "application/json", null
);
@@ -99,7 +102,7 @@ public class ExerciseManager {
// Path data is split into two parts, due to the left and right hand.
// If one wants to add support for more sensors, one will have to adjust the Exercise
// class to support more paths.
String[] leftRightData = content.get(PROPERTY_PATH).getAsString().split(";");
String[] leftRightData = content.get(PROPERTY_PATH).getAsString().split(PATH_DELIMITER);
if (leftRightData.length != SENSOR_COUNT)
return null;

View File

@@ -71,7 +71,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// This will provide the element with the appropriate dimensions for drawing
// the canvas properly.
personalMotionPreviewElement.post(() -> {
this.acquireExercise((exercise) -> {
this.fetchExerciseAsync((exercise) -> {
// Acquire paths from the exercise and provide them to the motion processor
Vector3f[][] vectors = new Vector3f[][]{exercise.leftPath.getVectors(), exercise.rightPath.getVectors()};
@@ -97,11 +97,11 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
* Whenever the retrieval failed, it will have the robot say something to the user
* to inform them about the issue.
*/
public void acquireExercise(Exercise.ExerciseFetchHandler onSuccessfulFetch, Exercise.ExerciseFetchHandler onFailedFetch) {
public void fetchExerciseAsync(Exercise.ExerciseFetchHandler onSuccessfulFetch, Exercise.ExerciseFetchHandler onFailedFetch) {
// For some stupid reason we cannot perform network operations on the main thread.
// therefore we'll have to do it like this...
(new Thread(() -> {
Exercise exercise = ExerciseManager.retrieveExercise();
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
if (exercise == null) {
onFailedFetch.handle(null);
} else {

View File

@@ -122,7 +122,7 @@ public class ExerciseStatusElement extends View implements IInputHandler {
// Move on to the next exercise, or finish.
if (this.exerciseCount > 0) {
this.exerciseCount--;
this.parentActivity.acquireExercise((newExercise) -> {
this.parentActivity.fetchExerciseAsync((newExercise) -> {
this.motionProcessor.useExercise(newExercise);
}, (failed) -> {
// Move to main screen

View File

@@ -3,6 +3,7 @@ package com.example.fitbot.util.processing;
import android.util.Log;
import com.example.fitbot.exercise.Exercise;
import com.example.fitbot.exercise.ExerciseManager;
import com.example.fitbot.util.server.WebServer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -220,6 +221,13 @@ public class InputProcessor {
}
}
/**
* Function for converting the recorded data to a string.
* This function will convert the recorded data to a string
* that can be sent to a database or other storage.
*
* @return The converted string.
*/
private String convertRecordedDataToString()
{
// First, remove empty entries
@@ -251,7 +259,7 @@ public class InputProcessor {
}
// Add a separator between devices
if ( deviceId < selfRotationVectorPaths.length - 1)
pathBuilder.append(";");
pathBuilder.append(ExerciseManager.PATH_DELIMITER);
}
return pathBuilder.toString();
}

View File

@@ -1,6 +1,5 @@
package com.example.fitbot;
import com.example.fitbot.exercise.EMuscleGroup;
import com.example.fitbot.exercise.Exercise;
import com.example.fitbot.exercise.ExerciseManager;
@@ -11,7 +10,7 @@ public class DatabaseFetchingTest {
@Test
public void testDatabaseFetching() {
Exercise exercise = ExerciseManager.retrieveExercise();
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
assert exercise != null;
System.out.println("\n---------------------------------");
System.out.println("Exercise:");