ICT2201-P6-9 / air-manager

0 stars 0 forks source link

WBS 3.3.1 Create pseudo code for requirements #59

Open JonTJT opened 1 year ago

JonTJT commented 1 year ago

Todo: 1. Login (Meng Rong) 2. Admin (Jon) 3. Manager (Jon) 4. Staff (Meng Rong)

Todo (Updated 24/11):

JonTJT commented 1 year ago

Task update 25/11 13:00PM :

  1. Create Pseudo code for Staff dashboard processing.

Task update 25/11 15:32PM:

  1. Completed logic for processing weekly schedule
  2. Added empty functions and classes

Task update 25/11 17:14PM:

  1. Completed logic for processing Monthly workload

Task update 25/11 10:25PM:

  1. Completed Pseudo code for Staff dashboard processing.
  2. Completed logic for processing upcoming jobs.

Task update 25/11 11:48PM:

  1. Added comments for the pseudo code
  2. Added return value

Task update 26/11 01:23AM:

  1. Added line numbers for the CFG
  2. Changed some to be represented better in the CFG

Task update 26/11 16:24PM:

  1. Changed the pseudo code to match class diagram
    • Moved some of the logic of date range calculation to the "getFlightsWithinTimeRange" function
    • Changed the second for loop logic of the processing of the weekly schedule to a switch statement instead
    • Simplified some of the logic so that it is easier to understand

Task update 26/11 18:14PM:

  1. Updated function names to match the class diagram

Attached below is the latest version of the pseudo code for your convenience

JonTJT commented 1 year ago
1.  processStaffDashboard(Staff staff) {
        // Processing for weekly schedule.
2.      LocalDate today = LocalDate.now(); // Get today's date
3.      LocalDate startOfWeek = today; // Store today into a temporary varible "startOfWeek"
        //  Go backwards to monday and save it to "startOfWeek" variable
4.      while (startOfWeek.getDayOfWeek() != DayOfWeek.MONDAY) {
5.          startOfWeek = startOfWeek.minusDays(1);
        }
6.      ArrayList<Flight> weeklyAssignedFlights = getAssignmentsWithinTimeRange(startOfWeek, startOfWeek.plusDays(6)); // Get flights assigned to staff for the week
7.      Map<LocalDate, ArrayList<Flight>> weeklySchedule = new HashMap<LocalDate, ArrayList<Flight>>(); // Create a hashmap with the day of the week as the key, and an arraylist of flights attached to the day as the value.
8.      for (int i = 0; i < weeklyAssignedFlights.size(); i++) { // Iterate through all the days of the current week
9.          Flight currFlight = weeklyAssignedFlights.get(i); // Get a flight from the weeklyAssignedFlights variable based on the current iteration
10.         LocalDate dayToInsert = startOfWeek; // Default day is monday
11.         switch (currFlight.getDepartureTime().getDayOfWeek) { // Determine what day the flight is, and change the dayToInsert value to match the day
12.             case "TUESDAY":
13.                 dayToInsert.plusDays(1);
14.                 break;
15.             case "WEDNESDAY":
16.                 dayToInsert.plusDays(2);
17.                 break;
18.             case "THURSDAY":
19.                 dayToInsert.plusDays(3);
20.                 break;
21.             case "FRIDAY":
22.                 dayToInsert.plusDays(4);
23.                 break;
24.             case "SATURDAY":
25.                 dayToInsert.plusDays(5);
26.                 break;
27.             case "SUNDAY":
28.                 dayToInsert.plusDays(6);
29.                 break;
30.         }
31.         ArrayList<Flight> flightsOfTheDay = weeklySchedule.get(dateToInsert); // get the current value in the hashmap, if theres any and store it in an arraylist of flights that are tied to that day
32.         flightsOfTheDay.add(currFlight);
33.         weeklySchedule.put(dayToInsert, flightsOfTheDay); // Put all the flights of the day in the hashmap with the date as the key.
        }
        // Processing for monthly workload (2 weeks prior, current week, and next week)
34.     LocalDate startDate = startOfWeek.minusDays(14); // startDate of the monthly workload is 2 weeks prior to the start of the current week
35.     LocalDate endDate = startOfWeek.plusDays(13); // endDate of the monthly workload is the next week
36.     ArrayList<Flight> monthlyFlights = getAssignmentsWithinTimeRange(startDate, endDate); // Get flights assigned to the staff for the month
37.     ArrayList<Integer> hoursPerWeekOfMonth = new ArrayList<>(); // Store the number of hours per week in this variable. Index 0 = week1, index1 = week2 etc.
38.     int startWeek = getWeekOfYear(startDate);
39.     for (int i = 0; i < monthlyFlights.size(); i++){
40.         Flight currFlight = monthlyFlights.get(i);
41.         int currWeek = getWeekOfYear(currFlight.getDepartureTime());
42.         int indexToInsert = currWeek % startWeek;
43.         hoursPerWeekOfMonth.set(indexToInsert, hoursPerWeekOfMonth.get(indexToInsert) + currFlight.getDuration());
        }
        // Processing for upcoming jobs
44.     Map<String, LocalDate> upcomingJobs = new HashMap<String, LocalDate>();
45.     ArrayList<Flight> sortedFlightsArray = sortFlights(getUpcomingFlights());
46.     for (int i = 0; i < sortedFlightsArray.size(); i++) {
47.         Flight flight = sortedFlightsArray.get(i);
48.         upcomingJobs.put(flight.getFlightNo(), flight.getDepartureTime());} 
49.     const dashboardData = [weeklySchedule,hoursPerWeekOfMonth, upcomingJobs];
50.     return dashboardData;
    }