diff --git a/Code/Steiner/CO2-Daten-Projekt/bin/App.class b/Code/Steiner/CO2-Daten-Projekt/bin/App.class index 985e89e..ca3f457 100644 Binary files a/Code/Steiner/CO2-Daten-Projekt/bin/App.class and b/Code/Steiner/CO2-Daten-Projekt/bin/App.class differ diff --git a/Code/Steiner/CO2-Daten-Projekt/bin/FillTable.class b/Code/Steiner/CO2-Daten-Projekt/bin/FillTable.class index 57bc825..bbcabff 100644 Binary files a/Code/Steiner/CO2-Daten-Projekt/bin/FillTable.class and b/Code/Steiner/CO2-Daten-Projekt/bin/FillTable.class differ diff --git a/Code/Steiner/CO2-Daten-Projekt/bin/Lesson.class b/Code/Steiner/CO2-Daten-Projekt/bin/Lesson.class index 004bbc4..79eac00 100644 Binary files a/Code/Steiner/CO2-Daten-Projekt/bin/Lesson.class and b/Code/Steiner/CO2-Daten-Projekt/bin/Lesson.class differ diff --git a/Code/Steiner/CO2-Daten-Projekt/bin/Teacher.class b/Code/Steiner/CO2-Daten-Projekt/bin/Teacher.class index 1cb89e2..ec6a467 100644 Binary files a/Code/Steiner/CO2-Daten-Projekt/bin/Teacher.class and b/Code/Steiner/CO2-Daten-Projekt/bin/Teacher.class differ diff --git a/Code/Steiner/CO2-Daten-Projekt/src/App.java b/Code/Steiner/CO2-Daten-Projekt/src/App.java index 319bd88..1dcbdfe 100644 --- a/Code/Steiner/CO2-Daten-Projekt/src/App.java +++ b/Code/Steiner/CO2-Daten-Projekt/src/App.java @@ -1,32 +1,24 @@ -import java.util.List; import java.util.Arrays; import java.util.Scanner; +// Main application class public class App { private static final Scanner scanner = new Scanner(System.in); // Initialize the scanner // Constants for rooms and timetable dimensions private static final int ROOM_COUNT = 3; private static final int DAY_COUNT = 5; - private static final int LESSON_COUNT = 12; - - // Data sources for different rooms - private static final List room39Data = Data.getData("https://api.thingspeak.com/channels/1521262/feeds.csv", - 39); - private static final List room38Data = Data.getData("https://api.thingspeak.com/channels/1364580/feeds.csv", - 38); - private static final List room37Data = Data.getData("https://api.thingspeak.com/channels/1521263/feeds.csv", - 37); + private static final int LESSON_COUNT = 12; // Updated to match the lengths of START_TIMES and END_TIMES // Time table public static final Lesson[][][] timeTable = new Lesson[ROOM_COUNT][DAY_COUNT][LESSON_COUNT]; // Teacher initials and array private static final String[] TEACHER_INITIALS = { - "Bä", "Bd", "Bu", "Cg", "Di", "Do", "Eh", "Es", "Fh", "Gi", - "Gr", "Hm", "Hi", "Kg", "Kh", "Lz", "Lu", "Or", "Re", "Se", - "Ts", "Vt", "Zu" + "Bd", "Bu", "Cg", "Do", "Eh", "Fh", "Gi", "Gr", "Hm", "Hi", + "Kg", "Kh", "Lz", "Lu", "Or", "Re", "Se", "Ts", "Vt", "Zu" }; + private static final Teacher[] teachers = new Teacher[TEACHER_INITIALS.length]; // Initialization of teachers @@ -45,14 +37,28 @@ public class App { // Calculate points based on criteria private static void calculatePoints() { - // TODO: Implement point calculation logic based on specific criteria. - // Example: If a teacher opens the window during a small break (entire break 5 - // points - can - // be reduced by the amount the window was open). - // Maximum points for a long break: 10 points. - // Plus 5 bonus points if the teachers are switching after. - for (Teacher teacher : teachers) { - teacher.setPoints(0); + for (int day = 0; day < DAY_COUNT; day++) { + for (int room = 0; room < ROOM_COUNT; room++) { + for (int lessonIndex = 0; lessonIndex < LESSON_COUNT - 1; lessonIndex++) { + Lesson currentLesson = timeTable[room][day][lessonIndex]; + Lesson nextLesson = timeTable[room][day][lessonIndex + 1]; + + // Ensure both current and next lessons are not null + if (currentLesson != null && nextLesson != null) { + // Calculate points for the current lesson based on the next lesson + int points = currentLesson.calculatePoints(nextLesson); + + // Update the points for the teacher associated with the current lesson + String currentTeacherName = currentLesson.getTeacherName(); + for (Teacher teacher : teachers) { + if (teacher.getName().equals(currentTeacherName)) { + teacher.addPoints(points); // Update teacher points + break; + } + } + } + } + } } } @@ -64,22 +70,20 @@ public class App { // Print the teachers and their points private static void printTeachers() { System.out.println("Teachers and their points:"); - - int rank = 1; // Start with rank 1 - int previousPoints = -1; // Track the points of the previous teacher - int currentRankCount = 0; // Count how many teachers share the same rank + int rank = 1; + int previousPoints = -1; + int currentRankCount = 0; for (Teacher teacher : teachers) { if (teacher.getPoints() != previousPoints) { - rank += currentRankCount; // Update rank if points are different - currentRankCount = 1; // Reset count for the new points + rank += currentRankCount; + currentRankCount = 1; } else { - currentRankCount++; // Increment count for same points + currentRankCount++; } - // Print the teacher with their rank and points System.out.printf("%d. %s - %d points%n", rank, teacher.getName(), teacher.getPoints()); - previousPoints = teacher.getPoints(); // Update previous points + previousPoints = teacher.getPoints(); } } @@ -88,17 +92,18 @@ public class App { System.out.println(textOutput); while (!scanner.hasNextInt()) { System.out.println("Invalid input. Please enter a number."); - scanner.next(); // Clear the invalid input + scanner.next(); } - return scanner.nextInt(); // Read user input + return scanner.nextInt(); } // Print explanation of point calculations private static void printExplanation() { System.out.println("Point calculation explanation:"); - System.out.println("1. 5 points for keeping the window open during a small break."); - System.out.println("2. Up to 10 points for long breaks, with deductions for window usage."); - System.out.println("3. Bonus points for switching teachers."); + System.out.println("1. Up to 5 points for keeping the window open during a small break."); + System.out.println( + "2. Up to 10 points for long breaks, depending on the duration the window is open and deductions for usage."); + System.out.println("3. Additional 5 bonus points for switching teachers if another teacher is in the room."); } // Print shutdown animation @@ -107,7 +112,7 @@ public class App { for (int i = 3; i > 0; i--) { System.out.print(i + "..."); try { - Thread.sleep(1000); // Sleep for 1 second + Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } @@ -131,10 +136,9 @@ public class App { } else if (userInput == 0) { printShutDown(); } else { - // Handle invalid input System.out.println("Invalid input. Please enter 1 for Yes or 0 for No."); } - scanner.close(); // Close the scanner to avoid resource leaks + scanner.close(); } } diff --git a/Code/Steiner/CO2-Daten-Projekt/src/Data.java b/Code/Steiner/CO2-Daten-Projekt/src/Data.java index 7e45e80..068a501 100644 --- a/Code/Steiner/CO2-Daten-Projekt/src/Data.java +++ b/Code/Steiner/CO2-Daten-Projekt/src/Data.java @@ -84,4 +84,4 @@ public class Data { return new Data(classRomNumber, co2Level, day, date); } -} +} \ No newline at end of file diff --git a/Code/Steiner/CO2-Daten-Projekt/src/FillTable.java b/Code/Steiner/CO2-Daten-Projekt/src/FillTable.java index 66b07cb..adf9696 100644 --- a/Code/Steiner/CO2-Daten-Projekt/src/FillTable.java +++ b/Code/Steiner/CO2-Daten-Projekt/src/FillTable.java @@ -1,6 +1,5 @@ + public class FillTable { - // Define start and end times as class variables - // #region Class Variables private static final String[] START_TIMES = { "7:45", "8:35", "9:40", "10:30", "11:20", "12:10", "12:50", "13:35", "14:25", "15:15", "16:15", "17:05" @@ -11,14 +10,13 @@ public class FillTable { "14:20", "15:10", "16:10", "17:00", "17:50" }; - // #region fillTable - // Example method to fill a timetable with teachers - private static void fillTable(String[] teacherNames, String day, String[] startTime, String[] endTime, + private static void fillTable(String[] teacherShortNames, String day, String[] startTime, String[] endTime, int roomIndex) { int dayIndex = getDayIndex(day); - for (int i = 0; i < teacherNames.length; i++) { - // Room is determined by the caller method - App.timeTable[roomIndex][dayIndex][i] = new Lesson(37, teacherNames[i], startTime[i], endTime[i], day); + for (int i = 0; i < teacherShortNames.length && i < startTime.length && i < endTime.length; i++) { + Teacher teacher = new Teacher(teacherShortNames[i]); // Initialize Teacher with shortform + App.timeTable[roomIndex][dayIndex][i] = new Lesson(roomIndex, teacher.getName(), startTime[i], endTime[i], + day); } } @@ -35,36 +33,49 @@ public class FillTable { case "Friday": return 4; default: - return -1; // Invalid day + return -1; } } - // Fill 37 timetable - // #region table 37 static void fill37TimeTable() { int roomIndex = 0; - fillTable(new String[] { "Hm", "Py", "Hi", "Hm", "Le", "", "Gi", "Gi", "D", "Ts", "Ts", "" }, + fillTable(new String[] { "Hm", "Hm", "Hi", "Hm", "Hm", "Lunch", "Bd", "Gi", "Gi", "Ts", "Ts", "" }, "Monday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Ts", "Ts", "Ts", "Ts", "Le", "Lunch", "Lunch", "Fh", "Fh", "Fh", "Fh", "" }, + "Tuesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Lu", "Lu", "Lu", "Lu", "Cg", "Cg", "Lunch", "Se", "Se", "Se", "Se", "" }, + "Wednesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Gi", "Gi", "Ba", "Ba", "Ba", "Lunch", "Bd", "Du", "Lz", "Lz" }, + "Thursday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Kp", "KP", "Or", "Vt", "Vt", "Lunch", "Lunch", "Du", "Du", "Du", "", "" }, + "Friday", START_TIMES, END_TIMES, roomIndex); } - // Fill Room 38 timetable - // #region table 38 static void fill38TimeTable() { int roomIndex = 1; - fillTable(new String[] { "Bz", "Bz", "Bz", "Bz", "Bz", "", "Hn", "Hn", "Bu", "Bu", "Hn", "Hn" }, + fillTable(new String[] { "Bz", "Bz", "Bz", "Bz", "Bz", "Lunch", "Lunch", "Hn", "Hn", "Bu", "Hn", "Hn" }, "Monday", START_TIMES, END_TIMES, roomIndex); - fillTable(new String[] { "Br", "Kg", "Kh", "Re", "Es", "", "Bt", "EW", "FR", "FR", "VW", "VW" }, + fillTable(new String[] { "Kg", "Kg", "Eh", "Re", "Re", "Lunch", "Lunch", "Bt", "Kh", "Kh", "", "" }, "Tuesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Cg", "Cg", "Cg", "Cg", "Es", "Lunch", "Lunch", "Cg", "Cg", "", "", "" }, + "Wednesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Do", "Do", "Gr", "Gr", "Or", "Lunch", "Lunch", "Bu", "Bu", "Zu", "", "" }, + "Thursday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "", "Hu", "Ge", "Eh", "Eh", "Bu", "Lunch", "Eh", "Eh", "", "", "" }, + "Friday", START_TIMES, END_TIMES, roomIndex); } - // Fill Room 39 timetable - // #region table 39 static void fill39TimeTable() { int roomIndex = 2; - fillTable(new String[] { "", "", "", "", "", "", "", "", "", "", "", "" }, + fillTable(new String[] { "Bd", "Bd", "Bd", "Bd", "Bd", "Lunch", "Lunch", "Lu", "Lu", "Lu", "Lu", "" }, "Monday", START_TIMES, END_TIMES, roomIndex); - fillTable(new String[] { "", "", "", "", "", "", "", "", "", "", "", "" }, + fillTable(new String[] { "Do", "Do", "Zu", "Zu", "Zu", "Lunch", "Lunch", "Se", "Se", "Se", "Se", "" }, "Tuesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Cg", "Cg", "Cg", "Cg", "Bu", "Lunch", "Lunch", "Gi", "Gi", "Gi", "Gi", "" }, + "Wednesday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Bd", "Bd", "Bd", "Bd", "Or", "Lunch", "Lunch", "Le", "Le", "Le", "", "" }, + "Thursday", START_TIMES, END_TIMES, roomIndex); + fillTable(new String[] { "Gi", "Gi", "Gr", "Gr", "Gi", "Lunch", "Lunch", "Hi", "Hi", "Hi", "", "" }, + "Friday", START_TIMES, END_TIMES, roomIndex); } -} - +} \ No newline at end of file diff --git a/Code/Steiner/CO2-Daten-Projekt/src/Lesson.java b/Code/Steiner/CO2-Daten-Projekt/src/Lesson.java index 5990b7a..bb51798 100644 --- a/Code/Steiner/CO2-Daten-Projekt/src/Lesson.java +++ b/Code/Steiner/CO2-Daten-Projekt/src/Lesson.java @@ -1,3 +1,9 @@ +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.util.List; + public class Lesson { private int room; private String teacherName; @@ -5,6 +11,20 @@ public class Lesson { private String endTime; private String day; + // CO2 level tracking + private List co2Levels; // Assuming this is provided during breaks + private static final int SMALL_BREAK_POINTS = 5; + private static final int BIG_BREAK_POINT_PER_MINUTE = 1; + + // Define a DateTimeFormatter that accepts both 'HH:mm' and 'H:mm' + private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("H:mm") // Matches '8:30' + .optionalStart() + .appendPattern("HH:mm") // Matches '08:30' + .optionalEnd() + .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0) // Set default minutes to 0 if not provided + .toFormatter(); + // Constructor to initialize all fields public Lesson(int room, String teacherName, String startTime, String endTime, String day) { this.room = room; @@ -14,6 +34,7 @@ public class Lesson { this.day = day; } + // Getters public int getRoom() { return room; } @@ -34,20 +55,76 @@ public class Lesson { return day; } - public boolean isBreak() { - // Logic if it is between lessons - return false; + public boolean isBreak(Lesson nextLesson) { + LocalTime thisEndTime = LocalTime.parse(endTime, TIME_FORMATTER); + LocalTime nextStartTime = LocalTime.parse(nextLesson.getStartTime(), TIME_FORMATTER); + return thisEndTime.equals(nextStartTime); } - public boolean isBigBreak() { - // is the break longer than 5 minutes - // But was not the last lesson of the day - // Is not Lunch break - return false; + public boolean isBigBreak(Lesson nextLesson) { + LocalTime thisEndTime = LocalTime.parse(endTime, TIME_FORMATTER); + LocalTime nextStartTime = LocalTime.parse(nextLesson.getStartTime(), TIME_FORMATTER); + long breakDuration = java.time.Duration.between(thisEndTime, nextStartTime).toMinutes(); + boolean notLastLesson = !nextLesson.getEndTime().equals("17:00"); + boolean isLunchBreak = "Lunch".equals(nextLesson.getTeacherName()); + return breakDuration > 5 && notLastLesson && !isLunchBreak; } - public boolean isTeacherSwitch() { - // is a another teacher in this room - return false; + public boolean isTeacherSwitch(Lesson nextLesson) { + return room == nextLesson.getRoom() && !teacherName.equals(nextLesson.getTeacherName()); + } + + public void setCo2Levels(List co2Levels) { + this.co2Levels = co2Levels; + } + + public int calculatePoints(Lesson nextLesson) { + int points = 0; + + // Check for small break + if (isBreak(nextLesson)) { + points += calculateSmallBreakPoints(); + } + + // Check for long break + if (isBigBreak(nextLesson)) { + points += calculateBigBreakPoints(); + } + + // Check for teacher switch + if (isTeacherSwitch(nextLesson)) { + points += 5; // Additional 5 points for switching teachers + } + + return points; + } + + private int calculateSmallBreakPoints() { + if (co2Levels == null || co2Levels.size() < 5) + return 0; + + boolean continuousDecrease = true; + for (int i = 1; i < co2Levels.size(); i++) { + if (co2Levels.get(i) >= co2Levels.get(i - 1)) { + continuousDecrease = false; + break; + } + } + + return continuousDecrease ? SMALL_BREAK_POINTS : 0; + } + + private int calculateBigBreakPoints() { + if (co2Levels == null) + return 0; + + int points = 0; + for (int i = 1; i < co2Levels.size(); i++) { + if (co2Levels.get(i) < co2Levels.get(i - 1)) { + points += BIG_BREAK_POINT_PER_MINUTE; + } + } + + return points; } } \ No newline at end of file diff --git a/Code/Steiner/CO2-Daten-Projekt/src/Teacher.java b/Code/Steiner/CO2-Daten-Projekt/src/Teacher.java index 1331336..6311918 100644 --- a/Code/Steiner/CO2-Daten-Projekt/src/Teacher.java +++ b/Code/Steiner/CO2-Daten-Projekt/src/Teacher.java @@ -11,14 +11,11 @@ public class Teacher { // Static block to initialize the name mappings static { nameMap.put("Hm", "Hummel"); - nameMap.put("Bä", "Bäcker"); nameMap.put("Bd", "Bender"); nameMap.put("Bu", "Burger"); nameMap.put("Cg", "Chung"); - nameMap.put("Di", "Dimitrov"); nameMap.put("Do", "Doe"); nameMap.put("Eh", "Ehrlich"); - nameMap.put("Es", "Esposito"); nameMap.put("Fh", "Fischer"); nameMap.put("Gi", "Giordano"); nameMap.put("Gr", "Graham"); @@ -33,17 +30,17 @@ public class Teacher { nameMap.put("Ts", "Tanaka"); nameMap.put("Vt", "Vetter"); nameMap.put("Zu", "Zuniga"); - // Add more mappings as needed + // No additional mappings beyond those present in the timetable } // Constructor public Teacher(String name) { setName(name); - points = 0; + points = 0; // Initialize points to zero } public String getName() { - return name; + return name; // Return the full name of the teacher } public void setName(String name) { @@ -51,10 +48,14 @@ public class Teacher { } public int getPoints() { - return points; + return points; // Return the current points } public void setPoints(int points) { - this.points = points; + this.points = points; // Set the points to a specific value + } + + public void addPoints(int points) { + this.points += points; // Add points to the current total } }