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));
}
});
}
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;
}
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();
}
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;
}
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());
}
Aggregations