Start of the Project

This commit is contained in:
Sage The DM 2024-10-29 20:17:51 +01:00
parent 48a8902a52
commit c317cd6227
14 changed files with 231 additions and 6 deletions

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View 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).

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,47 @@
import java.util.List;
public class App {
// Fetch data for rooms
private List<Data> room39Data = Data.getData("https://api.thingspeak.com/channels/1521262/feeds.csv", 39);
private List<Data> room38Data = Data.getData("https://api.thingspeak.com/channels/1364580/feeds.csv", 38);
private List<Data> room37Data = Data.getData("https://api.thingspeak.com/channels/1521263/feeds.csv", 37);
// Time table
// [Room 37 (0), 38 (1), or 39 (2)][Day 0-4][Lesson slot 0-11]
static Lesson[][][] timeTable = new Lesson[3][5][12];
public static void main(String[] args) {
fillInTimeTable();
// Display filled timetable for verification
for (int room = 0; room < timeTable.length; room++) {
for (int day = 0; day < timeTable[room].length; day++) {
System.out.println("Room " + (room + 37) + ", Day " + (day + 1) + ":");
for (int lesson = 0; lesson < timeTable[room][day].length; lesson++) {
Lesson lessonData = timeTable[room][day][lesson];
if (lessonData != null) {
System.out.println(" Lesson " + (lesson + 1) + ": " + lessonData);
} else {
System.out.println(" Lesson " + (lesson + 1) + ": No Lesson");
}
}
}
}
}
private static void fillInTimeTable() {
// Fill Room 37 timetable
FillTable.fillRoom37TimeTable();
// Fill Room 38 timetable
FillTable.fillRoom38TimeTable();
// Fill Room 39 timetable
FillTable.fillRoom39TimeTable();
}
private static void fillRoom37TimeTable() {
}
}

View file

@ -0,0 +1,87 @@
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 Data {
private int classRomNumber; // either 37 or 38
private int co2Level; // value in ppm
private String day; // the name of the day
private String date; // example 12.08.2024
// Constructor
public Data(int classRomNumber, int co2Level, String day, String date) {
this.classRomNumber = classRomNumber;
this.co2Level = co2Level;
this.day = day;
this.date = date;
}
// Getters
public int getClassRomNumber() {
return classRomNumber;
}
public int getCo2Level() {
return co2Level;
}
public String getDay() {
return day;
}
public String getDate() {
return date;
}
public static List<Data> getData(String csvURL, int classRomNumber) {
List<Data> dataList = new ArrayList<>();
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());
}
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(in);
String output;
// Skip header line
br.readLine();
while ((output = br.readLine()) != null) {
Data data = parseData(output, classRomNumber);
if (data != null) {
dataList.add(data);
}
}
conn.disconnect();
} catch (Exception e) {
System.out.println("Exception in NetClientGet: " + e);
}
return dataList; // Return the list of Data objects
}
private static Data parseData(String csvLine, int classRomNumber) {
String[] fields = csvLine.split(",");
if (fields.length < 5) {
return null; // or handle error
}
String createdAt = fields[0]; // created_at field
int co2Level = Integer.parseInt(fields[2]); // field1 as CO2 level
String date = createdAt.split(" ")[0]; // Extract date
String day = createdAt.split(" ")[0]; // You can implement logic to determine the day from the date if needed
return new Data(classRomNumber, co2Level, day, date);
}
}

View file

@ -0,0 +1,28 @@
public class FillTable {
// Fill Room 37 timetable
static void fillRoom37TimeTable() {
// Monday
// Tuesday
// Wednesday
// Thursday
// Friday
}
// Fill Room 38 timetable
static void fillRoom38TimeTable() {
// Monday
// Tuesday
// Wednesday
// Thursday
// Friday
}
// Fill Room 39 timetable
static void fillRoom39TimeTable() {
// Monday
// Tuesday
// Wednesday
// Thursday
// Friday
}
}

View file

@ -0,0 +1,13 @@
public class Lesson {
int room;
String teacherName;
String startTime;
String endTime;
String day;
public Lesson(int room, String teacherName) {
this.room = room;
this.teacherName = teacherName;
}
}

View file

@ -0,0 +1,25 @@
public class Teacher {
private String name;
private int points;
public Teacher(String name) {
this.name = name;
points = 0;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
}

View file

@ -17,11 +17,11 @@ public class App extends Application {
AnchorPane anchorPane = new AnchorPane();
// Create Controll button
Button controlButton = new Button("Button");
AnchorPane.setTopAnchor(controlButton, 50.0);
AnchorPane.setLeftAnchor(controlButton, 50.0);
AnchorPane.setRightAnchor(controlButton, 10.0);
AnchorPane.setBottomAnchor(controlButton, 10.0);
Button mainButton = new Button("Button");
AnchorPane.setTopAnchor(mainButton, 50.0);
AnchorPane.setLeftAnchor(mainButton, 50.0);
AnchorPane.setRightAnchor(mainButton, 10.0);
AnchorPane.setBottomAnchor(mainButton, 10.0);
// Create Button 1
Button button1 = new Button("Button 1");
@ -29,7 +29,7 @@ public class App extends Application {
AnchorPane.setLeftAnchor(button1, 10.0);
// Add buttons to the pane
anchorPane.getChildren().addAll(controlButton, button1);
anchorPane.getChildren().addAll(mainButton, button1);
// Set up the Scene with AnchorPane
Scene scene = new Scene(anchorPane, 640, 480);