This commit is contained in:
sageTheDM 2024-11-23 22:30:08 +01:00
parent 1716f0fb17
commit f7468774f7
20 changed files with 721 additions and 132 deletions

View file

@ -60,110 +60,27 @@ public class App {
// #region Calculation
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();
if (FillTable.isBreak(intHour, intMinute)) {
String whatBreak = FillTable.whatBreakIsIt(intHour, intMinute);
int[] time = FillTable.whatTime(intHour, intMinute);
switch (whatBreak) {
case "short":
calculateFiveMinuteBreakPoints(data, time, roomNumber);
break;
case "long":
calculateLongerBreakPoints(data, time, roomNumber);
break;
default:
break;
}
}
}
}
// #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
return 0;
}
// #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
return 0;
}
// #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();
return 0;
}
if (!isNextLessonLunch && isTeacherChange) {
return 5; // Bonus points for teacher switch
} else {
return 0; // No bonus points
}
private static double avarageMinuteCo2() {
// get the avrage value of a minute for the co2 value
return 0.0;
}
// #region checks

View file

@ -2,7 +2,7 @@ public class FillTable {
// #region Constants
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"
"13:35", "14:25", "15:25", "16:15", "17:05"
};
private static final String[] END_TIMES = {
@ -10,6 +10,22 @@ public class FillTable {
"14:20", "15:10", "16:10", "17:00", "17:50"
};
private static final String[] START_SMALL_BREAK = {
"8:30", "10:25", "11:15", "12:05", "13:30", "14:20", "16:10", "17:00", "17:50"
};
private static final String[] END_SMALL_BREAK = {
"8:35", "10:30", "11:20", "12:10", "13:35", "14:25", "16:15", "17:05", "17:55"
};
private static final String[] START_LONG_BREAK = {
"9:20", "15:10"
};
private static final String[] END_LONG_BREAK = {
"9:40", "15:25"
};
// #region Helper Methods
private static void fillTable(String[] teacherShortNames, String day, String[] startTime, String[] endTime,
int roomIndex) {
@ -85,6 +101,55 @@ public class FillTable {
}
// #region Check Methods
public static String whatBreak(int intHour, int intMinute) {
// Check if the time is during a lesson
for (int i = 0; i < START_TIMES.length; i++) {
String[] startParts = START_TIMES[i].split(":");
int startHour = Integer.parseInt(startParts[0]);
int startMinute = Integer.parseInt(startParts[1]);
String[] endParts = END_TIMES[i].split(":");
int endHour = Integer.parseInt(endParts[0]);
int endMinute = Integer.parseInt(endParts[1]);
if ((intHour > startHour || (intHour == startHour && intMinute >= startMinute)) &&
(intHour < endHour || (intHour == endHour && intMinute < endMinute))) {
return "no-break"; // Inside lesson time
}
}
// Check if the time is during a small break
for (int i = 0; i < START_SMALL_BREAK.length; i++) {
String[] startParts = START_SMALL_BREAK[i].split(":");
int startHour = Integer.parseInt(startParts[0]);
int startMinute = Integer.parseInt(startParts[1]);
String[] endParts = END_SMALL_BREAK[i].split(":");
int endHour = Integer.parseInt(endParts[0]);
int endMinute = Integer.parseInt(endParts[1]);
if ((intHour > startHour || (intHour == startHour && intMinute >= startMinute)) &&
(intHour < endHour || (intHour == endHour && intMinute < endMinute))) {
return "short"; // Inside small break time
}
}
// Check if the time is during a long break
for (int i = 0; i < START_LONG_BREAK.length; i++) {
String[] startParts = START_LONG_BREAK[i].split(":");
int startHour = Integer.parseInt(startParts[0]);
int startMinute = Integer.parseInt(startParts[1]);
String[] endParts = END_LONG_BREAK[i].split(":");
int endHour = Integer.parseInt(endParts[0]);
int endMinute = Integer.parseInt(endParts[1]);
if ((intHour > startHour || (intHour == startHour && intMinute >= startMinute)) &&
(intHour < endHour || (intHour == endHour && intMinute < endMinute))) {
return "long"; // Inside long break time
}
}
return "no-break"; // Default case
}
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)
@ -148,46 +213,6 @@ public class FillTable {
}
}
return -1;
}
static boolean isBreak(int intHour, int intMinute) {
if (intHour >= 7 && intHour <= 17) {
for (int i = 0; i < START_TIMES.length; i++) {
String[] startTime = START_TIMES[i].split(":");
String[] endTime = END_TIMES[i].split(":");
int startHour = Integer.parseInt(startTime[0]);
int startMinute = Integer.parseInt(startTime[1]);
int endHour = Integer.parseInt(endTime[0]);
int endMinute = Integer.parseInt(endTime[1]);
if ((intHour > startHour || (intHour == startHour && intMinute >= startMinute)) &&
(intHour < endHour || (intHour == endHour && intMinute < endMinute))) {
return false;
}
}
return true;
}
return false;
}
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;
return -1;// what was i thinking here????
}
}