Search in sources :

Example 6 with DataTrafficLight

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.

the class BTWDataBaseImpl method insertRoadsToTrafficLights.

/**
 * @author Sharon Hadar
 * @Date 21/01/2018
 */
private void insertRoadsToTrafficLights() {
    Map<String, Road> roadsLightsOfName = new HashMap<>();
    this.roads.forEach(road -> roadsLightsOfName.put(road.getName(), road));
    for (TrafficLight trafficLight : this.trafficLights) {
        String sourceRoadName = ((DataTrafficLight) trafficLight).getSourceRoadName();
        ((DataTrafficLight) trafficLight).setSourceRoad(roadsLightsOfName.get(sourceRoadName));
        String destinationRoadName = ((DataTrafficLight) trafficLight).getDestinationRoadName();
        ((DataTrafficLight) trafficLight).setDestinationRoad(roadsLightsOfName.get(destinationRoadName));
    }
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) DataCrossRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad) DataRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)

Example 7 with DataTrafficLight

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.

the class QueryAllTrafficLights method arrangeRecievedData.

/*
    * @author Sharon Hadar
    * @Date 21/01/2018
    * build the recieved data from the data base results
    * */
@Override
public Set<DataTrafficLight> arrangeRecievedData(ResultSet resultSet) {
    Set<DataTrafficLight> trafficLights = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            double cordx = resultSet.getDouble("cordx");
            double cordy = resultSet.getDouble("cordy");
            String sourceRoadId = nameID.split("from:| to:")[1];
            // resultSet.getString("from");
            String destinationRoadIf = nameID.split(" to:")[1];
            // resultSet.getString("to");
            long overload = resultSet.getLong("overload");
            Point position = new PointImpl(cordx, cordy);
            DataTrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
            trafficLights.add(trafficLight);
        }
    } catch (SQLException e) {
        logger.error("query all trafficlights failed");
    }
    return trafficLights;
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) SQLException(java.sql.SQLException) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 8 with DataTrafficLight

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight in project BTW by TechnionYearlyProject.

the class TestGeoJasonToJavaParser method testTrafficLightsCorrect.

@Test
public void testTrafficLightsCorrect() {
    GeoJasonToJavaParser parser = new GeoJasonToJavaParser(mapName, geoJson);
    assertNotNull(parser.getTrafficLights());
    Iterator<TrafficLight> trafficLightsIterator = parser.getTrafficLights().iterator();
    DataTrafficLight dataTrafficLight = (DataTrafficLight) (trafficLightsIterator.next());
    assertNotNull(dataTrafficLight);
    assertEquals("from:3 StreetR to:3 Street", dataTrafficLight.getName());
    assertEquals("3 StreetR", dataTrafficLight.getSourceRoadName());
    assertEquals("3 Street", dataTrafficLight.getDestinationRoadName());
    assertEquals(0.0014190683853251293, dataTrafficLight.getCoordinateX(), 0.0000000000000000000001);
    assertEquals(0.014645366930914668, dataTrafficLight.getCoordinateY(), 0.0000000000000000000001);
    assertEquals(1, parser.getTrafficLights().size());
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) Test(org.junit.Test)

Aggregations

DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)8 Point (il.ac.technion.cs.yp.btw.classes.Point)4 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)4 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)4 SQLException (java.sql.SQLException)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)2 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)1 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)1