District report evey hour 2-12-2020 meeting

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-12-02 00:46:05 +03:00
parent 19291fbfe1
commit 35ce9ca754
Signed by: Hesham
GPG Key ID: 74876157D199B09E
2 changed files with 18 additions and 14 deletions

View File

@ -44,7 +44,6 @@ public class MakkahCity {
//Set Routes for Campaigns //Set Routes for Campaigns
setRoutesForCampaigns(Mashier.ARAFAT); setRoutesForCampaigns(Mashier.ARAFAT);
System.out.println(preSimulationReport());
while(!firstDayTimeMan.isEnded()) { while(!firstDayTimeMan.isEnded()) {
//Start of Every hour //Start of Every hour
if (firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){ if (firstDayTimeMan.getCurrentCalendar().get(Calendar.MINUTE) == 0){
@ -401,12 +400,12 @@ public class MakkahCity {
else status = " Status: Heading to hotels"; else status = " Status: Heading to hotels";
String headerFormat = "******Streets report*****\n" + String headerFormat = "******Streets report*****\n" +
"Time: %s%s\n" + "Time: %s%s\n" +
" Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time" + " Street name |Street Load| Total | Buses | Local Vehicles | Avg. Time\n";
"*********| District | Average Arrival | Avg. time\n";
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status)); report.append(String.format(headerFormat, currenttimeManager.getCurrentTime(), status));
String streetFormat = "%-18s | %%%-8s | %5d | %5d | %14d | %-9s"; String streetFormat = "%-18s | %%%-8s | %5d | %5d | %14d | %-9s";
String districtForamt = " | %-9s | %%%-14d | %s";
for (int i = 0; i < stdStreet.length; i++) { for (int i = 0; i < stdStreet.length; i++) {
int cap = stdStreet[i].getPercentRemainingCapacity(); int cap = stdStreet[i].getPercentRemainingCapacity();
report.append(String.format(streetFormat, report.append(String.format(streetFormat,
@ -416,13 +415,10 @@ public class MakkahCity {
stdStreet[i].getNumberOfBuses(), stdStreet[i].getNumberOfBuses(),
stdStreet[i].getNumberOfLocalCars(), stdStreet[i].getNumberOfLocalCars(),
avgTimeOnStreet(stdStreet[i]))); avgTimeOnStreet(stdStreet[i])));
if (i < 3){
report.append(String.format(districtForamt, District.values()[i], getPercentArrival(District.values()[i]),getAvgTimeOfTrip(District.values()[i])));
}
report.append("\n"); report.append("\n");
} }
report.append("\n").append(getFinalRep()); report.append("\n").append(getFinalRep()).append("\n");
report.append("*************************"); report.append(preSimulationReport());
return report.toString(); return report.toString();
} }
@ -433,7 +429,7 @@ public class MakkahCity {
//Redundant loops slow down execution. find better sol. //Redundant loops slow down execution. find better sol.
for (Campaign campaign : listOfCampaigns) { for (Campaign campaign : listOfCampaigns) {
numberOfBusses += campaign.getNumberOfBusses(); numberOfBusses += campaign.getNumberOfBusses();
} //TODO Add max min time, Estimated arrivel if taken street. } //TODO Add max min time.
//TODO: And print all routes with their streets. //TODO: And print all routes with their streets.
String fFormat = "All arrived to %s at: %s"; String fFormat = "All arrived to %s at: %s";
boolean arr = isAllArrived();//since it has looping. use once. boolean arr = isAllArrived();//since it has looping. use once.
@ -471,7 +467,7 @@ public class MakkahCity {
int hours = sum / 60; int hours = sum / 60;
int minutes = sum % 60; int minutes = sum % 60;
if (hours == 0 && minutes == 0) return "(No arrivals) in last Hour"; if (hours == 0 && minutes == 0) return "(No arrivals) in last Hour";
return String.format("%2d:%02d", hours,minutes); return String.format("%2d:%02d", hours, minutes);
} }
private static int getPercentArrival(District district) { private static int getPercentArrival(District district) {
@ -539,15 +535,16 @@ public class MakkahCity {
private static String preSimulationReport() { private static String preSimulationReport() {
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append("******************************District details******************************\n"); report.append("******************************District details******************************\n");
report.append("District | Campaigns | Busses | Best time to Arafat | Best time to District \n"); report.append("District | Campaigns | Busses | Avg arrival | Best time to Arafat | Best time to District \n");
for (int i = 0; i < campPerDistrict.length; i++) { for (int i = 0; i < campPerDistrict.length; i++) {
//Per District, i denotes district index //Per District, i denotes district index
report.append(String.format("%-9s|",campPerDistrict[i].get(0).getHotelDistrict().name())); report.append(String.format("%-9s|",campPerDistrict[i].get(0).getHotelDistrict().name()));
report.append(String.format(" %-10d|",campPerDistrict[i].size())); report.append(String.format(" %-10d|",campPerDistrict[i].size()));
report.append(String.format(" %-7d|", busesInDistrict(District.values()[i]))); report.append(String.format(" %-7d|", busesInDistrict(District.values()[i])));
report.append(String.format(" %%%-11d|", getPercentArrival(District.values()[i])));
report.append(String.format(" %-20s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus()))); report.append(String.format(" %-20s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.ARAFAT).getFastestTimeOfTravel(new Bus())));
report.append(String.format(" %-20s|", getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus()))); report.append(String.format(" %-20s", getShortestRoute(campPerDistrict[i].get(0), Mashier.MINA).getFastestTimeOfTravel(new Bus())));
//Calc values per dist here. //Calc values per dist here.
report.append("\n"); report.append("\n");
@ -569,7 +566,7 @@ public class MakkahCity {
sum /= counter; sum /= counter;
int hours = sum / 60; int hours = sum / 60;
int minutes = sum % 60; int minutes = sum % 60;
if (hours == 0 && minutes == 0) return "n/a"; if (hours == 0 && minutes == 0) return street.getFastestTimeOfTravel(new Bus());
return String.format("%02d:%02d", hours, minutes); return String.format("%02d:%02d", hours, minutes);
} }

View File

@ -162,6 +162,13 @@ public class Street {
return false; return false;
} }
public String getFastestTimeOfTravel(Vehicle vehicle) {
double totalLength = length;
int maxSpeed = vehicle.getMaxSpeed();
int totalTime = (int) (totalLength/maxSpeed);
return String.format("%02d:%02d",totalTime / 60, totalTime % 60);
}
public String toString(){ public String toString(){
StringBuilder printedStreet = new StringBuilder(); StringBuilder printedStreet = new StringBuilder();
//Imagine steert is 32 units in lengths (scale down) //Imagine steert is 32 units in lengths (scale down)