Search in sources :

Example 1 with DataTrafficLight

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

the class QueryTrafficLightExample method arrangeRecievedData.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Override
public Set<TrafficLight> arrangeRecievedData(ResultSet resultSet) {
    Set<TrafficLight> trafficLights = new HashSet();
    try {
        while (resultSet.next()) {
            String nameID = resultSet.getString("nameID");
            int cordx = resultSet.getInt("cordx");
            int cordy = resultSet.getInt("cordy");
            String sourceRoadId = nameID.split("-")[1];
            // resultSet.getString("from");
            String destinationRoadIf = nameID.split("-")[2];
            // resultSet.getString("to");
            long overload = resultSet.getLong("overload");
            Point position = new PointImpl(cordx, cordy);
            TrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
            System.out.println(trafficLight.toString());
            trafficLights.add(trafficLight);
        }
    } catch (SQLException e) {
        System.out.println("query has failed");
    }
    return trafficLights;
}
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) Point(il.ac.technion.cs.yp.btw.classes.Point) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

Example 2 with DataTrafficLight

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

the class TestDataTrafficLight method testGetParameters.

/**
 * @Autor: Shay
 * @Date: 15/6/18
 * DataTrafficLight unit test
 */
@Test
public void testGetParameters() {
    BTWDataBase btw = new BTWDataBaseImpl("test1");
    btw.loadMap();
    Set<TrafficLight> tls = btw.getAllTrafficLights();
    for (TrafficLight tl : tls) {
        if (tl.getName().equals("from:cc to:dd")) {
            Assert.assertTrue(tl.getCoordinateX() == 0.0);
            Assert.assertTrue(tl.getCoordinateY() == 0.0);
            Assert.assertTrue(tl.getMinimumWeight().seconds() == 4647);
        }
        if (tl.getName().equals("from:aa to:bb")) {
            Assert.assertTrue(tl.getCoordinateX() == 0.0);
            Assert.assertTrue(tl.getCoordinateY() == 0.0);
            Assert.assertTrue(tl.getMinimumWeight().seconds() == 435345445);
        }
        if (tl.getName().equals("from:bb to:ee")) {
            Assert.assertTrue(tl.getCoordinateX() == 2.0);
            Assert.assertTrue(tl.getCoordinateY() == 0.0);
            Assert.assertTrue(tl.getMinimumWeight().seconds() == 4647);
        }
    }
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) Test(org.junit.Test)

Example 3 with DataTrafficLight

use of il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight 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 4 with DataTrafficLight

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

the class TestDataTrafficLight method testConstruct.

/**
 * @Autor: Shay
 * @Date: 15/6/18
 * DataTrafficLight unit test
 */
@Test
public void testConstruct() {
    DataTrafficLight tl = new DataTrafficLight("tl12009", new PointImpl(2, 5.12313), "aa", "cc", 239732623, "test1");
    BTWDataBase b = new BTWDataBaseImpl("test1");
    b.loadMap();
    String rd = tl.getDestinationRoadName();
    String rs = tl.getSourceRoadName();
    Assert.assertNotNull(rd);
    Assert.assertNotNull(rs);
    String s = tl.toString();
    try {
        BTWTime time = BTWTime.of(44);
        Assert.assertTrue(tl.getWeightByTime(time).seconds() == 0);
    } catch (BTWIllegalTimeException e) {
    }
    Assert.assertTrue(s.contains("tl12009"));
}
Also used : DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) Test(org.junit.Test)

Example 5 with DataTrafficLight

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

the class QueryCrossRoad method arrangeRecievedData.

/*
    * @author Sharon Hadar
    * @Date 21/01/2018
    * construct a cross road from the data base results
    * */
@Override
public Crossroad arrangeRecievedData(ResultSet resultSet) {
    Set<TrafficLight> 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);
            TrafficLight trafficLight = new DataTrafficLight(nameID, position, sourceRoadId, destinationRoadIf, overload, mapName);
            trafficLights.add(trafficLight);
        }
    } catch (SQLException e) {
        logger.error("queryCrossRoad has failed");
    }
    Crossroad crossRoad = new DataCrossRoad(this.position, trafficLights, mapName);
    return crossRoad;
}
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) Crossroad(il.ac.technion.cs.yp.btw.classes.Crossroad) Point(il.ac.technion.cs.yp.btw.classes.Point) DataCrossRoad(il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad) PointImpl(il.ac.technion.cs.yp.btw.classes.PointImpl) HashSet(java.util.HashSet)

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