tetst
This commit is contained in:
parent
1716f0fb17
commit
f7468774f7
20 changed files with 721 additions and 132 deletions
Binary file not shown.
Binary file not shown.
|
@ -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();
|
||||
|
||||
if (!isNextLessonLunch && isTeacherChange) {
|
||||
return 5; // Bonus points for teacher switch
|
||||
} else {
|
||||
return 0; // No bonus points
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static double avarageMinuteCo2() {
|
||||
// get the avrage value of a minute for the co2 value
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// #region checks
|
||||
|
|
|
@ -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????
|
||||
}
|
||||
}
|
||||
|
|
7
Code/Steiner/CO2-Daten-Projekt-V3/.vscode/settings.json
vendored
Normal file
7
Code/Steiner/CO2-Daten-Projekt-V3/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
18
Code/Steiner/CO2-Daten-Projekt-V3/README.md
Normal file
18
Code/Steiner/CO2-Daten-Projekt-V3/README.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Getting Started
|
||||
|
||||
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||
|
||||
## Folder Structure
|
||||
|
||||
The workspace contains two folders by default, where:
|
||||
|
||||
- `src`: the folder to maintain sources
|
||||
- `lib`: the folder to maintain dependencies
|
||||
|
||||
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||
|
||||
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||
|
||||
## Dependency Management
|
||||
|
||||
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/App.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/App.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Break.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Break.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Co2Data.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Co2Data.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Date.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Date.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Points.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Points.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Teacher.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Teacher.class
Normal file
Binary file not shown.
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Time.class
Normal file
BIN
Code/Steiner/CO2-Daten-Projekt-V3/bin/Time.class
Normal file
Binary file not shown.
191
Code/Steiner/CO2-Daten-Projekt-V3/src/App.java
Normal file
191
Code/Steiner/CO2-Daten-Projekt-V3/src/App.java
Normal file
|
@ -0,0 +1,191 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class App {
|
||||
// #region app constants
|
||||
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
||||
// Date and time 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 int START_HOUR = 0;
|
||||
private static final int START_MINUTE = 0;
|
||||
|
||||
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 int END_HOUR = 23;
|
||||
private static final int END_MINUTE = 59;
|
||||
|
||||
// Formatting the start and end date with time
|
||||
private static final String START_DATE = String.format("%d-%02d-%02d%%20%02d:%02d:00",
|
||||
START_YEAR, START_MONTH, START_DAY, START_HOUR, START_MINUTE);
|
||||
private static final String END_DATE = String.format("%d-%02d-%02d%%20%02d:%02d:00",
|
||||
END_YEAR, END_MONTH, END_DAY, END_HOUR, END_MINUTE);
|
||||
|
||||
// #region Initialization
|
||||
private static String createUrl(int ROOM_X_NUMBER) {
|
||||
return String.format("https://api.thingspeak.com/channels/%d/feeds.csv?start=%s&end=%s",
|
||||
ROOM_X_NUMBER, START_DATE, END_DATE);
|
||||
}
|
||||
// #endregion
|
||||
|
||||
private static void getDataForBreak() {
|
||||
// Co2Data[Wochentag][Room 37, 38 or 39]
|
||||
Co2Data[][][] data = new Co2Data[5][3][11];
|
||||
|
||||
// Placeholder logic: Retrieve data for CO2 during breaks
|
||||
// This should be replaced with the actual logic to get the data from ThingSpeak
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for (int k = 0; k < 11; k++) {
|
||||
data[i][j][k] = new Co2Data(null, k); // Placeholder CO2 data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double getDataAverageForMinute(String time) {
|
||||
// Placeholder logic to calculate average CO2 levels
|
||||
return 400.0; // Example CO2 average level
|
||||
}
|
||||
|
||||
private static void initializeTeachers() {
|
||||
int index = 0;
|
||||
for (String initial : Teacher.nameMap.keySet()) {
|
||||
Teacher teacher = new Teacher(initial);
|
||||
Points points = new Points(); // Initialize Points object for each teacher
|
||||
teacher.setPoints(points.getLongerBreak(), points.getBonusPoints(), points.getFiveMinuteBreak());
|
||||
teachers[index++] = teacher;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
// #region User Interaction
|
||||
private static int getUserInput(String textOutput) {
|
||||
System.out.println(textOutput);
|
||||
while (true) {
|
||||
if (scanner.hasNextInt()) {
|
||||
return scanner.nextInt();
|
||||
}
|
||||
scanner.next(); // Clear invalid input
|
||||
}
|
||||
}
|
||||
|
||||
// #region Explanation
|
||||
private static void printExplanation() {
|
||||
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 classrooms.");
|
||||
System.out.println("4. Deduct points if CO2 levels are too high.");
|
||||
}
|
||||
|
||||
// #region shutdown
|
||||
private static void printShutDown() {
|
||||
System.out.println("Shutting down...");
|
||||
for (int i = 3; i > 0; i--) {
|
||||
System.out.print(i + "...");
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #TODO: remove this before hand-in deadline
|
||||
public static void debbugingValueLists(List<Co2Data> data) {
|
||||
// Debugging co2Data
|
||||
int index = 0;
|
||||
for (Co2Data a : data) {
|
||||
System.out.println(a.toString());
|
||||
index++;
|
||||
}
|
||||
|
||||
System.out.println("-----------------");
|
||||
System.out.println(index);
|
||||
}
|
||||
|
||||
// #TODO
|
||||
// #region Print & sort
|
||||
private static void sortTeachers() {
|
||||
// Sorting teachers by total points (implement sorting logic based on points)
|
||||
Arrays.sort(teachers,
|
||||
(a, b) -> Integer.compare(b.getPoints().getTotalPoints(), a.getPoints().getTotalPoints()));
|
||||
}
|
||||
|
||||
private static void printTeachers() {
|
||||
int rank = 1;
|
||||
int previousPoints = -1;
|
||||
int currentRank = 1;
|
||||
|
||||
for (int i = 0; i < teachers.length; i++) {
|
||||
Teacher teacher = teachers[i];
|
||||
int teacherPoints = teacher.getPoints().getTotalPoints(); // Assuming points are available in getPoints()
|
||||
|
||||
if (teacherPoints == previousPoints) {
|
||||
System.out.println(currentRank + ". " + teacher.getName() + " " + teacherPoints);
|
||||
} else {
|
||||
if (i > 0) {
|
||||
rank += (i - (currentRank - 1));
|
||||
}
|
||||
currentRank = rank;
|
||||
System.out.println(rank + ". " + teacher.getName() + " " + teacherPoints);
|
||||
}
|
||||
|
||||
previousPoints = teacherPoints;
|
||||
}
|
||||
}
|
||||
|
||||
// #region Main
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Calculations in process please do not shut off...");
|
||||
initializeTeachers();
|
||||
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
while (true) {
|
||||
int userInput = getUserInput(
|
||||
"Do you want to see how the points were calculated? (Yes 1, No 0; anything is an error)");
|
||||
|
||||
if (userInput == 1) {
|
||||
printExplanation();
|
||||
printShutDown();
|
||||
break;
|
||||
} else if (userInput == 0) {
|
||||
printShutDown();
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Invalid input. Please enter 1 for Yes or 0 for No.");
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
}
|
||||
}
|
45
Code/Steiner/CO2-Daten-Projekt-V3/src/Break.java
Normal file
45
Code/Steiner/CO2-Daten-Projekt-V3/src/Break.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
public class Break {
|
||||
private Time start;
|
||||
private Time end;
|
||||
private Teacher teacher;
|
||||
private int room;
|
||||
|
||||
public Break(Time start, Time end, Teacher teacher, int room) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.teacher = teacher;
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
public Time getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Time start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public Time getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(Time end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public Teacher getTeacher() {
|
||||
return teacher;
|
||||
}
|
||||
|
||||
public void setTeacher(Teacher teacher) {
|
||||
this.teacher = teacher;
|
||||
}
|
||||
|
||||
public int getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public void setRoom(int room) {
|
||||
this.room = room;
|
||||
}
|
||||
}
|
119
Code/Steiner/CO2-Daten-Projekt-V3/src/Co2Data.java
Normal file
119
Code/Steiner/CO2-Daten-Projekt-V3/src/Co2Data.java
Normal file
|
@ -0,0 +1,119 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Co2Data {
|
||||
// #region Fields
|
||||
private Date date;
|
||||
private int co2Level;
|
||||
|
||||
// #region Constructor
|
||||
public Co2Data(Date date, int co2Level) {
|
||||
this.date = date;
|
||||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// #region Getters and Setters
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getCo2Level() {
|
||||
return co2Level;
|
||||
}
|
||||
|
||||
public void setCo2Level(int co2Level) {
|
||||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// #region Data Fetching
|
||||
// Method to fetch and parse CO2 data from a URL
|
||||
public static List<Co2Data> getData(String csvURL, int classRoomNumber) {
|
||||
List<Co2Data> dataList = new ArrayList<>();
|
||||
Date referenceDate = new Date(8, 11, 2024, 0, 0); // Reference date: November 8, 2024
|
||||
|
||||
try {
|
||||
URL url = new URL(csvURL);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setRequestProperty("Accept", "application/csv");
|
||||
|
||||
if (conn.getResponseCode() != 200) {
|
||||
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
br.readLine(); // Skip header line
|
||||
|
||||
String output;
|
||||
while ((output = br.readLine()) != null) {
|
||||
Co2Data data = parseData(output, classRoomNumber);
|
||||
if (data != null && isNewerThanReferenceDate(data.getDate(), referenceDate)) {
|
||||
dataList.add(data);
|
||||
}
|
||||
}
|
||||
conn.disconnect();
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception in NetClientGet: " + e);
|
||||
}
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
||||
// #region Date Comparison
|
||||
// Method to compare if the data date is newer than the reference date
|
||||
private static boolean isNewerThanReferenceDate(Date dataDate, Date referenceDate) {
|
||||
if (dataDate.getYear() > referenceDate.getYear()) {
|
||||
return true;
|
||||
} else if (dataDate.getYear() == referenceDate.getYear()) {
|
||||
if (dataDate.getMonth() > referenceDate.getMonth()) {
|
||||
return true;
|
||||
} else if (dataDate.getMonth() == referenceDate.getMonth()) {
|
||||
return dataDate.getDay() > referenceDate.getDay();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// #region Data Parsing
|
||||
// Method to parse CO2 data from a CSV line
|
||||
private static Co2Data parseData(String csvLine, int classRoomNumber) {
|
||||
String[] fields = csvLine.split(",");
|
||||
if (fields.length < 5)
|
||||
return null;
|
||||
|
||||
try {
|
||||
String[] dateTime = fields[0].split(" ");
|
||||
String[] dateParts = dateTime[0].split("-");
|
||||
String[] timeParts = dateTime[1].split(":");
|
||||
|
||||
int year = Integer.parseInt(dateParts[0]);
|
||||
int month = Integer.parseInt(dateParts[1]);
|
||||
int day = Integer.parseInt(dateParts[2]);
|
||||
int hour = Integer.parseInt(timeParts[0]);
|
||||
int minute = Integer.parseInt(timeParts[1]);
|
||||
Date date = new Date(day, month, year, hour, minute);
|
||||
|
||||
int co2Level = Integer.parseInt(fields[2]);
|
||||
|
||||
return new Co2Data(date, co2Level);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #region ToString Method
|
||||
// Method to return a string representation of the CO2 data
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Date: " + date + ", CO2 Level: " + co2Level;
|
||||
}
|
||||
}
|
77
Code/Steiner/CO2-Daten-Projekt-V3/src/Date.java
Normal file
77
Code/Steiner/CO2-Daten-Projekt-V3/src/Date.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
public class Date {
|
||||
// #region Fields
|
||||
private int day;
|
||||
private int month;
|
||||
private int year;
|
||||
private int hour;
|
||||
private int minute;
|
||||
|
||||
// #region Constructor
|
||||
public Date(int day, int month, int year, int hour, int minute) {
|
||||
this.day = day;
|
||||
this.month = month;
|
||||
this.year = year;
|
||||
this.hour = hour;
|
||||
this.minute = minute;
|
||||
|
||||
// Automatically adjust for Switzerland time after initialization
|
||||
adjustForSwitzerlandTime();
|
||||
}
|
||||
|
||||
// #region Getters
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
// #region Adjust UTC to Switzerland Time
|
||||
private void adjustForSwitzerlandTime() {
|
||||
hour += 1;
|
||||
|
||||
// Adjust if the hour exceeds 24 or falls below 0
|
||||
if (hour >= 24) {
|
||||
hour -= 24;
|
||||
day++;
|
||||
if (day > 31) { // Simple month/day rollover, could be more sophisticated
|
||||
day = 1;
|
||||
month++;
|
||||
if (month > 12) {
|
||||
month = 1;
|
||||
year++;
|
||||
}
|
||||
}
|
||||
} else if (hour < 0) {
|
||||
hour += 24;
|
||||
day--;
|
||||
if (day < 1) {
|
||||
month--;
|
||||
if (month < 1) {
|
||||
month = 12;
|
||||
year--;
|
||||
}
|
||||
day = 31; // Simple month/day rollover, could be more sophisticated
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #region toString Override
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%04d-%02d-%02d %02d:%02d", year, month, day, hour, minute);
|
||||
}
|
||||
}
|
82
Code/Steiner/CO2-Daten-Projekt-V3/src/Points.java
Normal file
82
Code/Steiner/CO2-Daten-Projekt-V3/src/Points.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
public class Points {
|
||||
// #region Fields
|
||||
private int fiveMinuteBreak;
|
||||
private int longerBreak;
|
||||
private int bonusPoints;
|
||||
|
||||
// #region Constructor
|
||||
public Points() {
|
||||
this.fiveMinuteBreak = 0; // Default initialization
|
||||
this.longerBreak = 0; // Default initialization
|
||||
this.bonusPoints = 0; // Default initialization
|
||||
}
|
||||
|
||||
public Points(int fiveMinuteBreak, int longerBreak, int bonusPoints) {
|
||||
this.fiveMinuteBreak = fiveMinuteBreak >= 0 ? fiveMinuteBreak : 0; // Validate
|
||||
this.longerBreak = longerBreak >= 0 ? longerBreak : 0; // Validate
|
||||
this.bonusPoints = bonusPoints >= 0 ? bonusPoints : 0; // Validate
|
||||
}
|
||||
|
||||
// Copy constructor to duplicate an existing Points object
|
||||
public Points(Points points) {
|
||||
this.fiveMinuteBreak = points.fiveMinuteBreak;
|
||||
this.longerBreak = points.longerBreak;
|
||||
this.bonusPoints = points.bonusPoints;
|
||||
}
|
||||
|
||||
// #region Getters and Setters
|
||||
public int getFiveMinuteBreak() {
|
||||
return fiveMinuteBreak;
|
||||
}
|
||||
|
||||
public void setFiveMinuteBreak(int fiveMinuteBreak) {
|
||||
this.fiveMinuteBreak = Math.max(fiveMinuteBreak, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
public int getLongerBreak() {
|
||||
return longerBreak;
|
||||
}
|
||||
|
||||
public void setLongerBreak(int longerBreak) {
|
||||
this.longerBreak = Math.max(longerBreak, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
public int getBonusPoints() {
|
||||
return bonusPoints;
|
||||
}
|
||||
|
||||
public void setBonusPoints(int bonusPoints) {
|
||||
this.bonusPoints = Math.max(bonusPoints, 0); // Ensure no negative points
|
||||
}
|
||||
|
||||
// #region Points Adjustment Methods
|
||||
public void addFiveMinuteBreakPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.fiveMinuteBreak += points;
|
||||
}
|
||||
}
|
||||
|
||||
public void addLongerBreakPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.longerBreak += points;
|
||||
}
|
||||
}
|
||||
|
||||
public void addBonusPoints(int points) {
|
||||
if (points > 0) {
|
||||
this.bonusPoints += points;
|
||||
}
|
||||
}
|
||||
|
||||
// #region Total Points Calculation
|
||||
public int getTotalPoints() {
|
||||
return fiveMinuteBreak + longerBreak + bonusPoints;
|
||||
}
|
||||
|
||||
// #region String Representation (Optional for debugging or output)
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Five Minute Break: %d, Longer Break: %d, Bonus Points: %d, Total: %d",
|
||||
fiveMinuteBreak, longerBreak, bonusPoints, getTotalPoints());
|
||||
}
|
||||
}
|
79
Code/Steiner/CO2-Daten-Projekt-V3/src/Teacher.java
Normal file
79
Code/Steiner/CO2-Daten-Projekt-V3/src/Teacher.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Teacher {
|
||||
// #region Fields
|
||||
private String name;
|
||||
private Map<String, String[]> timetable = new HashMap<>(); // Map of Day -> Teachers in class for that day
|
||||
private Points points; // Points field to store teacher's points
|
||||
|
||||
public static final Map<String, String> nameMap = new HashMap<>();
|
||||
|
||||
// #region Initialization
|
||||
static {
|
||||
// Mapping short names to full teacher names
|
||||
nameMap.put("Hm", "Hummel");
|
||||
nameMap.put("Bd", "Bender");
|
||||
nameMap.put("Bu", "Burger");
|
||||
nameMap.put("Cg", "Chung");
|
||||
nameMap.put("Do", "Doe");
|
||||
nameMap.put("Eh", "Ehrlich");
|
||||
nameMap.put("Fh", "Fischer");
|
||||
nameMap.put("Gi", "Giordano");
|
||||
nameMap.put("Gr", "Graham");
|
||||
nameMap.put("Hi", "Higgins");
|
||||
nameMap.put("Kg", "Kang");
|
||||
nameMap.put("Kh", "Khan");
|
||||
nameMap.put("Lz", "Lozano");
|
||||
nameMap.put("Lu", "Lund");
|
||||
nameMap.put("Or", "Ortega");
|
||||
nameMap.put("Re", "Reyes");
|
||||
nameMap.put("Se", "Seng");
|
||||
nameMap.put("Ts", "Tanaka");
|
||||
nameMap.put("Vt", "Vetter");
|
||||
nameMap.put("Zu", "Zuniga");
|
||||
}
|
||||
|
||||
// #region Constructor
|
||||
public Teacher(String name) {
|
||||
// Use the short name to find the full name from the nameMap
|
||||
this.name = nameMap.getOrDefault(name, "Unknown");
|
||||
this.points = new Points(); // Initialize Points object when Teacher is created
|
||||
}
|
||||
|
||||
// #region Timetable Methods
|
||||
public void setTimetable(String day, String[] classes) {
|
||||
if (day == null || classes == null || classes.length == 0) {
|
||||
throw new IllegalArgumentException("Day and classes cannot be null or empty.");
|
||||
}
|
||||
timetable.put(day, classes);
|
||||
}
|
||||
|
||||
public String[] getTimetableForDay(String day) {
|
||||
return timetable.getOrDefault(day, new String[0]);
|
||||
}
|
||||
|
||||
// #region Getters and Setters
|
||||
public String getName() {
|
||||
return name; // Return the teacher's full name
|
||||
}
|
||||
|
||||
public Map<String, String[]> getTimetable() {
|
||||
return Collections.unmodifiableMap(timetable); // Return an unmodifiable view of the timetable
|
||||
}
|
||||
|
||||
public Points getPoints() {
|
||||
return points; // Return the Points object associated with the teacher
|
||||
}
|
||||
|
||||
public void setPoints(int fiveMinute, int tenMinutes, int bonusPoints) {
|
||||
this.points.setFiveMinuteBreak(fiveMinute);
|
||||
this.points.setLongerBreak(tenMinutes);
|
||||
this.points.setBonusPoints(bonusPoints);
|
||||
}
|
||||
|
||||
public int getTotalPoints() {
|
||||
return this.points.getTotalPoints();
|
||||
}
|
||||
}
|
29
Code/Steiner/CO2-Daten-Projekt-V3/src/Time.java
Normal file
29
Code/Steiner/CO2-Daten-Projekt-V3/src/Time.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
public class Time {
|
||||
private int hour;
|
||||
private int minute;
|
||||
|
||||
public Time(int hour, int minute) {
|
||||
if (hour >= 1 && hour <= 24 && minute >= 1 && minute <= 60) {
|
||||
this.hour = hour;
|
||||
this.minute = minute;
|
||||
} else {
|
||||
System.out.println("Failed to initialize the hour");
|
||||
}
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public void setHour(int hour) {
|
||||
this.hour = hour;
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
return minute;
|
||||
}
|
||||
|
||||
public void setMinute(int minute) {
|
||||
this.minute = minute;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue