use of il.ac.technion.cs.yp.btw.classes.Road 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.Road in project BTW by TechnionYearlyProject.
the class VehiclesGenerator method addRandomEntryToList.
private void addRandomEntryToList(PoissonDistribution pd, VehicleDescriptorFactory vehicleDescriptorsFactory, List<VehicleEntry> vehicleEntriesList, Random randomGenerator) {
int index = randomGenerator.nextInt(this.availableRoads.size());
List<Road> roads = new ArrayList<>(this.availableRoads);
Road r1 = roads.get(index);
index = randomGenerator.nextInt(this.availableRoads.size());
Road r2 = roads.get(index);
Double ratio1 = randomGenerator.nextDouble();
Double ratio2 = randomGenerator.nextDouble();
vehicleEntriesList.add(new VehicleEntry().setDestinationRoadName(r1.getName()).setSourceRoadName(r2.getName()).setSourceRoadRatio(ratio1).setDestinationRoadRatio(ratio2).setTimeOfDrivingStart(BTWTime.of(pd.sample())).setDescriptor(vehicleDescriptorsFactory.get()));
}
use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.
the class QueryTrafficLightExample method testGetAllRoadsSet.
// the test method name needs to begin with the word 'test'
/*
* @author Sharon Hadar
* @Date 21/01/2018*/
@Test
public void testGetAllRoadsSet() {
TestResult result = new TestResult();
MainDataBase.openConnection();
Query query = new QueryRoadExample("first");
// MainDataBase database = new MainDataBase();
// Set<Road> roads = (Set<Road>) database.queryDataBase(query);
Set<Road> roads = (Set<Road>) MainDataBase.queryDataBase(query);
Iterator<Road> iterator = roads.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.Road in project BTW by TechnionYearlyProject.
the class TestDataRoad method testConstructing.
@Test
public void testConstructing() {
// first constructor
Road a = new DataRoad("Road6", 3, "STR1", new PointImpl(0, 0), new PointImpl(6.6, 6.6), "try");
// second constructor
Road b = new DataRoad("Road4", 43346, "STR2", new PointImpl(11.32, 77.234), new PointImpl(6.6, 6.6), 0, 342, 235, "try");
Assert.assertTrue(b.isStreetNumberInRange(100));
Assert.assertFalse(b.isStreetNumberInRange(1000));
Assert.assertTrue(a.getName().equals("Road6"));
Assert.assertTrue(b.getName().equals("Road4"));
Assert.assertTrue(a.getRoadLength() == 3);
String s = a.toString();
String s2 = b.toString();
Assert.assertTrue(s.contains("Road6"));
Assert.assertTrue(s2.contains("STR2"));
Assert.assertNull(((DataRoad) a).getWeights());
Assert.assertNotNull(((DataRoad) a).getDistances());
// Assert.assertTrue(a.getSpeed()>-1 && a.getSpeed() <1);
// Assert.assertTrue(a.getOverload()>-1 && a.getOverload() <1);
Assert.assertTrue(s2.contains("STR2"));
System.out.println(a.getWeightByTime(BTWTime.of(0)).seconds());
}
use of il.ac.technion.cs.yp.btw.classes.Road in project BTW by TechnionYearlyProject.
the class QueryRoad method arrangeRecievedData.
/*
* @author Sharon Hadar
* @Date 21/01/2018
* construct a road by the results from the data base*/
@Override
public Road arrangeRecievedData(ResultSet resultSet) {
Road road = null;
try {
resultSet.next();
String nameID = resultSet.getString("nameID");
double cord1x = resultSet.getDouble("cord1x");
double cord2x = resultSet.getDouble("cord2x");
double cord1y = resultSet.getDouble("cord1y");
double cord2y = resultSet.getDouble("cord2y");
int length = resultSet.getInt("length");
int secStart = resultSet.getInt("secStart");
int secEnd = resultSet.getInt("secEnd");
long overload = resultSet.getLong("overload");
String myStreet = nameID.split("st")[0];
Point sourceCrossroadId = new PointImpl(cord1x, cord1y);
Point destinationCrossroadId = new PointImpl(cord2x, cord2y);
road = new DataRoad(nameID, length, myStreet, sourceCrossroadId, destinationCrossroadId, secStart, secEnd, overload, mapName);
} catch (SQLException e) {
logger.error("query Road has failed");
}
return road;
}
Aggregations