use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.
the class TestTrafficLightDataBase method testGetAllTrafficLightsInPosition.
/*
* @author Sharon Hadar
* @Date 21/01/2018*/
@Test
public void testGetAllTrafficLightsInPosition() {
MainDataBase.openConnection();
Point position = new PointImpl(1, 1);
Set<TrafficLight> allTrafficLights = TrafficLightsDataBase.getAllTrafficLights(position, "mapName");
Iterator<TrafficLight> iterator = allTrafficLights.iterator();
// System.out.println("\n\n\nthe result set is:");
while (iterator.hasNext()) {
assertNotNull(iterator.next());
// System.out.println(iterator.next().toString());
}
MainDataBase.closeConnection();
}
use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.
the class QueryTrafficLightExample method arrangeRecievedData.
/*
* @author Sharon Hadar
* @Date 21/01/2018*/
@Override
public Set<Road> arrangeRecievedData(ResultSet resultSet) {
Set<Road> roads = new HashSet();
try {
while (resultSet.next()) {
String nameID = resultSet.getString("nameID");
int cord1x = resultSet.getInt("cord1x");
int cord2x = resultSet.getInt("cord2x");
int cord1y = resultSet.getInt("cord1y");
int cord2y = resultSet.getInt("cord2y");
int length = resultSet.getInt("length");
int secStart = resultSet.getInt("secStart");
int secEnd = resultSet.getInt("secEnd");
String overload = resultSet.getString("overload");
System.out.println("nameID = " + nameID + " cord1x = " + cord1x + " cord2x = " + cord2x + " cord1y = " + cord1y + " cord2y = " + cord2y + " length = " + length + " secStart = " + secStart + " secEnd = " + secEnd + " overload = " + overload);
String myStreet = nameID.split("st")[0];
Point sourceCrossroadId = new PointImpl(cord1x, cord1y);
Point destinationCrossroadId = new PointImpl(cord2x, cord2y);
Road road = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, mapName);
System.out.println(road.toString());
roads.add(road);
}
} catch (SQLException e) {
System.out.println("query has failed");
}
return roads;
}
use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.
the class QueryAllCentralLocations method arrangeRecievedData.
/*
* @author Sharon Hadar
* @Date 21/01/2018
* get the results fro the data base and construct the match centeral locations
* */
@Override
public Set<CentralLocation> arrangeRecievedData(ResultSet resultSet) {
Set<CentralLocation> centralLocations = new HashSet();
try {
while (resultSet.next()) {
String nameID = resultSet.getString("nameID");
String street = resultSet.getString("street");
int cord1x = resultSet.getInt("cord1x");
int cord2x = resultSet.getInt("cord2x");
int cord3x = resultSet.getInt("cord3x");
int cord4x = resultSet.getInt("cord4x");
int cord1y = resultSet.getInt("cord1y");
int cord2y = resultSet.getInt("cord2y");
int cord3y = resultSet.getInt("cord3y");
int cord4y = resultSet.getInt("cord4y");
Set<Point> points = new HashSet<Point>();
points.add(new PointImpl(cord1x, cord1y));
points.add(new PointImpl(cord2x, cord2y));
points.add(new PointImpl(cord3x, cord3y));
points.add(new PointImpl(cord4x, cord4y));
CentralLocation centralLocation = new DataCentralLocation(points, nameID, street, mapName);
centralLocations.add(centralLocation);
}
} catch (SQLException e) {
System.out.println("query has failed");
}
return centralLocations;
}
use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.
the class MapGraphics method createCircles.
/**
* @author: shay
* @date: 20/1/18
* creating the array of circles, each circle for a traffic light.
* @param trafficLights - trafficlights in the map
*/
// TODO: change the color according to real time loads.
private void createCircles(Set<CityTrafficLight> trafficLights) {
int x = 0;
for (CityTrafficLight currTrafficLight : trafficLights) {
Point point = calculateTrafficLightLocation(currTrafficLight);
Circle circle = new Circle(point.getCoordinateX(), point.getCoordinateY(), 0.0001);
if (currTrafficLight.getState() == CityTrafficLight.TrafficLightState.GREEN)
circle.setFill(Color.GREEN);
else
circle.setFill(Color.RED);
circle.setOnMouseClicked(event -> {
System.out.println(currTrafficLight.getName());
});
circles.add(new Pair(circle, currTrafficLight.getName()));
x++;
}
}
use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.
the class MapGraphics method createLines.
/**
* @author Shay and Anat and Adam Elgressy
* @Date 20-1-2018
* creating the array of lines to represent roads
* @param roads - roads in the map
*/
private void createLines(Set<CityRoad> roads) {
HashSet<CityRoad> l_roads = new HashSet<>();
for (CityRoad currRoad : roads) {
double deviationAngle = 0.0;
double deviationDistance = -0.00003;
Point newSource = getDeviationFromVectorEnd(currRoad.getDestinationCrossroad(), currRoad.getSourceCrossroad(), deviationAngle, deviationDistance);
Point newDestination = getDeviationFromVectorEnd(currRoad.getSourceCrossroad(), currRoad.getDestinationCrossroad(), deviationAngle, deviationDistance);
deviationAngle = 0.5;
deviationDistance = 0.000125;
newSource = getDeviationFromVectorEnd(newDestination, newSource, -deviationAngle, deviationDistance);
newDestination = getDeviationFromVectorEnd(newSource, newDestination, deviationAngle, deviationDistance);
double xroad1 = newSource.getCoordinateX();
double yroad1 = newSource.getCoordinateY();
double xroad2 = newDestination.getCoordinateX();
double yroad2 = newDestination.getCoordinateY();
Line roadLine = new Line(xroad1, yroad1, xroad2, yroad2);
roadLine.setStroke(Color.BLACK);
roadLine.setStrokeWidth(0.00025);
roadLine.toBack();
deviationAngle = 0.0;
deviationDistance = -0.0003;
newSource = getDeviationFromVectorEnd(currRoad.getDestinationCrossroad(), currRoad.getSourceCrossroad(), deviationAngle, deviationDistance);
newDestination = getDeviationFromVectorEnd(currRoad.getSourceCrossroad(), currRoad.getDestinationCrossroad(), deviationAngle, deviationDistance);
double xSeperateLine1 = newSource.getCoordinateX();
double ySeperateLine1 = newSource.getCoordinateY();
double xSeperateLine2 = newDestination.getCoordinateX();
double ySeperateLine2 = newDestination.getCoordinateY();
Line separateline = new Line(xSeperateLine1, ySeperateLine1, xSeperateLine2, ySeperateLine2);
separateline.setStroke(Color.WHITE);
separateline.setStrokeWidth(0.00005);
lines.add(new Pair(roadLine, currRoad.getRoadName()));
lines.add(new Pair(separateline, currRoad.getRoadName()));
roadLine.setOnMouseClicked(event -> {
RoadData roadData = currRoad.getStatisticalData();
int length = roadData.getRoadLength();
double averageSpeed = roadData.getAverageSpeed();
int numOfVehicles = roadData.getNumOfVehicles();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/road_real_time_statistics.fxml"));
try {
Parent root = fxmlLoader.load();
RoadRealTimeStatisticsController roadRealTimeStatisticsController = fxmlLoader.getController();
roadRealTimeStatisticsController.generateView(length, averageSpeed, numOfVehicles, root);
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
Aggregations