Task 2.4 Step 1: Show actual exam assignments per classroom

This commit is contained in:
Omnicscient
2025-12-16 23:27:12 +03:00
parent 9e082c6cac
commit 67dc3f0dd1

View File

@@ -10,25 +10,45 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import org.example.se302.model.Classroom; import org.example.se302.model.Classroom;
import org.example.se302.model.ExamAssignment;
import org.example.se302.model.ScheduleConfiguration;
import org.example.se302.service.DataManager; import org.example.se302.service.DataManager;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/** /**
* Controller for the Classroom Schedule view. * Controller for the Classroom Schedule view.
* Shows exam assignments for each classroom.
*/ */
public class ScheduleClassroomController { public class ScheduleClassroomController {
@FXML private ComboBox<Classroom> classroomComboBox; @FXML
@FXML private Label selectedClassroomLabel; private ComboBox<Classroom> classroomComboBox;
@FXML private TableView<ClassroomSlotEntry> scheduleTable; @FXML
@FXML private TableColumn<ClassroomSlotEntry, String> dateColumn; private Label selectedClassroomLabel;
@FXML private TableColumn<ClassroomSlotEntry, String> timeColumn; @FXML
@FXML private TableColumn<ClassroomSlotEntry, String> courseColumn; private TableView<ClassroomSlotEntry> scheduleTable;
@FXML private TableColumn<ClassroomSlotEntry, Number> studentsColumn; @FXML
@FXML private TableColumn<ClassroomSlotEntry, String> utilizationColumn; private TableColumn<ClassroomSlotEntry, String> dateColumn;
@FXML private Label utilizationLabel; @FXML
private TableColumn<ClassroomSlotEntry, String> timeColumn;
@FXML
private TableColumn<ClassroomSlotEntry, String> courseColumn;
@FXML
private TableColumn<ClassroomSlotEntry, Number> studentsColumn;
@FXML
private TableColumn<ClassroomSlotEntry, String> utilizationColumn;
@FXML
private Label utilizationLabel;
private DataManager dataManager; private DataManager dataManager;
// Reference to the current schedule state (set by parent controller)
private Map<String, ExamAssignment> currentAssignments;
private ScheduleConfiguration configuration;
@FXML @FXML
public void initialize() { public void initialize() {
dataManager = DataManager.getInstance(); dataManager = DataManager.getInstance();
@@ -37,31 +57,63 @@ public class ScheduleClassroomController {
classroomComboBox.setItems(dataManager.getClassrooms()); classroomComboBox.setItems(dataManager.getClassrooms());
// Set up table columns // Set up table columns
dateColumn.setCellValueFactory(cellData -> dateColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getDate()));
new SimpleStringProperty(cellData.getValue().getDate())); timeColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getTime()));
timeColumn.setCellValueFactory(cellData -> courseColumn.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCourse()));
new SimpleStringProperty(cellData.getValue().getTime())); studentsColumn.setCellValueFactory(
courseColumn.setCellValueFactory(cellData -> cellData -> new SimpleIntegerProperty(cellData.getValue().getStudentCount()));
new SimpleStringProperty(cellData.getValue().getCourse())); utilizationColumn.setCellValueFactory(
studentsColumn.setCellValueFactory(cellData -> cellData -> new SimpleStringProperty(cellData.getValue().getUtilization()));
new SimpleIntegerProperty(cellData.getValue().getStudentCount())); }
utilizationColumn.setCellValueFactory(cellData ->
new SimpleStringProperty(cellData.getValue().getUtilization())); /**
* Sets the current schedule assignments. Called by parent controller after
* schedule generation.
*/
public void setScheduleData(Map<String, ExamAssignment> assignments, ScheduleConfiguration config) {
this.currentAssignments = assignments;
this.configuration = config;
} }
@FXML @FXML
private void onShowSchedule() { private void onShowSchedule() {
Classroom selected = classroomComboBox.getValue(); Classroom selected = classroomComboBox.getValue();
if (selected == null) return; if (selected == null)
return;
selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() + selectedClassroomLabel.setText("Schedule for: " + selected.getClassroomId() +
" (Capacity: " + selected.getCapacity() + ")"); " (Capacity: " + selected.getCapacity() + ")");
// For demo: show empty schedule
ObservableList<ClassroomSlotEntry> entries = FXCollections.observableArrayList(); ObservableList<ClassroomSlotEntry> entries = FXCollections.observableArrayList();
scheduleTable.setItems(entries);
utilizationLabel.setText("Overall Utilization: 0% (No exams scheduled)"); // If we have assignments, filter by this classroom
if (currentAssignments != null && !currentAssignments.isEmpty()) {
for (ExamAssignment assignment : currentAssignments.values()) {
if (assignment.isAssigned() &&
selected.getClassroomId().equals(assignment.getClassroomId())) {
// Format date
String dateStr;
if (configuration != null && configuration.getStartDate() != null) {
LocalDate examDate = configuration.getStartDate()
.plusDays(assignment.getDay());
dateStr = examDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
} else {
dateStr = "Day " + (assignment.getDay() + 1);
}
// Format time
String timeStr = "Slot " + (assignment.getTimeSlotIndex() + 1);
entries.add(new ClassroomSlotEntry(
dateStr, timeStr, assignment.getCourseCode(),
assignment.getStudentCount(), "-"));
}
}
}
scheduleTable.setItems(entries);
utilizationLabel.setText("Exams shown: " + entries.size());
} }
// Helper class for table entries // Helper class for table entries
@@ -72,7 +124,8 @@ public class ScheduleClassroomController {
private final int studentCount; private final int studentCount;
private final String utilization; private final String utilization;
public ClassroomSlotEntry(String date, String time, String course, int studentCount, String utilization) { public ClassroomSlotEntry(String date, String time, String course, int studentCount,
String utilization) {
this.date = date; this.date = date;
this.time = time; this.time = time;
this.course = course; this.course = course;
@@ -80,10 +133,24 @@ public class ScheduleClassroomController {
this.utilization = utilization; this.utilization = utilization;
} }
public String getDate() { return date; } public String getDate() {
public String getTime() { return time; } return date;
public String getCourse() { return course; } }
public int getStudentCount() { return studentCount; }
public String getUtilization() { return utilization; } public String getTime() {
return time;
}
public String getCourse() {
return course;
}
public int getStudentCount() {
return studentCount;
}
public String getUtilization() {
return utilization;
}
} }
} }