Search in sources :

Example 6 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 7 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);
        double avgSpeed = currRoad.getStatisticalData().getAverageSpeed();
        chooseRoadColor(roadLine, avgSpeed);
        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.getName()));
        lines.add(new Pair(separateline, currRoad.getName()));
        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)

Example 8 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class GeoJasonToJavaParser method parseRoad.

/*@Author: Sharon Hadar
    *@Date: 30/3/2018
    *get the geometry of feature from type LineString, and parse it to java class Road
    * the geometry's pattern is: {"type":"LineString","coordinates":[[0.01635651734518988,0.008806996592190556],[0.014402113034462271,0.006739623239087599]]}
    * the properties pattern is: {"name":"31 StreetR","length":"316","overload":0}}]}
    * */
private Road parseRoad(JsonObject geometry, JsonObject properties) {
    String name = properties.get("name").getAsString();
    int roadLength = properties.get("length").getAsInt();
    String myStreet = name.split(" Street| StreetR")[0];
    Point[] points = parsePointFromLineStringGeometry(geometry);
    Point sourceCrossroadId = points[sourceCoordIndex];
    Point destinationCrossroadId = points[destinationCoordIndex];
    int secStart = 0;
    if (name.contains("section")) {
        secStart = Integer.parseInt(name.split("section ")[1].split("R")[0]);
    }
    int secEnd = secStart;
    long overload = properties.get("overload").getAsLong();
    return new DataRoad(name, roadLength, myStreet, sourceCrossroadId, destinationCrossroadId, secStart, secEnd, overload, mapName);
}
Also used : 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)

Example 9 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class QueryTrafficLight method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018
     * construct a traffic light by the result of the data base*/
@Override
public TrafficLight arrangeRecievedData(ResultSet resultSet) {
    TrafficLight trafficLight = null;
    try {
        resultSet.next();
        String nameID = resultSet.getString("nameID");
        double cordx = resultSet.getDouble("cordx");
        double cordy = resultSet.getDouble("cordy");
        String sourceRoadId = nameID.split("from:|to:")[1];
        String destinationRoadIf = nameID.split("to:")[1];
        long overload = resultSet.getLong("overload");
        Point position = new PointImpl(cordx, cordy);
        trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
    } catch (SQLException e) {
        logger.error("query trafficlight has failed");
    }
    return trafficLight;
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) SQLException(java.sql.SQLException) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) 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)

Example 10 with Point

use of il.ac.technion.cs.yp.btw.classes.Point in project BTW by TechnionYearlyProject.

the class TestDataCentralLocation method testCentralLocation.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testCentralLocation() {
    Point a = new PointImpl(3, 4);
    Point b = new PointImpl(1, 2);
    Set<Point> points = new HashSet<Point>();
    points.add(a);
    points.add(b);
    CentralLocation cl = new DataCentralLocation(points, "Bank", "Namir", "try");
    String s = cl.toString();
    String sn = cl.getName();
    Assert.assertTrue(s.contains(sn));
}
Also used : DataCentralLocation(il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation) 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) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Point (il.ac.technion.cs.yp.btw.classes.Point)17 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)12 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)5 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)5 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)5 Road (il.ac.technion.cs.yp.btw.classes.Road)4 CentralLocation (il.ac.technion.cs.yp.btw.classes.CentralLocation)3 DataCentralLocation (il.ac.technion.cs.yp.btw.db.DataObjects.DataCentralLocation)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)2 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)2 Pair (javafx.util.Pair)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1