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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,9 +3,8 @@ import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
// #region Fields
|
// #region Constants
|
||||||
private static final Scanner scanner = new Scanner(System.in);
|
private static final Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
private static final int ROOM_COUNT = 3;
|
private static final int ROOM_COUNT = 3;
|
||||||
private static final int DAY_COUNT = 5;
|
private static final int DAY_COUNT = 5;
|
||||||
private static final int LESSON_COUNT = 12;
|
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];
|
public static final Lesson[][][] timeTable = new Lesson[ROOM_COUNT][DAY_COUNT][LESSON_COUNT];
|
||||||
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
||||||
|
|
||||||
// Get data from the last 8'000 entries seeing as that is the maximum
|
// URLs for fetching CO2 data
|
||||||
private static final List<Co2Data> room39Data = Co2Data.getData(
|
private static final String ROOM_39_URL = "https://api.thingspeak.com/channels/1521262/feeds.csv?results=8000";
|
||||||
"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";
|
||||||
39);
|
private static final String ROOM_37_URL = "https://api.thingspeak.com/channels/1521263/feeds.csv?results=8000";
|
||||||
private static final List<Co2Data> room38Data = Co2Data.getData(
|
|
||||||
"https://api.thingspeak.com/channels/1364580/feeds.csv?results=8000",
|
private static final List<Co2Data> room39Data = Co2Data.getData(ROOM_39_URL, 39);
|
||||||
38);
|
private static final List<Co2Data> room38Data = Co2Data.getData(ROOM_38_URL, 38);
|
||||||
private static final List<Co2Data> room37Data = Co2Data.getData(
|
private static final List<Co2Data> room37Data = Co2Data.getData(ROOM_37_URL, 37);
|
||||||
"https://api.thingspeak.com/channels/1521263/feeds.csv?results=8000",
|
|
||||||
37);
|
|
||||||
|
|
||||||
// #region Initialization
|
// #region Initialization
|
||||||
private static void initializeTeachers() {
|
private static void initializeTeachers() {
|
||||||
|
@ -38,17 +35,46 @@ public class App {
|
||||||
FillTable.fill39TimeTable();
|
FillTable.fill39TimeTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Calculations
|
// #region Calculation
|
||||||
private static void calculatePoints() {
|
private static void calculatePoints(List<Co2Data> data) {
|
||||||
// Point calculation logic
|
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() {
|
private static void sortTeachers() {
|
||||||
Arrays.sort(teachers,
|
Arrays.sort(teachers,
|
||||||
(a, b) -> Integer.compare(b.getPoints().getTotalPoints(), a.getPoints().getTotalPoints()));
|
(a, b) -> Integer.compare(b.getPoints().getTotalPoints(), a.getPoints().getTotalPoints()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Input - Output handler
|
|
||||||
private static void printTeachers() {
|
private static void printTeachers() {
|
||||||
int rank = 1;
|
int rank = 1;
|
||||||
int previousPoints = -1;
|
int previousPoints = -1;
|
||||||
|
@ -72,6 +98,7 @@ public class App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #region User Interaction
|
||||||
private static int getUserInput(String textOutput) {
|
private static int getUserInput(String textOutput) {
|
||||||
System.out.println(textOutput);
|
System.out.println(textOutput);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -86,8 +113,8 @@ public class App {
|
||||||
|
|
||||||
private static void printExplanation() {
|
private static void printExplanation() {
|
||||||
System.out.println("Point calculation explanation:");
|
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("1. Up to 5 points for keeping the window open during a small pause.");
|
||||||
System.out.println("2. Up to 10 points for long breaks, depending on window usage.");
|
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 the room.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +146,7 @@ public class App {
|
||||||
|
|
||||||
// #region Main
|
// #region Main
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
boolean debbugingList = true;
|
boolean debbugingList = false;
|
||||||
if (debbugingList) {
|
if (debbugingList) {
|
||||||
debbugingValueLists(room37Data);
|
debbugingValueLists(room37Data);
|
||||||
// debbugingValueLists(room38Data);
|
// debbugingValueLists(room38Data);
|
||||||
|
@ -127,7 +154,9 @@ public class App {
|
||||||
} else {
|
} else {
|
||||||
fillInTimeTable();
|
fillInTimeTable();
|
||||||
initializeTeachers();
|
initializeTeachers();
|
||||||
calculatePoints();
|
calculatePoints(room37Data);
|
||||||
|
calculatePoints(room38Data);
|
||||||
|
calculatePoints(room39Data);
|
||||||
sortTeachers();
|
sortTeachers();
|
||||||
printTeachers();
|
printTeachers();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Co2Data {
|
public class Co2Data {
|
||||||
|
// #region Fields
|
||||||
private Date date;
|
private Date date;
|
||||||
private int co2Level;
|
private int co2Level;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ public class Co2Data {
|
||||||
this.co2Level = co2Level;
|
this.co2Level = co2Level;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Getters Setters
|
// #region Getters and Setters
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
@ -32,30 +33,26 @@ public class Co2Data {
|
||||||
this.co2Level = co2Level;
|
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) {
|
public static List<Co2Data> getData(String csvURL, int classRoomNumber) {
|
||||||
List<Co2Data> dataList = new ArrayList<>();
|
List<Co2Data> dataList = new ArrayList<>();
|
||||||
|
Date referenceDate = new Date(11, 8, 2024, 0, 0); // Reference date: August 11, 2024
|
||||||
// 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
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(csvURL);
|
URL url = new URL(csvURL);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
conn.setRequestMethod("GET");
|
conn.setRequestMethod("GET");
|
||||||
conn.setRequestProperty("Accept", "application/csv");
|
conn.setRequestProperty("Accept", "application/csv");
|
||||||
|
|
||||||
if (conn.getResponseCode() != 200) {
|
if (conn.getResponseCode() != 200) {
|
||||||
throw new RuntimeException("Failed : HTTP Error code : "
|
throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
|
||||||
+ conn.getResponseCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStreamReader in = new InputStreamReader(conn.getInputStream());
|
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
BufferedReader br = new BufferedReader(in);
|
br.readLine(); // Skip header line
|
||||||
|
|
||||||
String output;
|
String output;
|
||||||
|
|
||||||
// Skip header line
|
|
||||||
br.readLine();
|
|
||||||
|
|
||||||
while ((output = br.readLine()) != null) {
|
while ((output = br.readLine()) != null) {
|
||||||
Co2Data data = parseData(output, classRoomNumber);
|
Co2Data data = parseData(output, classRoomNumber);
|
||||||
if (data != null && isNewerThanReferenceDate(data.getDate(), referenceDate)) {
|
if (data != null && isNewerThanReferenceDate(data.getDate(), referenceDate)) {
|
||||||
|
@ -68,12 +65,12 @@ public class Co2Data {
|
||||||
System.out.println("Exception in NetClientGet: " + e);
|
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) {
|
private static boolean isNewerThanReferenceDate(Date dataDate, Date referenceDate) {
|
||||||
// Compare year, month, and day only (ignoring the time part)
|
|
||||||
if (dataDate.getYear() > referenceDate.getYear()) {
|
if (dataDate.getYear() > referenceDate.getYear()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (dataDate.getYear() == referenceDate.getYear()) {
|
} else if (dataDate.getYear() == referenceDate.getYear()) {
|
||||||
|
@ -86,20 +83,18 @@ public class Co2Data {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #region Data Parsing
|
||||||
|
// Method to parse CO2 data from a CSV line
|
||||||
private static Co2Data parseData(String csvLine, int classRoomNumber) {
|
private static Co2Data parseData(String csvLine, int classRoomNumber) {
|
||||||
String[] fields = csvLine.split(",");
|
String[] fields = csvLine.split(",");
|
||||||
if (fields.length < 5) {
|
if (fields.length < 5)
|
||||||
return null; // Handle error or log it if needed
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Extract date and time from created_at field
|
String[] dateTime = fields[0].split(" ");
|
||||||
String createdAt = fields[0];
|
|
||||||
String[] dateTime = createdAt.split(" ");
|
|
||||||
String[] dateParts = dateTime[0].split("-");
|
String[] dateParts = dateTime[0].split("-");
|
||||||
String[] timeParts = dateTime[1].split(":");
|
String[] timeParts = dateTime[1].split(":");
|
||||||
|
|
||||||
// Create a Date object
|
|
||||||
int year = Integer.parseInt(dateParts[0]);
|
int year = Integer.parseInt(dateParts[0]);
|
||||||
int month = Integer.parseInt(dateParts[1]);
|
int month = Integer.parseInt(dateParts[1]);
|
||||||
int day = Integer.parseInt(dateParts[2]);
|
int day = Integer.parseInt(dateParts[2]);
|
||||||
|
@ -107,19 +102,18 @@ public class Co2Data {
|
||||||
int minute = Integer.parseInt(timeParts[1]);
|
int minute = Integer.parseInt(timeParts[1]);
|
||||||
Date date = new Date(day, month, year, hour, minute);
|
Date date = new Date(day, month, year, hour, minute);
|
||||||
|
|
||||||
// Parse CO2 level (field1)
|
|
||||||
int co2Level = Integer.parseInt(fields[2]);
|
int co2Level = Integer.parseInt(fields[2]);
|
||||||
|
|
||||||
return new Co2Data(date, co2Level);
|
return new Co2Data(date, co2Level);
|
||||||
} catch (Exception e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Error parsing data: " + e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region toString Override
|
// #region ToString Method
|
||||||
|
// Method to return a string representation of the CO2 data
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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);
|
"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 {
|
public class Lesson {
|
||||||
// #region Fields
|
// #region Fields
|
||||||
private int roomNumberNumber;
|
private int roomNumber;
|
||||||
private String teacherInitials;
|
private String teacherInitials;
|
||||||
private String startTime;
|
private String startTime;
|
||||||
private String endTime;
|
private String endTime;
|
||||||
private String weekweekDay;
|
private String weekDay;
|
||||||
|
|
||||||
// #region Constructor
|
// #region Constructor
|
||||||
// Constructor to initialize all fields
|
public Lesson(int roomNumber, String teacherInitials, String startTime, String endTime, String weekDay) {
|
||||||
public Lesson(int roomNumber, String teacherInitials, String startTime, String endTime, String weekweekDay) {
|
this.roomNumber = roomNumber;
|
||||||
this.roomNumberNumber = roomNumber;
|
|
||||||
this.teacherInitials = teacherInitials;
|
this.teacherInitials = teacherInitials;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
this.weekweekDay = weekweekDay;
|
this.weekDay = weekDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Getters
|
// #region Getters
|
||||||
public int getroomNumber() {
|
public int getRoomNumber() {
|
||||||
return roomNumberNumber;
|
return roomNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getteacherInitials() {
|
public String getTeacherInitials() {
|
||||||
return teacherInitials;
|
return teacherInitials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +32,7 @@ public class Lesson {
|
||||||
return endTime;
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getweekDay() {
|
public String getWeekDay() {
|
||||||
return weekweekDay;
|
return weekDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
// Points class for managing point categories
|
|
||||||
public class Points {
|
public class Points {
|
||||||
// #region Fields
|
|
||||||
private int fiveMinuteBreak;
|
private int fiveMinuteBreak;
|
||||||
private int longerBreak;
|
private int longerBreak;
|
||||||
private int bonusPoints;
|
private int bonusPoints;
|
||||||
|
@ -31,9 +29,7 @@ public class Points {
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Calculation
|
// #region Calculation
|
||||||
// Method to calculate total points
|
|
||||||
public int getTotalPoints() {
|
public int getTotalPoints() {
|
||||||
return fiveMinuteBreak + longerBreak + bonusPoints;
|
return fiveMinuteBreak + longerBreak + bonusPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ public class Teacher {
|
||||||
|
|
||||||
// #region Initialization
|
// #region Initialization
|
||||||
static {
|
static {
|
||||||
|
// Mapping short names to full teacher names
|
||||||
nameMap.put("Hm", "Hummel");
|
nameMap.put("Hm", "Hummel");
|
||||||
nameMap.put("Bd", "Bender");
|
nameMap.put("Bd", "Bender");
|
||||||
nameMap.put("Bu", "Burger");
|
nameMap.put("Bu", "Burger");
|
||||||
|
@ -32,20 +33,19 @@ public class Teacher {
|
||||||
nameMap.put("Zu", "Zuniga");
|
nameMap.put("Zu", "Zuniga");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #region Constructor
|
// #region Constructor
|
||||||
public Teacher(String name) {
|
public Teacher(String name) {
|
||||||
|
// Use the short name to find the full name from the nameMap
|
||||||
this.name = nameMap.getOrDefault(name, "Unknown");
|
this.name = nameMap.getOrDefault(name, "Unknown");
|
||||||
this.points = new Points();
|
this.points = new Points(); // Initialize a new Points object
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region Getters
|
// #region Getters
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name; // Return the teacher's full name
|
||||||
}
|
}
|
||||||
|
|
||||||
public Points getPoints() {
|
public Points getPoints() {
|
||||||
return points;
|
return points; // Return the Points object associated with this teacher
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue