Search in sources :

Example 1 with Point

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();
}
Also used : TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) Test(org.junit.Test)

Example 2 with Point

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;
}
Also used : SQLException(java.sql.SQLException) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Road(il.ac.technion.cs.yp.btw.classes.Road) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) Point(il.ac.technion.cs.yp.btw.classes.Point) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 3 with Point

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;
}
Also used : DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) SQLException(java.sql.SQLException) CentralLocation(il.ac.technion.cs.yp.btw.classes.CentralLocation) DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) Point(il.ac.technion.cs.yp.btw.classes.Point) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 4 with Point

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++;
    }
}
Also used : Circle(javafx.scene.shape.Circle) Point(il.ac.technion.cs.yp.btw.classes.Point) CityTrafficLight(il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight) Point(il.ac.technion.cs.yp.btw.classes.Point) Pair(javafx.util.Pair)

Example 5 with Point

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();
            }
        });
    }
}
Also used : Parent(javafx.scene.Parent) Point(il.ac.technion.cs.yp.btw.classes.Point) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) Point(il.ac.technion.cs.yp.btw.classes.Point) Line(javafx.scene.shape.Line) RoadData(il.ac.technion.cs.yp.btw.citysimulation.RoadData) CityRoad(il.ac.technion.cs.yp.btw.citysimulation.CityRoad) HashSet(java.util.HashSet) Pair(javafx.util.Pair)

Aggregations

Point (il.ac.technion.cs.yp.btw.classes.Point)14 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)12 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 Road (il.ac.technion.cs.yp.btw.classes.Road)4 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)4 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)4 CentralLocation (il.ac.technion.cs.yp.btw.classes.CentralLocation)3 DataCentralLocation (il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation)3 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)3 Pair (javafx.util.Pair)2 Test (org.junit.Test)2 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1 RoadData (il.ac.technion.cs.yp.btw.citysimulation.RoadData)1 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)1 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)1 DataStreet (il.ac.technion.cs.yp.btw.db.DataObjects.DataStreet)1 IOException (java.io.IOException)1 FXMLLoader (javafx.fxml.FXMLLoader)1