Search in sources :

Example 6 with TrafficLight

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

the class StatisticsComparisonController method initTextFields.

/**
 *@author: Orel
 * @date: 20/6/18
 * Initializing all the data in the table
 */
private void initTextFields() {
    defaultFill = avgDrivingTime1.getFill();
    simulation1Text.setText(simulationType1);
    simulation2Text.setText(simulationType2);
    EvaluationComparator comparator = new EvaluationComparator(eval1, eval2);
    setTimeText(avgDrivingTime1, eval1.averageTotalDrivingTime().seconds());
    setTimeText(avgDrivingTime2, eval2.averageTotalDrivingTime().seconds());
    setTimeText(avgRoadDriving1, eval1.averageDrivingTimeOnAllRoads().seconds());
    setTimeText(avgRoadDriving2, eval2.averageDrivingTimeOnAllRoads().seconds());
    setTimeText(avgWaitingTime1, eval1.averageWaitingTimeOnAllTrafficLights().seconds());
    setTimeText(avgWaitingTime2, eval2.averageWaitingTimeOnAllTrafficLights().seconds());
    setColoredTimeText(avgDrivingTimeDiff, comparator.compareAverageDrivingTimeOfVehicles());
    setColoredTimeText(avgRoadDrivingDiff, comparator.compareAverageDrivingTimeOnRoads());
    setColoredTimeText(avgWaitingTimeDiff, comparator.compareAverageWaitingTimeOnTrafficLights());
    setColoredTimePercent(avgDrivingTimePercent, comparator.compareAverageDrivingTimeOfVehiclesPercent());
    setColoredTimePercent(avgRoadDrivingPercent, comparator.compareAverageDrivingTimeOnRoadsPercent());
    setColoredTimePercent(avgWaitingTimePercent, comparator.compareAverageWaitingTimeOnTrafficLightsPercent());
    // now for the combo boxes
    new Thread(() -> {
        for (TrafficLight f : mapDatabase.getAllTrafficLights()) {
            Label l = new Label(f.getName());
            trafficLightComboBox.getItems().add(l);
        }
        for (Road r : mapDatabase.getAllRoads()) {
            Label l = new Label(r.getName());
            roadComboBox.getItems().add(l);
        }
        for (VehicleEntry v : vehiclesList) {
            Optional<VehicleDescriptor> descriptor = v.getDescriptor();
            if (descriptor.isPresent()) {
                Label l = new Label(Integer.toString(descriptor.get().getID()));
                vehicleComboBox.getItems().add(l);
                vehiclesMap.put(descriptor.get().getID(), descriptor.get());
            }
        }
    }).start();
    vehicleComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            Integer id = Integer.parseInt(newValue.getText());
            VehicleDescriptor vec = vehiclesMap.get(id);
            try {
                setTimeText(drivingTime1, eval1.totalDrivingTime(vec).seconds());
                setTimeText(drivingTime2, eval2.totalDrivingTime(vec).seconds());
                setColoredTimeText(drivingTimeDiff, comparator.compareDrivingTimeOfVehicle(vec));
                setColoredTimePercent(drivingTimePercent, comparator.compareDrivingTimeOfVehiclePercent(vec));
            } catch (UnfinishedVehicleException e) {
                setTimeText(drivingTime1, (long) 0);
                setTimeText(drivingTime2, (long) 0);
                setColoredTimeText(drivingTimeDiff, (long) 0);
                setColoredTimePercent(drivingTimePercent, (double) 0);
            }
        }
    });
    trafficLightComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            String id = newValue.getText();
            TrafficLight tl = mapDatabase.getTrafficLight(id);
            setTimeText(waitingTime1, eval1.averageWaitingTimeOnTrafficLight(tl).seconds());
            setTimeText(waitingTime2, eval2.averageWaitingTimeOnTrafficLight(tl).seconds());
            setColoredTimeText(waitingTimeDiff, comparator.compareWaitingTimeOnTrafficLight(tl));
            setColoredTimePercent(waitingTimePercent, comparator.compareWaitingTimeOnTrafficLightPercent(tl));
        }
    });
    roadComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            String id = newValue.getText();
            Road r = mapDatabase.getRoad(id);
            setTimeText(roadDriving1, eval1.averageDrivingTimeOnRoad(r).seconds());
            setTimeText(roadDriving2, eval2.averageDrivingTimeOnRoad(r).seconds());
            setColoredTimeText(roadDrivingDiff, comparator.compareDrivingTimeOnRoad(r));
            setColoredTimePercent(roadDrivingPercent, comparator.compareDrivingTimeOnRoadPercent(r));
        }
    });
}
Also used : UnfinishedVehicleException(il.ac.technion.cs.yp.btw.evaluation.UnfinishedVehicleException) EvaluationComparator(il.ac.technion.cs.yp.btw.evaluation.EvaluationComparator) Road(il.ac.technion.cs.yp.btw.classes.Road) Label(javafx.scene.control.Label) VehicleEntry(il.ac.technion.cs.yp.btw.citysimulation.VehicleEntry) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) VehicleDescriptor(il.ac.technion.cs.yp.btw.citysimulation.VehicleDescriptor)

Example 7 with TrafficLight

use of il.ac.technion.cs.yp.btw.classes.TrafficLight 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 8 with TrafficLight

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

the class QueryTrafficLightExample method testGetAllTrafficLights.

/*
     * @author Sharon Hadar
     * @Date 21/01/2018*/
@Test
public void testGetAllTrafficLights() {
    TestResult result = new TestResult();
    MainDataBase.openConnection();
    Query query = new QueryTrafficLightExample("first");
    // MainDataBase database = new MainDataBase();
    // Set<TrafficLight> trafficLights = (Set<TrafficLight>) database.queryDataBase(query);
    Set<TrafficLight> trafficLights = (Set<TrafficLight>) MainDataBase.queryDataBase(query);
    Iterator<TrafficLight> iterator = trafficLights.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 : Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Query(il.ac.technion.cs.yp.btw.db.queries.Query) DataTrafficLight(il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) TestResult(junit.framework.TestResult) Test(org.junit.Test)

Example 9 with TrafficLight

use of il.ac.technion.cs.yp.btw.classes.TrafficLight 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)

Example 10 with TrafficLight

use of il.ac.technion.cs.yp.btw.classes.TrafficLight 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

TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)11 DataTrafficLight (il.ac.technion.cs.yp.btw.db.DataObjects.DataTrafficLight)7 Point (il.ac.technion.cs.yp.btw.classes.Point)5 Test (org.junit.Test)5 PointImpl (il.ac.technion.cs.yp.btw.classes.PointImpl)4 Road (il.ac.technion.cs.yp.btw.classes.Road)4 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 DataCrossRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataCrossRoad)2 DataRoad (il.ac.technion.cs.yp.btw.db.DataObjects.DataRoad)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CityCrossroad (il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad)1 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1 VehicleDescriptor (il.ac.technion.cs.yp.btw.citysimulation.VehicleDescriptor)1 VehicleEntry (il.ac.technion.cs.yp.btw.citysimulation.VehicleEntry)1