Meeting fixes and new TODO

This commit is contained in:
HeshamTB 2020-12-17 14:27:11 +03:00
parent 67b313aabf
commit d915e04832
2 changed files with 34 additions and 9 deletions

View File

@ -7,6 +7,8 @@ import java.util.Calendar;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.Color;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
@ -208,7 +210,7 @@ public class GUI_ViewBuses {
else busData[i][3] = "%0";
busData[i][4] = vehicles.get(i).getTripTime();
if (vehicles.get(i).isArrivedToDest())
busData[i][5] = vehicles.get(i).getTimeOfArrival().toString();//Formula of time
busData[i][5] = getShortTime(vehicles.get(i).getTimeOfArrival());
else busData[i][5] = "NOT Arrived";
}
table.setModel(new DefaultTableModel(busData ,busColNames));
@ -222,4 +224,10 @@ public class GUI_ViewBuses {
lblDate.setText(currenttimeManager.getCurrentTime().toString());
updateTable();
}
private String getShortTime(Date time) {
Calendar cal = new GregorianCalendar();
cal.setTime(time);
return String.format("%02d:%02d", cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE));
}
}

View File

@ -48,10 +48,15 @@ public class MakkahCity {
private static JLabel lblBusesArrivedInTheLastHourValue;
private static JLabel lblAverageTripForLastHourValue;
private static JButton btnPause;
private static JLabel lblAverageTimeForTheTrip;
public static void main(String[] args) {
//TODO: View camp >> View Report
//TODO: History view
//TODO: Arrival dates (Arafat, Mina)
//TODO: fix state errors
t.start();
//Gen Camp
campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
@ -320,7 +325,7 @@ public class MakkahCity {
lblAvgTime.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAvgTime.setBounds(287, 694, 208, 29);
JLabel lblAverageTimeForTheTrip = new JLabel("-:--");
lblAverageTimeForTheTrip = new JLabel("-:--");
lblAverageTimeForTheTrip.setForeground(Color.WHITE);
lblAverageTimeForTheTrip.setFont(new Font("Rockwell", Font.PLAIN, 16));
lblAverageTimeForTheTrip.setBounds(512, 701, 101, 14);
@ -1240,15 +1245,27 @@ public class MakkahCity {
lblBusesArrivedInTheLastHourValue.setText(NumberOfBussPerHour);
lblAverageTripForLastHourValue.setText(avgTimeOfTrip());
lblAverageTimeForTheTrip.setText(getAvgTripForAllDis());
}
//TODO Avg for All the Dist
public static void getAvgTripForAllDis() {
for (int i = 0; i < campPerDistrict.length; i++) {
getAvgTimeOfTrip(District.values()[i]);
public static String getAvgTripForAllDis() {
int sum = 0;
int counter = 1;
for (Campaign campaign : listOfCampaigns) {
for (Vehicle vehicle : campaign.getVehicles()) {
if (vehicle.isArrivedToDest()) {
long minutes = (vehicle.getTimeOfArrival().getTime() - vehicle.getTimeStartedMoving().getTime())/60000;
sum+= minutes;
counter++;
}
//lblAverageTripForLastHourValue.setText();
}
}//Make the following a method since it is the same other method
sum = sum /counter;
int hours = sum / 60;
int minutes = sum % 60;
if (hours == 0 && minutes == 0) return " n/a";
return String.format("%2d:%02d", hours,minutes);
}
}