Skip to content

Commit

Permalink
Add last modifications before release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Rince committed Mar 23, 2019
1 parent 2eb2e73 commit ec0f46d
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 126 deletions.
227 changes: 113 additions & 114 deletions src/fr/ecp/IS1220/myVelib/client/Scenario1c.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,119 +10,118 @@ public class Scenario1c {

public static void main(String[] args) throws RuntimeException, Exception {
//Creation of an instance of SystemDate.
SystemDate SD = SystemDate.getInstance();
//Initialization of the date and time of SystemDate.
SD.setDay(2019, 02, 17);SD.setTime(0, 0, 0);

//Creation of a MyVelib network named "Paris".
MyVelibNetwork network = new MyVelibNetwork("Paris");

//Creation of 10 Stations (of which 4 Plus stations), each dotted with 10 parking slots.
//These stations are created in a circular area of radius 5 km centered on the pyramide du Louvre in Paris.
//70% of the totality of the parking slots are populated with bicycles.
//70% of these bicycles are "mechanical", the other 30% are "electrical".
network.createStations(new Localization(48.86101631231847,2.33583927154541), 5., 10, 4, 10, 70., new double[] {70,30});
//Creation of a new standard station named "Odeon" next to the Odeon Metro station.
//This station is dotted with 12 parking slots, and populated with 1 "mechanical" bike and 1 "electrical" bike.
network.createPopStation(new Localization(48.85223492920533,2.339315414428711), false, 12,new int[]{1,1},"Odeon");
//Creation of a new Plus station named "Vaneau" next to the Vaneau Metro station.
//This station is dotted with 8 parking slots, and populated with 6 "mechanical" bikes.
network.createPopStation(new Localization(48.84890268296977,2.321033477783203), true, 8,new int[]{6,0},"Vaneau");

//Creation of 11 user with no subscription.
network.createSubscribers(11, "standard");
//Creation of 7 user with a "Vlibre" subscription.
network.createSubscribers(7, "Vlibre");
//Creation of 4 user with a "Vmax" subscription.
network.createSubscribers(4, "Vmax");

//Displaying the station database and their current state.
System.out.println(network.stationDatabaseState());
//Displaying the user database.
System.out.println(network.userDatabaseRepresentation());

//Change of the time.
SD.setTime(9, 22, 37);
//User1 starts a new ride in Station2. They do not care about bicycle type.
network.user(1).newRide(network.station(2));
//
SD.setTime(9, 28, 42);
//User20 starts a new ride in Station1 with an electrical bike.
network.user(20).newRide(network.station(1),"electrical");
//
SD.setTime(9, 31, 13);
//User15 plans a new ride from a point next to Odeon to a point next to Vaneau.
//He wishes to ride with an electrical bike.
network.user(15).planRide(new Localization(48.85223492920534,2.339315414428711),
new Localization(48.84890268296978,2.321033477783203),"electrical");
//
SD.setTime(9, 31, 49);
//User4 starts a new ride in Station10 Odeon with an electrical bike.
//Doing so, he takes the last electrical bike of this station so the planned ride of User15 has to be updated.
network.user(4).newRide(network.station(10),"electrical");
//
SD.setTime(9, 33, 4);
//User15 decides to discard their planned ride to plan an other one.
network.user(15).discardPlannedRide();
//This time, User15 doesn't specify any bicycle type for their planned ride.
network.user(15).planRide(new Localization(48.85223492920534,2.339315414428711),
new Localization(48.84890268296978,2.321033477783203));
//User15 indicates that they're going for the ride they had planned.
network.user(15).getPlannedRide().start();
//
SD.setTime(9, 35, 38);
//User15 decides to follow the indications of their planned ride and starts a new ride from Station10 Odeon. They do not care about bicycle type.
network.user(15).newRide(network.station(10));
//
SD.setTime(9, 46, 34);
//User15 ends their ride in Station11 Vaneau.
network.user(15).endCurrentRide(network.station(11));
//
SD.setTime(9, 48, 13);
//User20 ends their ride in Station10 Odeon.
network.user(20).endCurrentRide(network.station(10));
//
SD.setTime(10, 37, 59);
//User1 ends their ride in Station10 Odeon.
network.user(1).endCurrentRide(network.station(10));
//
SD.setTime(10, 56, 03);
//User4 ends their ride in Station11 Vaneau.
network.user(4).endCurrentRide(network.station(11));

//Displaying the history of a station
System.out.println(network.station(10).historyTrace());
//Displaying the statistics of a few stations
//StationBalance.display(network.station(10));
//StationBalance.display(network.station(11));
StationBalance.display(network.station(0));
//Displaying the statistics of a few users
UserBalance.display(network.user(1));
UserBalance.display(network.user(15));
UserBalance.display(network.user(20));

//Sorting of station database
//Basic
ArrayList<Station> stations = (ArrayList<Station>) network.getStationDatabase().clone();
System.out.println(" == Stations initial order == ");
System.out.println(stations.toString());
System.out.println();
//By ID
Collections.sort(stations);
System.out.println(" == Stations sorted by ID == ");
System.out.println(stations.toString());
System.out.println();
//By most used
Comparator<Station> c = new SortStationByMostUsed();
Collections.sort(stations, c);
System.out.println(" == Stations sorted by most used == ");
System.out.println(stations);
System.out.println();
//By least occupied
c = new SortStationByLeastOccupied();
Collections.sort(stations, c);
System.out.println(" == Stations sorted by least occupied == ");
System.out.println(stations);
System.out.println();
SystemDate SD = SystemDate.getInstance();
//Initialization of the date and time of SystemDate.
SD.setDay(2019, 02, 17);SD.setTime(0, 0, 0);

//Creation of a MyVelib network named "Paris".
MyVelibNetwork network = new MyVelibNetwork("Paris");

//Creation of 10 Stations (of which 4 Plus stations), each dotted with 10 parking slots.
//These stations are created in a circular area of radius 5 km centered on the pyramide du Louvre in Paris.
//70% of the totality of the parking slots are populated with bicycles.
//70% of these bicycles are "mechanical", the other 30% are "electrical".
network.createStations(new Localization(48.86101631231847,2.33583927154541), 5., 10, 4, 10, 70., new double[] {70,30});
//Creation of a new standard station named "Odeon" next to the Odeon Metro station.
//This station is dotted with 12 parking slots, and populated with 1 "mechanical" bike and 1 "electrical" bike.
network.createPopStation(new Localization(48.85223492920533,2.339315414428711), false, 12,new int[]{1,1},"Odeon");
//Creation of a new Plus station named "Vaneau" next to the Vaneau Metro station.
//This station is dotted with 8 parking slots, and populated with 6 "mechanical" bikes.
network.createPopStation(new Localization(48.84890268296977,2.321033477783203), true, 8,new int[]{6,0},"Vaneau");

//Creation of 11 user with no subscription.
network.createSubscribers(11, "standard");
//Creation of 7 user with a "Vlibre" subscription.
network.createSubscribers(7, "Vlibre");
//Creation of 4 user with a "Vmax" subscription.
network.createSubscribers(4, "Vmax");

//Displaying the station database and their current state.
System.out.println(network.stationDatabaseState());
//Displaying the user database.
System.out.println(network.userDatabaseRepresentation());

//Change of the time.
SD.setTime(9, 22, 37);
//User1 starts a new ride in Station2. They do not care about bicycle type.
network.user(1).newRide(network.station(2));
//
SD.setTime(9, 28, 42);
//User20 starts a new ride in Station1 with an electrical bike.
network.user(20).newRide(network.station(1),"electrical");
//
SD.setTime(9, 31, 13);
//User15 plans a new ride from a point next to Odeon to a point next to Vaneau.
//He wishes to ride with an electrical bike.
network.user(15).planRide(new Localization(48.85223492920534,2.339315414428711),
new Localization(48.84890268296978,2.321033477783203),"electrical");
//
SD.setTime(9, 31, 49);
//User4 starts a new ride in Station10 Odeon with an electrical bike.
//Doing so, he takes the last electrical bike of this station so the planned ride of User15 has to be updated.
network.user(4).newRide(network.station(10),"electrical");
//
SD.setTime(9, 33, 4);
//User15 decides to discard their planned ride to plan an other one.
network.user(15).discardPlannedRide();
//This time, User15 doesn't specify any bicycle type for their planned ride.
network.user(15).planRide(new Localization(48.85223492920534,2.339315414428711),
new Localization(48.84890268296978,2.321033477783203));
//User15 indicates that they're going for the ride they had planned.
network.user(15).getPlannedRide().start();
//
SD.setTime(9, 35, 38);
//User15 decides to follow the indications of their planned ride and starts a new ride from Station10 Odeon. They do not care about bicycle type.
network.user(15).newRide(network.station(10));
//
SD.setTime(9, 46, 34);
//User15 ends their ride in Station11 Vaneau.
network.user(15).endCurrentRide(network.station(11));
//
SD.setTime(9, 48, 13);
//User20 ends their ride in Station10 Odeon.
network.user(20).endCurrentRide(network.station(10));
//
SD.setTime(10, 37, 59);
//User1 ends their ride in Station10 Odeon.
network.user(1).endCurrentRide(network.station(10));
//
SD.setTime(10, 56, 03);
//User4 ends their ride in Station11 Vaneau.
network.user(4).endCurrentRide(network.station(11));

//Displaying the history of a station
System.out.println(network.station(10).historyTrace());
//Displaying the statistics of a few stations
StationBalance.display(network.station(10));
StationBalance.display(network.station(11));
//Displaying the statistics of a few users
UserBalance.display(network.user(1));
UserBalance.display(network.user(15));
UserBalance.display(network.user(20));

//Sorting of station database
//Basic
ArrayList<Station> stations = (ArrayList<Station>) network.getStationDatabase().clone();
System.out.println(" == Stations initial order == ");
System.out.println(stations.toString());
System.out.println();
//By ID
Collections.sort(stations);
System.out.println(" == Stations sorted by ID == ");
System.out.println(stations.toString());
System.out.println();
//By most used
Comparator<Station> c = new SortStationByMostUsed();
Collections.sort(stations, c);
System.out.println(" == Stations sorted by most used == ");
System.out.println(stations);
System.out.println();
//By least occupied
c = new SortStationByLeastOccupied();
Collections.sort(stations, c);
System.out.println(" == Stations sorted by least occupied == ");
System.out.println(stations);
System.out.println();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public int compare(Station s1, Station s2) {
SystemDate SD = SystemDate.getInstance();
Double ot1 = StationBalance.occupationRate(s1, s1.getCreatedAt(), new Date());
Double ot2 = StationBalance.occupationRate(s2, s2.getCreatedAt(), new Date());
return ot2.compareTo(ot1);
return ot1.compareTo(ot2);
}

}
62 changes: 51 additions & 11 deletions src/fr/ecp/IS1220/myVelib/core/StationBalance.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,81 @@ public static double occupationRate(Station station, Date start, Date end)
throw new RuntimeException(station+" did not exist yet during that time window.");
while (end.isAfter(station.getHistory().get(maxIndex).getTimeStamp())){
maxIndex++;
if (maxIndex == station.getHistory().size())
maxIndex--;
if (maxIndex == station.getHistory().size())
break;

}
maxIndex--;

int occupationTime = 0;
int totalTime = 0;

for (int i = 0; i < station.getHistory().size()-1; i++) {
ArrayList<ArrayList<Boolean>> parkingSlotStatus =
station.getHistory().get(i).getParkingSlotStatus();
Date nextTimeStamp = station.getHistory().get(i+1).getTimeStamp();
if (minIndex == maxIndex) {
ArrayList<ArrayList<Boolean>> parkingSlotStatus = station.getHistory().
get(minIndex).getParkingSlotStatus();
Date timeStamp = station.getHistory().get(minIndex).getTimeStamp();
if (start.isAfter(timeStamp))
timeStamp = start;
Date nextTimeStamp = end;
int numberOfOccupied = 0;
for (int j = 0; j < parkingSlotStatus.size(); j++) {
if (parkingSlotStatus.get(j).get(0) == true
|| parkingSlotStatus.get(j).get(1) == true) {
numberOfOccupied++;
}
}
int elapsedTime = new Duration(station.getHistory().get(i).
getTimeStamp(),nextTimeStamp).getDuration();
int elapsedTime = new Duration(timeStamp,nextTimeStamp).getDuration();
occupationTime += numberOfOccupied*elapsedTime;
totalTime += parkingSlotStatus.size()*elapsedTime;

return (double)occupationTime/(double)totalTime;
}

ArrayList<ArrayList<Boolean>> parkingSlotStatus = station.getHistory().
get(station. getHistory().size()-1).getParkingSlotStatus();
get(minIndex).getParkingSlotStatus();
Date timeStamp = station.getHistory().get(minIndex).getTimeStamp();
if (start.isAfter(timeStamp))
timeStamp = start;
Date nextTimeStamp = station.getHistory().get(minIndex+1).getTimeStamp();
int numberOfOccupied = 0;
for (int j = 0; j < parkingSlotStatus.size(); j++) {
if (parkingSlotStatus.get(j).get(0) == true
|| parkingSlotStatus.get(j).get(1) == true) {
numberOfOccupied++;
}
}
int elapsedTime = new Duration(station.getHistory().get(station.
getHistory().size()-1).getTimeStamp(),end).getDuration();
int elapsedTime = new Duration(timeStamp, nextTimeStamp).getDuration();
occupationTime += numberOfOccupied*elapsedTime;
totalTime += parkingSlotStatus.size()*elapsedTime;

for (int i = minIndex+1; i < maxIndex; i++) {
parkingSlotStatus = station.getHistory().get(i).getParkingSlotStatus();
timeStamp = station.getHistory().get(i).getTimeStamp();
nextTimeStamp = station.getHistory().get(i+1).getTimeStamp();
numberOfOccupied = 0;
for (int j = 0; j < parkingSlotStatus.size(); j++) {
if (parkingSlotStatus.get(j).get(0) == true
|| parkingSlotStatus.get(j).get(1) == true) {
numberOfOccupied++;
}
}
elapsedTime = new Duration(timeStamp,nextTimeStamp).getDuration();
occupationTime += numberOfOccupied*elapsedTime;
totalTime += parkingSlotStatus.size()*elapsedTime;
}

parkingSlotStatus = station.getHistory().
get(maxIndex).getParkingSlotStatus();
timeStamp = station.getHistory().get(maxIndex).getTimeStamp();
nextTimeStamp = end;
numberOfOccupied = 0;
for (int j = 0; j < parkingSlotStatus.size(); j++) {
if (parkingSlotStatus.get(j).get(0) == true
|| parkingSlotStatus.get(j).get(1) == true) {
numberOfOccupied++;
}
}
elapsedTime = new Duration(timeStamp,nextTimeStamp).getDuration();
occupationTime += numberOfOccupied*elapsedTime;
totalTime += parkingSlotStatus.size()*elapsedTime;

Expand Down

0 comments on commit ec0f46d

Please sign in to comment.