Updated routingAPI to privde a list of moves isntead of raw coordinates, DrivingRoute.txt added to simulate that generation

This commit is contained in:
Fennel Kora 2024-04-14 00:20:59 -04:00
parent 2dbaf79393
commit 72f82fb425
2 changed files with 31 additions and 24 deletions

12
DrivingRoute.txt Normal file
View file

@ -0,0 +1,12 @@
FWD;0.2;20
LEFT;0.044;20
LEFT;0.1;35
LEFT;3.0;45
RIGHT;2.3;50
LEFT;0.3;50
FWD;9.6;70
RIGHT;0.3;50
RIGHT;0.2;35
LEFT;0.2;35
LEFT;0.4;35
RIGHT;0.08;20

View file

@ -1,3 +1,8 @@
import java.util.Vector;
import java.nio.file.Paths;
import java.util.Scanner;
import java.io.IOException;
//a collection of helper functions to act as responses for otherwise
//external calls in this implementation for demo purposes
@ -18,35 +23,25 @@ public class HelperFunctions {
return returnArray;
}
public double[][] routingAPI(double[] startCoords, double[] destinationCoords, Boolean tollsFlag, Boolean hwyFlag) {
//ideally this would return a series of coordinates, but for the sake of the demo it's just
//going to concatenate the start and end into a 2x2 array with just those two steps
//speed is also returned in MPH for the expected points as the third index in the array's second dimension
double[][] routeArray = new double[2][3];
public Object[] routingAPI(double[] startCoords, double[] destinationCoords, Boolean tollsFlag, Boolean hwyFlag) {
//method simulates a call to translate two pairs of coords into a driving route
//for demo purposes returns a pregenerated set of move instructions
//located in DrivingRoute.txt as semicolon delimited strings for direction, distance, and speedLimit
Vector<String[]> routeArray = new Vector<String[]>();
if (tollsFlag && hwyFlag) { //provides a result that both avoid tolls and major highways
routeArray[0] = startCoords;
routeArray[1] = destinationCoords;
routeArray[0][2] = 45; //avg speed leg 1
routeArray[0][3] = 0; //tolls leg 1
routeArray[1][2] = 45; //avg speed leg 2
routeArray[1][3] = 0; //tolls leg 2
} else if (tollsFlag && !hwyFlag) { //provides a result that avoids tolls but not major highways
routeArray[0][2] = 60; //avg speed leg 1
routeArray[0][3] = 0; //tolls leg 1
routeArray[1][2] = 45; //avg speed leg 2
routeArray[1][3] = 0; //tolls leg 2
} else if (!tollsFlag && hwyFlag) { //provides a result that does not avoid tolls and does avoid major highways
routeArray[0][2] = 45; //avg speed leg 1
routeArray[0][3] = 1.50; //tolls leg 1
routeArray[1][2] = 45; //avg speed leg 2
routeArray[1][3] = 0; //tolls leg 2
} else if (!tollsFlag && !hwyFlag) { //provides a result that does not avoid tolls or major highways
routeArray[0][2] = 60; //avg speed leg 1
routeArray[0][3] = 1.50; //tolls leg 1
routeArray[1][2] = 45; //avg speed leg 2
routeArray[1][3] = 0; //tolls leg 2
try (Scanner infile = new Scanner(Paths.get("DrivingRoute.txt"))) {
while (infile.hasNext()) {
routeArray.addElement(infile.nextLine().split(";"));
}
} catch (IOException e) {
System.err.println("File handling error");
}
}
return routeArray;
return routeArray.toArray();
}
public int[] internalTempSensors() {