Help me idk what im doing anymore
This commit is contained in:
parent
036911b58c
commit
8c68eab857
12 changed files with 148 additions and 69 deletions
|
@ -3,9 +3,8 @@ import java.util.List;
|
|||
import java.util.Scanner;
|
||||
|
||||
public class App {
|
||||
// #region Fields
|
||||
// #region Constants
|
||||
private static final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
private static final int ROOM_COUNT = 3;
|
||||
private static final int DAY_COUNT = 5;
|
||||
private static final int LESSON_COUNT = 12;
|
||||
|
@ -13,16 +12,14 @@ 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()];
|
||||
|
||||
// Get data from the last 8'000 entries seeing as that is the maximum
|
||||
private static final List<Co2Data> room39Data = Co2Data.getData(
|
||||
"https://api.thingspeak.com/channels/1521262/feeds.csv?results=8000",
|
||||
39);
|
||||
private static final List<Co2Data> room38Data = Co2Data.getData(
|
||||
"https://api.thingspeak.com/channels/1364580/feeds.csv?results=8000",
|
||||
38);
|
||||
private static final List<Co2Data> room37Data = Co2Data.getData(
|
||||
"https://api.thingspeak.com/channels/1521263/feeds.csv?results=8000",
|
||||
37);
|
||||
// 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";
|
||||
|
||||
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);
|
||||
|
||||
// #region Initialization
|
||||
private static void initializeTeachers() {
|
||||
|
@ -38,17 +35,46 @@ public class App {
|
|||
FillTable.fill39TimeTable();
|
||||
}
|
||||
|
||||
// #region Calculations
|
||||
private static void calculatePoints() {
|
||||
// Point calculation logic
|
||||
// #region Calculation
|
||||
private static void calculatePoints(List<Co2Data> data) {
|
||||
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);
|
||||
|
||||
switch (whatBreak) {
|
||||
case "short":
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int calculateFiveMinuteBreakPoints(Co2Data data) {
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
||||
private static int calculateLongerBreakPoints(Co2Data data) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
private static int calculateBonusPoints(Co2Data data) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
// #region Sorting Printing
|
||||
private static void sortTeachers() {
|
||||
Arrays.sort(teachers,
|
||||
(a, b) -> Integer.compare(b.getPoints().getTotalPoints(), a.getPoints().getTotalPoints()));
|
||||
}
|
||||
|
||||
// #region Input - Output handler
|
||||
private static void printTeachers() {
|
||||
int rank = 1;
|
||||
int previousPoints = -1;
|
||||
|
@ -72,6 +98,7 @@ public class App {
|
|||
}
|
||||
}
|
||||
|
||||
// #region User Interaction
|
||||
private static int getUserInput(String textOutput) {
|
||||
System.out.println(textOutput);
|
||||
while (true) {
|
||||
|
@ -86,8 +113,8 @@ public class App {
|
|||
|
||||
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 break.");
|
||||
System.out.println("2. Up to 10 points for long breaks, depending on window usage.");
|
||||
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.");
|
||||
}
|
||||
|
||||
|
@ -119,7 +146,7 @@ public class App {
|
|||
|
||||
// #region Main
|
||||
public static void main(String[] args) {
|
||||
boolean debbugingList = true;
|
||||
boolean debbugingList = false;
|
||||
if (debbugingList) {
|
||||
debbugingValueLists(room37Data);
|
||||
// debbugingValueLists(room38Data);
|
||||
|
@ -127,7 +154,9 @@ public class App {
|
|||
} else {
|
||||
fillInTimeTable();
|
||||
initializeTeachers();
|
||||
calculatePoints();
|
||||
calculatePoints(room37Data);
|
||||
calculatePoints(room38Data);
|
||||
calculatePoints(room39Data);
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class Co2Data {
|
||||
// #region Fields
|
||||
private Date date;
|
||||
private int co2Level;
|
||||
|
||||
|
@ -15,7 +16,7 @@ public class Co2Data {
|
|||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// #region Getters Setters
|
||||
// #region Getters and Setters
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
@ -32,30 +33,26 @@ public class Co2Data {
|
|||
this.co2Level = co2Level;
|
||||
}
|
||||
|
||||
// #region Fetching & Parsing
|
||||
// #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<>();
|
||||
|
||||
// Reference date: August 11, 2024
|
||||
Date referenceDate = new Date(11, 8, 2024, 0, 0); // Set time to 00:00 as we only care about the date
|
||||
Date referenceDate = new Date(11, 8, 2024, 0, 0); // Reference date: August 11, 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());
|
||||
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
|
||||
}
|
||||
|
||||
InputStreamReader in = new InputStreamReader(conn.getInputStream());
|
||||
BufferedReader br = new BufferedReader(in);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
br.readLine(); // Skip header line
|
||||
|
||||
String output;
|
||||
|
||||
// Skip header line
|
||||
br.readLine();
|
||||
|
||||
while ((output = br.readLine()) != null) {
|
||||
Co2Data data = parseData(output, classRoomNumber);
|
||||
if (data != null && isNewerThanReferenceDate(data.getDate(), referenceDate)) {
|
||||
|
@ -68,12 +65,12 @@ public class Co2Data {
|
|||
System.out.println("Exception in NetClientGet: " + e);
|
||||
}
|
||||
|
||||
return dataList; // Return the list of Co2Data objects
|
||||
return dataList;
|
||||
}
|
||||
|
||||
// Helper method to compare dates
|
||||
// #region Date Comparison
|
||||
// Method to compare if the data date is newer than the reference date
|
||||
private static boolean isNewerThanReferenceDate(Date dataDate, Date referenceDate) {
|
||||
// Compare year, month, and day only (ignoring the time part)
|
||||
if (dataDate.getYear() > referenceDate.getYear()) {
|
||||
return true;
|
||||
} else if (dataDate.getYear() == referenceDate.getYear()) {
|
||||
|
@ -86,20 +83,18 @@ public class Co2Data {
|
|||
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; // Handle error or log it if needed
|
||||
}
|
||||
if (fields.length < 5)
|
||||
return null;
|
||||
|
||||
try {
|
||||
// Extract date and time from created_at field
|
||||
String createdAt = fields[0];
|
||||
String[] dateTime = createdAt.split(" ");
|
||||
String[] dateTime = fields[0].split(" ");
|
||||
String[] dateParts = dateTime[0].split("-");
|
||||
String[] timeParts = dateTime[1].split(":");
|
||||
|
||||
// Create a Date object
|
||||
int year = Integer.parseInt(dateParts[0]);
|
||||
int month = Integer.parseInt(dateParts[1]);
|
||||
int day = Integer.parseInt(dateParts[2]);
|
||||
|
@ -107,19 +102,18 @@ public class Co2Data {
|
|||
int minute = Integer.parseInt(timeParts[1]);
|
||||
Date date = new Date(day, month, year, hour, minute);
|
||||
|
||||
// Parse CO2 level (field1)
|
||||
int co2Level = Integer.parseInt(fields[2]);
|
||||
|
||||
return new Co2Data(date, co2Level);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error parsing data: " + e);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// #region toString Override
|
||||
// #region ToString Method
|
||||
// Method to return a string representation of the CO2 data
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.date.toString() + "\n" + this.co2Level;
|
||||
return "Date: " + date + ", CO2 Level: " + co2Level;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,4 +83,66 @@ public class FillTable {
|
|||
"Friday", START_TIMES, END_TIMES, roomIndex);
|
||||
}
|
||||
|
||||
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(":");
|
||||
|
||||
int startHour = Integer.parseInt(startTime[0]);
|
||||
int startMinute = Integer.parseInt(startTime[1]);
|
||||
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 true; // If no lessons match, it must be a break
|
||||
}
|
||||
|
||||
return false; // Time is outside of the school hours (7 AM to 6 PM roughly)
|
||||
}
|
||||
|
||||
static String whatBreakIsIt(int intHour, int intMinute) {
|
||||
// Iterate through the timetable for all rooms and days
|
||||
for (int roomIndex = 0; roomIndex < App.timeTable.length; roomIndex++) {
|
||||
for (int dayIndex = 0; dayIndex < App.timeTable[roomIndex].length; dayIndex++) {
|
||||
for (int lessonIndex = 0; lessonIndex < App.timeTable[roomIndex][dayIndex].length; lessonIndex++) {
|
||||
Lesson lesson = App.timeTable[roomIndex][dayIndex][lessonIndex];
|
||||
if (lesson != null) {
|
||||
// Check if this lesson is labeled as "Lunch"
|
||||
if (lesson.getStartTime().equals("Lunch")
|
||||
|| lesson.getEndTime().equals("Lunch")) {
|
||||
return "Lunch"; // It's lunch time
|
||||
}
|
||||
// Check if the time is between any lessons (a short break)
|
||||
String[] startTime = lesson.getStartTime().split(":");
|
||||
String[] endTime = lesson.getEndTime().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]);
|
||||
|
||||
// Check if the given time is during the current lesson
|
||||
if ((intHour > startHour
|
||||
|| (intHour == startHour && intMinute >= startMinute)) &&
|
||||
(intHour < endHour || (intHour == endHour
|
||||
&& intMinute < endMinute))) {
|
||||
return "Short"; // It is a short break (between lessons)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "No Break"; // If no break is found, return "No Break"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,26 @@
|
|||
public class Lesson {
|
||||
// #region Fields
|
||||
private int roomNumberNumber;
|
||||
private int roomNumber;
|
||||
private String teacherInitials;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private String weekweekDay;
|
||||
private String weekDay;
|
||||
|
||||
// #region Constructor
|
||||
// Constructor to initialize all fields
|
||||
public Lesson(int roomNumber, String teacherInitials, String startTime, String endTime, String weekweekDay) {
|
||||
this.roomNumberNumber = roomNumber;
|
||||
public Lesson(int roomNumber, String teacherInitials, String startTime, String endTime, String weekDay) {
|
||||
this.roomNumber = roomNumber;
|
||||
this.teacherInitials = teacherInitials;
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
this.weekweekDay = weekweekDay;
|
||||
this.weekDay = weekDay;
|
||||
}
|
||||
|
||||
// #region Getters
|
||||
public int getroomNumber() {
|
||||
return roomNumberNumber;
|
||||
public int getRoomNumber() {
|
||||
return roomNumber;
|
||||
}
|
||||
|
||||
public String getteacherInitials() {
|
||||
public String getTeacherInitials() {
|
||||
return teacherInitials;
|
||||
}
|
||||
|
||||
|
@ -33,8 +32,7 @@ public class Lesson {
|
|||
return endTime;
|
||||
}
|
||||
|
||||
public String getweekDay() {
|
||||
return weekweekDay;
|
||||
public String getWeekDay() {
|
||||
return weekDay;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
// Points class for managing point categories
|
||||
public class Points {
|
||||
// #region Fields
|
||||
private int fiveMinuteBreak;
|
||||
private int longerBreak;
|
||||
private int bonusPoints;
|
||||
|
@ -31,9 +29,7 @@ public class Points {
|
|||
}
|
||||
|
||||
// #region Calculation
|
||||
// Method to calculate total points
|
||||
public int getTotalPoints() {
|
||||
return fiveMinuteBreak + longerBreak + bonusPoints;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ public class Teacher {
|
|||
|
||||
// #region Initialization
|
||||
static {
|
||||
// Mapping short names to full teacher names
|
||||
nameMap.put("Hm", "Hummel");
|
||||
nameMap.put("Bd", "Bender");
|
||||
nameMap.put("Bu", "Burger");
|
||||
|
@ -32,20 +33,19 @@ public class Teacher {
|
|||
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();
|
||||
this.points = new Points(); // Initialize a new Points object
|
||||
}
|
||||
|
||||
// #region Getters
|
||||
public String getName() {
|
||||
return name;
|
||||
return name; // Return the teacher's full name
|
||||
}
|
||||
|
||||
public Points getPoints() {
|
||||
return points;
|
||||
return points; // Return the Points object associated with this teacher
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue