Merge branch 'main' of https://github.com/SageTheDM/IMS-java
This commit is contained in:
commit
bfa313d60d
23 changed files with 519 additions and 69 deletions
Code/Steiner/CO2-Daten-Projekt-V2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -12,14 +12,37 @@ public class App {
|
|||
public static final Lesson[][][] timeTable = new Lesson[ROOM_COUNT][DAY_COUNT][LESSON_COUNT];
|
||||
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
||||
|
||||
// URLs for fetching CO2 data
|
||||
private static final String ROOM_39_URL = "https://api.thingspeak.com/channels/1521262/feeds.csv?results=8000";
|
||||
private static final String ROOM_38_URL = "https://api.thingspeak.com/channels/1364580/feeds.csv?results=8000";
|
||||
private static final String ROOM_37_URL = "https://api.thingspeak.com/channels/1521263/feeds.csv?results=8000";
|
||||
// Date constants
|
||||
private static final int START_YEAR = 2024;
|
||||
private static final int START_MONTH = 11; // November
|
||||
private static final int START_DAY = 4;
|
||||
private static final String START_DATE = String.format("%d-%02d-%02d%%2000:00:00", START_YEAR, START_MONTH,
|
||||
START_DAY);
|
||||
|
||||
private static final List<Co2Data> room39Data = Co2Data.getData(ROOM_39_URL, 39);
|
||||
private static final List<Co2Data> room38Data = Co2Data.getData(ROOM_38_URL, 38);
|
||||
private static final List<Co2Data> room37Data = Co2Data.getData(ROOM_37_URL, 37);
|
||||
private static final int END_YEAR = 2024;
|
||||
private static final int END_MONTH = 11; // November
|
||||
private static final int END_DAY = 8;
|
||||
private static final String END_DATE = String.format("%d-%02d-%02d%%2000:00:00", END_YEAR, END_MONTH, END_DAY);
|
||||
|
||||
// Room channel numbers
|
||||
private static final int ROOM_39_NUMBER = 1521262;
|
||||
private static final int ROOM_38_NUMBER = 1364580;
|
||||
private static final int ROOM_37_NUMBER = 1521263;
|
||||
|
||||
// Room URLs
|
||||
private static final String ROOM_39_URL = createUrl(ROOM_39_NUMBER);
|
||||
private static final String ROOM_38_URL = createUrl(ROOM_38_NUMBER);
|
||||
private static final String ROOM_37_URL = createUrl(ROOM_37_NUMBER);
|
||||
|
||||
// Room data
|
||||
private static final List<Co2Data> ROOM_39_DATA = Co2Data.getData(ROOM_39_URL, 39);
|
||||
private static final List<Co2Data> ROOM_38_DATA = Co2Data.getData(ROOM_38_URL, 38);
|
||||
private static final List<Co2Data> ROOM_37_DATA = Co2Data.getData(ROOM_37_URL, 37);
|
||||
|
||||
private static String createUrl(int channelNumber) {
|
||||
return String.format("https://api.thingspeak.com/channels/%d/feeds.csv?start=%s&end=%s", channelNumber,
|
||||
START_DATE, END_DATE);
|
||||
}
|
||||
|
||||
// #region Initialization
|
||||
private static void initializeTeachers() {
|
||||
|
@ -36,23 +59,22 @@ public class App {
|
|||
}
|
||||
|
||||
// #region Calculation
|
||||
private static void calculatePoints(List<Co2Data> data) {
|
||||
private static void calculatePoints(List<Co2Data> data, int roomNumber) {
|
||||
for (Co2Data co2Data : data) {
|
||||
Date temp = co2Data.getDate();
|
||||
int intHour = temp.getHour();
|
||||
int intMinute = temp.getMinute();
|
||||
int intDay = temp.getDay();
|
||||
if (FillTable.isBreak(intHour, intMinute)) {
|
||||
String whatBreak = FillTable.whatBreakIsIt(intHour, intMinute, intDay);
|
||||
String whatBreak = FillTable.whatBreakIsIt(intHour, intMinute);
|
||||
int[] time = FillTable.whatTime(intHour, intMinute);
|
||||
|
||||
switch (whatBreak) {
|
||||
case "short":
|
||||
calculateFiveMinuteBreakPoints(co2Data);
|
||||
calculateFiveMinuteBreakPoints(data, time, roomNumber);
|
||||
break;
|
||||
case "long":
|
||||
calculateLongerBreakPoints(co2Data);
|
||||
calculateLongerBreakPoints(data, time, roomNumber);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -60,15 +82,105 @@ public class App {
|
|||
}
|
||||
}
|
||||
|
||||
private static void calculateFiveMinuteBreakPoints(Co2Data data) {
|
||||
calculateBonusPoints(data);
|
||||
// #region 5min
|
||||
private static int calculateFiveMinuteBreakPoints(List<Co2Data> data, int[] time, int roomNumber) {
|
||||
// Calculate the time range for the break (e.g., a 5-minute break)
|
||||
int startMinute = time[0];
|
||||
int endMinute = time[1];
|
||||
|
||||
int points = 5; // Start with maximum points
|
||||
|
||||
// Loop over each minute in the break and check the CO2 level
|
||||
for (int i = startMinute; i < endMinute; i++) {
|
||||
// Get the CO2 data for the current minute (using the data list)
|
||||
Co2Data minuteData = getCo2DataForMinute(data, i); // data is already a List<Co2Data>
|
||||
|
||||
if (minuteData != null) {
|
||||
int currentCo2 = minuteData.getCo2Level();
|
||||
Co2Data previousMinuteData = getCo2DataForMinute(data, i - 1); // data is a List<Co2Data>
|
||||
|
||||
if (previousMinuteData != null) {
|
||||
int previousCo2 = previousMinuteData.getCo2Level();
|
||||
|
||||
// If CO2 level doesn't decrease, subtract points
|
||||
if (currentCo2 >= previousCo2) {
|
||||
points--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After calculating the points, consider any bonus points for teacher switch or
|
||||
// other criteria
|
||||
points += calculateBonusPoints(data, time, roomNumber);
|
||||
|
||||
return Math.max(points, 0); // Ensure that points don't go below zero
|
||||
}
|
||||
|
||||
private static void calculateLongerBreakPoints(Co2Data data) {
|
||||
calculateBonusPoints(data);
|
||||
// #region 5+ min
|
||||
private static int calculateLongerBreakPoints(List<Co2Data> data, int[] time, int roomNumber) {
|
||||
// Take the time for the entire break
|
||||
int startMinute = time[0];
|
||||
int endMinute = time[1];
|
||||
|
||||
int points = 10; // Start with maximum points for longer break
|
||||
|
||||
// Loop over each minute in the break and check the CO2 level
|
||||
for (int i = startMinute; i < endMinute; i++) {
|
||||
// Get the CO2 data for the current minute (using the data list)
|
||||
Co2Data minuteData = getCo2DataForMinute(data, i); // data is already a List<Co2Data>
|
||||
|
||||
if (minuteData != null) {
|
||||
int currentCo2 = minuteData.getCo2Level();
|
||||
Co2Data previousMinuteData = getCo2DataForMinute(data, i - 1); // data is a List<Co2Data>
|
||||
|
||||
if (previousMinuteData != null) {
|
||||
int previousCo2 = previousMinuteData.getCo2Level();
|
||||
|
||||
// If CO2 level doesn't decrease, subtract points
|
||||
if (currentCo2 >= previousCo2) {
|
||||
points--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// After calculating the points, consider any bonus points for teacher switch or
|
||||
// other criteria
|
||||
points += calculateBonusPoints(data, time, roomNumber);
|
||||
|
||||
return Math.max(points, 0); // Ensure that points don't go below zero
|
||||
}
|
||||
|
||||
private static void calculateBonusPoints(Co2Data data) {
|
||||
// #region bonus
|
||||
private static int calculateBonusPoints(List<Co2Data> data, int[] time, int roomNumber) {
|
||||
// Check if the next lesson isn't lunch or the same teacher (if the next lesson
|
||||
// is lunch, no bonus points possible)
|
||||
boolean isTeacherChange = isTeacherChange(data, roomNumber, time); // Check if the teacher is changing
|
||||
boolean isNextLessonLunch = FillTable.isNextLessonLunch();
|
||||
|
||||
if (!isNextLessonLunch && isTeacherChange) {
|
||||
return 5; // Bonus points for teacher switch
|
||||
} else {
|
||||
return 0; // No bonus points
|
||||
}
|
||||
}
|
||||
|
||||
// #region checks
|
||||
private static boolean isTeacherChange(List<Co2Data> data, int roomNumber, int[] time) {
|
||||
// go through the lesson table of that day and time for the room
|
||||
// check if the last teacher in the room equals itself or another teacher
|
||||
return false; // Placeholder logic (to be implemented based on the timetable)
|
||||
}
|
||||
|
||||
private static Co2Data getCo2DataForMinute(List<Co2Data> data, int minute) {
|
||||
// Logic to get the CO2 data for a specific minute in the break
|
||||
for (Co2Data co2Data : data) {
|
||||
if (co2Data.getDate().getMinute() == minute) {
|
||||
return co2Data;
|
||||
}
|
||||
}
|
||||
return null; // Return null if no data matches
|
||||
}
|
||||
|
||||
// #region Sorting Printing
|
||||
|
@ -106,10 +218,8 @@ public class App {
|
|||
while (true) {
|
||||
if (scanner.hasNextInt()) {
|
||||
return scanner.nextInt();
|
||||
} else {
|
||||
System.out.println("Invalid input. Please enter a number.");
|
||||
scanner.next();
|
||||
}
|
||||
scanner.next(); // Clear invalid input
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +227,8 @@ public class App {
|
|||
System.out.println("Point calculation explanation:");
|
||||
System.out.println("1. Up to 5 points for keeping the window open during a small pause.");
|
||||
System.out.println("2. Up to 10 points for long pauses, depending on window usage.");
|
||||
System.out.println("3. 5 bonus points for teacher switches in the room.");
|
||||
System.out.println("3. 5 bonus points for teacher switches in classrooms.");
|
||||
System.out.println("4. Deduct points if CO2 levels are too high.");
|
||||
}
|
||||
|
||||
private static void printShutDown() {
|
||||
|
@ -127,17 +238,16 @@ public class App {
|
|||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("Goodbye!");
|
||||
}
|
||||
|
||||
// @TODO: remove this before hand-in deadline
|
||||
public static void debbugingValueLists(List<Co2Data> data) {
|
||||
// Debugging co2Data
|
||||
int index = 0;
|
||||
for (Co2Data a : room37Data) {
|
||||
for (Co2Data a : data) {
|
||||
System.out.println(a.toString());
|
||||
index++;
|
||||
}
|
||||
|
@ -150,16 +260,16 @@ public class App {
|
|||
public static void main(String[] args) {
|
||||
boolean debbugingList = false;
|
||||
if (debbugingList) {
|
||||
debbugingValueLists(room37Data);
|
||||
debbugingValueLists(ROOM_37_DATA);
|
||||
// debbugingValueLists(room38Data);
|
||||
// debbugingValueLists(room39Data);
|
||||
} else {
|
||||
System.out.println("Calculations in process please do not shut off...");
|
||||
fillInTimeTable();
|
||||
initializeTeachers();
|
||||
calculatePoints(room37Data);
|
||||
calculatePoints(room38Data);
|
||||
calculatePoints(room39Data);
|
||||
calculatePoints(ROOM_37_DATA, 37);
|
||||
calculatePoints(ROOM_38_DATA, 38);
|
||||
calculatePoints(ROOM_39_DATA, 39);
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
while (true) {
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class Date {
|
||||
// #region Fields
|
||||
private int day;
|
||||
|
@ -42,34 +39,9 @@ public class Date {
|
|||
return minute;
|
||||
}
|
||||
|
||||
// #region Helper Method to Check Daylight Saving Time
|
||||
private boolean isDaylightSavingTime() {
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.set(year, month - 1, day); // Month is 0-based in Calendar
|
||||
|
||||
// Last Sunday in March (DST starts)
|
||||
Calendar lastSundayInMarch = new GregorianCalendar(year, Calendar.MARCH, 31);
|
||||
lastSundayInMarch.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
||||
lastSundayInMarch.add(Calendar.DATE, -7); // Go back to last Sunday of March
|
||||
|
||||
// Last Sunday in October (DST ends)
|
||||
Calendar lastSundayInOctober = new GregorianCalendar(year, Calendar.OCTOBER, 31);
|
||||
lastSundayInOctober.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
||||
lastSundayInOctober.add(Calendar.DATE, -7); // Go back to last Sunday of October
|
||||
|
||||
// Check if the current date is within the DST period
|
||||
return calendar.after(lastSundayInMarch) && calendar.before(lastSundayInOctober);
|
||||
}
|
||||
|
||||
// #region Adjust UTC to Switzerland Time
|
||||
private void adjustForSwitzerlandTime() {
|
||||
if (isDaylightSavingTime()) {
|
||||
// Switzerland is UTC +2 during DST (CEST)
|
||||
hour += 2;
|
||||
} else {
|
||||
// Switzerland is UTC +1 during Standard Time (CET)
|
||||
hour += 1;
|
||||
}
|
||||
hour += 1;
|
||||
|
||||
// Adjust if the hour exceeds 24 or falls below 0
|
||||
if (hour >= 24) {
|
||||
|
|
|
@ -16,7 +16,8 @@ public class FillTable {
|
|||
int dayIndex = getDayIndex(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],
|
||||
App.timeTable[roomIndex][dayIndex][i] = new Lesson(roomIndex, teacher.getName(), startTime[i],
|
||||
endTime[i],
|
||||
day);
|
||||
}
|
||||
}
|
||||
|
@ -83,12 +84,76 @@ public class FillTable {
|
|||
"Friday", START_TIMES, END_TIMES, roomIndex);
|
||||
}
|
||||
|
||||
// #region Check Methods
|
||||
static int[] whatTime(int intHour, int intMinute) {
|
||||
int[] result = new int[2]; // [most recent end time, next start time]
|
||||
result[0] = -1; // Initialize to -1 (no previous end time found)
|
||||
result[1] = -1; // Initialize to -1 (no next start time found)
|
||||
|
||||
for (int i = 0; i < END_TIMES.length; i++) {
|
||||
// Parse END_TIMES[i]
|
||||
String[] endParts = END_TIMES[i].split(":");
|
||||
int endHour = Integer.parseInt(endParts[0]);
|
||||
int endMinute = Integer.parseInt(endParts[1]);
|
||||
|
||||
// Parse START_TIMES[i]
|
||||
String[] startParts = START_TIMES[i].split(":");
|
||||
int startHour = Integer.parseInt(startParts[0]);
|
||||
int startMinute = Integer.parseInt(startParts[1]);
|
||||
|
||||
// Check for the most recent end time
|
||||
if ((intHour > endHour) || (intHour == endHour && intMinute >= endMinute)) {
|
||||
result[0] = i; // Track the most recent lesson's end time index
|
||||
}
|
||||
|
||||
// Check for the next start time
|
||||
if ((intHour < startHour) || (intHour == startHour && intMinute < startMinute)) {
|
||||
result[1] = i; // Track the next lesson's start time index
|
||||
break; // No need to continue since START_TIMES is sorted
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean isNextLessonLunch(int intHour, int intMinute, int roomIndex) {
|
||||
int currentTimeInMinutes = intHour * 60 + intMinute;
|
||||
int nextLessonIndex = getNextLessonIndex(currentTimeInMinutes, roomIndex);
|
||||
|
||||
if (nextLessonIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String nextLessonStartTime = START_TIMES[nextLessonIndex];
|
||||
String[] nextLessonStartParts = nextLessonStartTime.split(":");
|
||||
int nextLessonStartInMinutes = Integer.parseInt(nextLessonStartParts[0]) * 60
|
||||
+ Integer.parseInt(nextLessonStartParts[1]);
|
||||
|
||||
if (nextLessonStartInMinutes > currentTimeInMinutes) {
|
||||
String teacherShortName = App.timeTable[roomIndex][getDayIndex("Monday")][nextLessonIndex]
|
||||
.getTeacherInitials();
|
||||
return teacherShortName.equals("Lunch");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int getNextLessonIndex(int currentTimeInMinutes, int roomIndex) {
|
||||
for (int i = 0; i < START_TIMES.length; i++) {
|
||||
String[] startParts = START_TIMES[i].split(":");
|
||||
int startTimeInMinutes = Integer.parseInt(startParts[0]) * 60 + Integer.parseInt(startParts[1]);
|
||||
|
||||
if (startTimeInMinutes > currentTimeInMinutes) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static boolean isBreak(int intHour, int intMinute) {
|
||||
// Check if the time is between 7 AM and 5 PM
|
||||
if (intHour >= 7 && intHour <= 17) {
|
||||
// Check if the time falls between any lesson start and end times
|
||||
for (int i = 0; i < START_TIMES.length; i++) {
|
||||
// Split the start and end times into hours and minutes
|
||||
String[] startTime = START_TIMES[i].split(":");
|
||||
String[] endTime = END_TIMES[i].split(":");
|
||||
|
||||
|
@ -97,19 +162,32 @@ public class FillTable {
|
|||
int endHour = Integer.parseInt(endTime[0]);
|
||||
int endMinute = Integer.parseInt(endTime[1]);
|
||||
|
||||
// Check if the given time is during the current lesson
|
||||
if ((intHour > startHour || (intHour == startHour && intMinute >= startMinute)) &&
|
||||
(intHour < endHour || (intHour == endHour && intMinute < endMinute))) {
|
||||
return false; // It's not a break, it's during a lesson
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true; // If no lessons match, it must be a break
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Time is outside of the school hours (7 AM to 6 PM roughly)
|
||||
return false;
|
||||
}
|
||||
|
||||
static String whatBreakIsIt(int intHour, int intMinute, int intDay) {
|
||||
return "No Break"; // If no break is found, return "No Break"
|
||||
static String whatBreakIsIt(int intHour, int intMinute) {
|
||||
String whatBreak = "";
|
||||
for (int i = 0; i < END_TIMES.length; i++) {
|
||||
String[] tempEnd = END_TIMES[i].split(":");
|
||||
String[] tempStart = START_TIMES[i].split(":");
|
||||
if (intHour >= Integer.parseInt(tempStart[0]) && intHour <= Integer.parseInt(tempEnd[0])) {
|
||||
if (intMinute >= Integer.parseInt(tempStart[1])
|
||||
&& intMinute <= Integer.parseInt(tempEnd[1])) {
|
||||
if (Integer.parseInt(tempEnd[1]) - Integer.parseInt(tempStart[1]) == 5) {
|
||||
whatBreak = "short";
|
||||
} else if (Integer.parseInt(tempEnd[1]) - Integer.parseInt(tempStart[1]) > 5) {
|
||||
whatBreak = "long";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return whatBreak;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue