changes made
This commit is contained in:
parent
e192af4647
commit
bda5461576
8 changed files with 173 additions and 151 deletions
BIN
bin/App.class
BIN
bin/App.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
228
src/App.java
228
src/App.java
|
@ -8,58 +8,94 @@ import java.util.Scanner;
|
|||
public class App {
|
||||
// #region app constants
|
||||
private static final Scanner scanner = new Scanner(System.in);
|
||||
private static final Teacher[] teachers = new Teacher[Teacher.nameMap.size()];
|
||||
private static Teacher[] teachers = new Teacher[Teacher.nameMap.size()]; // problem
|
||||
|
||||
// Room channel numbers, sorted asc. 37, 38, 39
|
||||
// Room channel numbers, sorted in ascending order: 37, 38, 39
|
||||
private static final int[] ROOM_NUMBERS = { 1521263, 1364580, 1521262 };
|
||||
|
||||
// Date and time constants for Start and End Dates
|
||||
// Date constants for Start and End Dates
|
||||
private static final String[] DATES = { "2024-11-04", "2024-11-05", "2024-11-06", "2024-11-07", "2024-11-08" };
|
||||
|
||||
private static ArrayList<Break[]> SHORT_BREAKS = new ArrayList<Break[]>();
|
||||
private static ArrayList<Break[]> LONG_BREAKS = new ArrayList<Break[]>();
|
||||
private static final ArrayList<Break[]> SHORT_BREAKS = new ArrayList<>();
|
||||
private static final ArrayList<Break[]> LONG_BREAKS = new ArrayList<>();
|
||||
|
||||
// #region Initialization
|
||||
|
||||
public static URL generateLink(int channelNumber, String date) throws MalformedURLException {
|
||||
String baseUrl = "https://api.thingspeak.com/channels/";
|
||||
String formattedStartDateTime = date + " 07:00:00";
|
||||
String formattedEndDateTime = date + " 19:00:00";
|
||||
|
||||
return new URL(baseUrl + channelNumber + "/feeds.csv?start=" + formattedStartDateTime.replace(" ", "%20")
|
||||
+ "&end=" + formattedEndDateTime.replace(" ", "%20")); // %20 --> " "
|
||||
|
||||
return new URL(baseUrl + channelNumber + "/feeds.csv?start=" +
|
||||
formattedStartDateTime.replace(" ", "%20") +
|
||||
"&end=" + formattedEndDateTime.replace(" ", "%20"));
|
||||
}
|
||||
|
||||
private static void calculateBreakPoints(Break calcBreak, Teacher teacher) {
|
||||
int duration = calcBreak.getEnd() - calcBreak.getStart();
|
||||
Co2Data[] minuteData = calcBreak.getCo2Datas();
|
||||
|
||||
if (minuteData.length != duration) {
|
||||
System.out.println("Data inconsistency detected: duration mismatch.");
|
||||
return;
|
||||
}
|
||||
|
||||
int breakPoints = minuteData.length;
|
||||
if (duration == minuteData.length) {
|
||||
for (int i = 0; i < duration; i++) {
|
||||
if (i + 1 != duration && (minuteData[i].getCo2Level() < minuteData[i + 1].getCo2Level())) {
|
||||
for (int i = 0; i < duration - 1; i++) {
|
||||
if (minuteData[i].getCo2Level() < minuteData[i + 1].getCo2Level()) {
|
||||
breakPoints--;
|
||||
}
|
||||
}
|
||||
} else
|
||||
System.out.println("Unexpected error");
|
||||
|
||||
if (duration > 5) {
|
||||
teacher.addPoints(0, breakPoints, 0);
|
||||
} else {
|
||||
teacher.addPoints(breakPoints, 0, 0);
|
||||
}
|
||||
|
||||
// check if next lesson is lunch another teacher or the same and plan
|
||||
// accordingly
|
||||
// bonus Point for teacher switch
|
||||
|
||||
}
|
||||
|
||||
private static void initializeTeachers() {
|
||||
// Mapping short names to full teacher names
|
||||
Teacher.nameMap.put("Hm", "Johann Hummel");
|
||||
Teacher.nameMap.put("Bd", "Fender Bender");
|
||||
Teacher.nameMap.put("Bu", "Luca Burger");
|
||||
Teacher.nameMap.put("Cg", "Jesus Chung");
|
||||
Teacher.nameMap.put("Do", "Brother Doe");
|
||||
Teacher.nameMap.put("Eh", "Johnny Ehrlich");
|
||||
Teacher.nameMap.put("Fh", "Karl Fischer");
|
||||
Teacher.nameMap.put("Gi", "Bobby Giordano");
|
||||
Teacher.nameMap.put("Gr", "Graham");
|
||||
Teacher.nameMap.put("Hi", "Higgins");
|
||||
Teacher.nameMap.put("Kg", "Kang");
|
||||
Teacher.nameMap.put("Kh", "Khan");
|
||||
Teacher.nameMap.put("Lz", "Lozano");
|
||||
Teacher.nameMap.put("Lu", "Lund");
|
||||
Teacher.nameMap.put("Or", "Ortega");
|
||||
Teacher.nameMap.put("Re", "Reyes");
|
||||
Teacher.nameMap.put("Se", "Seng");
|
||||
Teacher.nameMap.put("Ts", "Tanaka");
|
||||
Teacher.nameMap.put("Vt", "Vetter");
|
||||
Teacher.nameMap.put("Zu", "Zuniga");
|
||||
Teacher.nameMap.put("Kp", "Kevin Peters");
|
||||
Teacher.nameMap.put("KP", "Kevin Peters");
|
||||
Teacher.nameMap.put("Ba", "Barbara Allen");
|
||||
Teacher.nameMap.put("Bz", "Basil Zephyr");
|
||||
Teacher.nameMap.put("Hn", "Hannah Nguyen");
|
||||
Teacher.nameMap.put("Le", "Full Name for Le");
|
||||
Teacher.nameMap.put("Du", "Full Name for Du");
|
||||
Teacher.nameMap.put("Bt", "Full Name for Bt");
|
||||
Teacher.nameMap.put("Es", "Full Name for Es");
|
||||
Teacher.nameMap.put("Hu", "Full Name for Hu");
|
||||
Teacher.nameMap.put("Ge", "Full Name for Ge");
|
||||
|
||||
// Initialize the teachers array with the size of nameMap
|
||||
teachers = new Teacher[Teacher.nameMap.size()];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +107,26 @@ public class App {
|
|||
if (scanner.hasNextInt()) {
|
||||
return scanner.nextInt();
|
||||
}
|
||||
scanner.next(); // Clear invalid input
|
||||
System.out.println("Invalid input. Please enter a number.");
|
||||
scanner.next();
|
||||
}
|
||||
}
|
||||
|
||||
private static void interactWithUser() {
|
||||
while (true) {
|
||||
int userInput = getUserInput("Do you want to see how the points were calculated? (1 = Yes, 0 = No)");
|
||||
if (userInput == 1) {
|
||||
printExplanation();
|
||||
break;
|
||||
} else if (userInput == 0) {
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Invalid input. Please enter 1 for Yes or 0 for No.");
|
||||
}
|
||||
}
|
||||
printShutdown();
|
||||
}
|
||||
|
||||
// #region Explanation
|
||||
private static void printExplanation() {
|
||||
System.out.println("Point calculation explanation:");
|
||||
|
@ -83,8 +135,8 @@ public class App {
|
|||
System.out.println("3. 5 bonus points for teacher switches in classrooms.");
|
||||
}
|
||||
|
||||
// #region shutdown
|
||||
private static void printShutDown() {
|
||||
// #region Shutdown
|
||||
private static void printShutdown() {
|
||||
System.out.println("Shutting down...");
|
||||
for (int i = 3; i > 0; i--) {
|
||||
System.out.print(i + "...");
|
||||
|
@ -96,94 +148,100 @@ public class App {
|
|||
}
|
||||
}
|
||||
|
||||
// #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
|
||||
// #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()));
|
||||
(a, b) -> Integer.compare(b.getTotalPoints(), a.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);
|
||||
}
|
||||
int teacherPoints = teacher.getTotalPoints();
|
||||
|
||||
if (teacherPoints != previousPoints) {
|
||||
rank = i + 1;
|
||||
previousPoints = teacherPoints;
|
||||
}
|
||||
System.out.println(rank + ". " + teacher.getName() + " - Points: " + teacherPoints);
|
||||
}
|
||||
}
|
||||
|
||||
// #region Main
|
||||
public static void main(String[] args) throws MalformedURLException {
|
||||
System.out.println("Calculations in process please do not shut off...");
|
||||
private static Teacher findTeacherForBreak(int breakIndex, TimeTable timeTable, int dayIndex) {
|
||||
String teacherShortName = timeTable.getLesson(breakIndex, dayIndex);
|
||||
|
||||
if (teacherShortName == null || teacherShortName.isEmpty()) {
|
||||
System.out.println("No teacher assigned during this break.");
|
||||
return null;
|
||||
}
|
||||
if (!Teacher.nameMap.containsKey(teacherShortName) && teacherShortName != "Lunch") {
|
||||
System.out.println("Teacher with short name " + teacherShortName + " not found in Teacher.nameMap.");
|
||||
return null;
|
||||
}
|
||||
|
||||
String fullName = Teacher.nameMap.get(teacherShortName);
|
||||
for (Teacher teacher : teachers) {
|
||||
if (teacher.getName().equals(fullName)) {
|
||||
return teacher;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// #region main
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.out.println("Calculations in process. Please do not shut off...");
|
||||
initializeTeachers();
|
||||
|
||||
ArrayList<Break> co2Datas = new ArrayList<Break>();
|
||||
for (int classrooms = 0; classrooms < 3; classrooms++) {
|
||||
for (int weekday = 0; weekday < 5; weekday++) {
|
||||
List<Co2Data> tempData = Co2Data.getData(generateLink(ROOM_NUMBERS[classrooms], DATES[weekday]));
|
||||
SHORT_BREAKS.add(BreakSchedule.createBreaks(BreakSchedule.START_SMALL_BREAK,
|
||||
BreakSchedule.END_SMALL_BREAK, tempData));
|
||||
LONG_BREAKS.add(BreakSchedule.createBreaks(BreakSchedule.START_LONG_BREAK,
|
||||
BreakSchedule.END_LONG_BREAK, tempData));
|
||||
for (int roomIndex = 0; roomIndex < ROOM_NUMBERS.length; roomIndex++) {
|
||||
TimeTable timeTable = new TimeTable(roomIndex);
|
||||
|
||||
for (String date : DATES) {
|
||||
try {
|
||||
List<Co2Data> tempData = Co2Data.getData(generateLink(ROOM_NUMBERS[roomIndex], date));
|
||||
if (tempData == null || tempData.isEmpty()) {
|
||||
System.out
|
||||
.println("No data available for " + date + " in Room" + (roomIndex + 37) + ".");
|
||||
continue;
|
||||
}
|
||||
|
||||
Break[] shortBreaks = BreakSchedule.createBreaks(
|
||||
BreakSchedule.START_SMALL_BREAK, BreakSchedule.END_SMALL_BREAK, tempData);
|
||||
|
||||
Break[] longBreaks = BreakSchedule.createBreaks(
|
||||
BreakSchedule.START_LONG_BREAK, BreakSchedule.END_LONG_BREAK, tempData);
|
||||
|
||||
for (int i = 0; i < shortBreaks.length; i++) {
|
||||
Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date));
|
||||
if (teacher != null) {
|
||||
calculateBreakPoints(shortBreaks[i], teacher);
|
||||
}
|
||||
}
|
||||
|
||||
calculateBreakPoints(SHORT_BREAKS.get(0)[0], teachers[0]);
|
||||
|
||||
// Loop threw each day with a specific classroom and after the weekdays are over
|
||||
// go to the next of the 3 classroms
|
||||
// go threw every break calculate the point and give them to the teacher
|
||||
// directly
|
||||
// remember the point class
|
||||
// BreakSchedule needed
|
||||
for (int i = 0; i < longBreaks.length; i++) {
|
||||
Teacher teacher = findTeacherForBreak(i, timeTable, Arrays.asList(DATES).indexOf(date));
|
||||
if (teacher != null) {
|
||||
calculateBreakPoints(longBreaks[i], teacher);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error processing data for date: " + date + ". " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sortTeachers();
|
||||
printTeachers();
|
||||
interactWithUser();
|
||||
|
||||
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();
|
||||
// add a more detailed listing of the teacher since points can be broken down
|
||||
// further
|
||||
printShutDown();
|
||||
break;
|
||||
} else if (userInput == 0) {
|
||||
printShutDown();
|
||||
break;
|
||||
} else {
|
||||
System.out.println("Invalid input. Please enter 1 for Yes or 0 for No.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fatal error: " + e.getMessage());
|
||||
} finally {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ public class BreakSchedule {
|
|||
Co2Data[] co2Datas = new Co2Data[endTimes[i] - startTimes[i]];
|
||||
for (Co2Data data : co2Data) {
|
||||
if (data.getTime() >= startTimes[i] && data.getTime() < endTimes[i]) {
|
||||
System.out.println(startTimes[i] + " " + endTimes[i] + " " + data.getTime());
|
||||
co2Datas[data.getTime() - startTimes[i]] = data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ public class Co2Data {
|
|||
br.readLine(); // Skip header line
|
||||
|
||||
String output;
|
||||
System.out.println(url);
|
||||
while ((output = br.readLine()) != null) {
|
||||
Co2Data data = parseData(output);
|
||||
if (data != null) {
|
||||
|
|
|
@ -1,73 +1,39 @@
|
|||
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<>();
|
||||
private String shortName;
|
||||
private String name;
|
||||
private int totalPoints;
|
||||
|
||||
// #region Initialization
|
||||
static {
|
||||
// Mapping short names to full teacher names
|
||||
nameMap.put("Hm", "Johann Hummel");
|
||||
nameMap.put("Bd", "Fender Bender");
|
||||
nameMap.put("Bu", "Luca Burger");
|
||||
nameMap.put("Cg", "Jesus Chung");
|
||||
nameMap.put("Do", "Brother Doe");
|
||||
nameMap.put("Eh", "Johnny Ehrlich");
|
||||
nameMap.put("Fh", "Karl Fischer");
|
||||
nameMap.put("Gi", "Bobby 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");
|
||||
// Constructor
|
||||
public Teacher(String shortName) {
|
||||
this.shortName = shortName;
|
||||
this.name = nameMap.get(shortName);
|
||||
this.totalPoints = 0;
|
||||
}
|
||||
|
||||
// #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
|
||||
// Getters
|
||||
public String getShortName() {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
// #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 void addPoints(int fiveMinute, int tenMinutes, int bonusPoints) {
|
||||
this.points.addFiveMinuteBreakPoints(fiveMinute);
|
||||
this.points.addLongerBreakPoints(tenMinutes);
|
||||
this.points.addBonusPoints(bonusPoints);
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getTotalPoints() {
|
||||
return this.points.getTotalPoints();
|
||||
return totalPoints;
|
||||
}
|
||||
|
||||
// Setters
|
||||
public void setTotalPoints(int points) {
|
||||
this.totalPoints = points;
|
||||
}
|
||||
|
||||
// Method to add points
|
||||
public void addPoints(int smallBreakPoints, int longBreakPoints, int bonusPoints) {
|
||||
this.totalPoints += smallBreakPoints + longBreakPoints + bonusPoints;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue