Skip to content

Commit

Permalink
Merge branch 'master' into DevRaph
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaLLamothe authored Nov 27, 2024
2 parents dd2a1dc + 1607e41 commit 2ea50a0
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 54 deletions.
Binary file added BD/CR.odt
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 42 additions & 1 deletion Code/java/src/main/java/application/tools/DataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ public static List<Float> getTemps(List<File> datasToFetch){
return tempsToReturn;
}

public static List<Float> getHumidites(List<File> datasToFetch){
public static float getTemps(File datasToFetch){
//-275 étant inférieur au 0 absolu, c'est une valeur absurde qui sera détectable de manière automatique
float tempToReturn = -275;
try {
String data = Files.readString(datasToFetch.toPath());
data = data.replace("{","").replace("}","");
String[] splittedValues = data.split(", ");
tempToReturn = Float.parseFloat(splittedValues[0]);
} catch (IOException e) {
throw new RuntimeException(e);
}
return tempToReturn;
}

public static List<Float> getHumidities(List<File> datasToFetch){

List <Float> humiditiesToReturn = new ArrayList<>();
for(File currentFile : datasToFetch){
try{
Expand All @@ -37,6 +52,19 @@ public static List<Float> getHumidites(List<File> datasToFetch){
return humiditiesToReturn;
}

public static float getHumidities(File datasToFetch){
float humidityToReturn = -1;
try {
String data = Files.readString(datasToFetch.toPath());
data = data.replace("{","").replace("}","");
String[] splittedValues = data.split(", ");
humidityToReturn = Float.parseFloat(splittedValues[1]);
} catch (IOException e) {
throw new RuntimeException(e);
}
return humidityToReturn;
}

public static List<Float> getCo2(List<File> datasToFetch){
List <Float> co2ToReturn = new ArrayList<>();
for(File currentFile : datasToFetch){
Expand All @@ -51,4 +79,17 @@ public static List<Float> getCo2(List<File> datasToFetch){
}
return co2ToReturn;
}

public static float getCo2(File datasToFetch){
float co2ToReturn = -1;
try {
String data = Files.readString(datasToFetch.toPath());
data = data.replace("{","").replace("}","");
String[] splittedValues = data.split(", ");
co2ToReturn = Float.parseFloat(splittedValues[2]);
} catch (IOException e) {
throw new RuntimeException(e);
}
return co2ToReturn;
}
}
156 changes: 103 additions & 53 deletions Code/java/src/main/java/application/view/DonneesActuellesController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package application.view;

import application.control.IoTMainFrame;
import application.tools.DataReader;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
Expand All @@ -15,12 +16,16 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import netscape.javascript.JSObject;

public class DonneesActuellesController {
private enum DATA{
TEMP, CO2, HUM
}
private enum TEXTVALUES{
TEMPTITLE("Température : "),
TEMPID("Temp"),
Expand All @@ -46,19 +51,16 @@ private String getDisplayText(){
public class JSBridge {
public void handleClick(String room) {
System.out.println("Room clicked: " + room);
displayedListUpdate(room);
try {
getCorrespondingData(room);
} catch (URISyntaxException | IOException e) {
throw new RuntimeException(e);
displayedListUpdate(room);
} catch (Exception e) {
System.out.println("Capteur introuvable.");
}
}
}

private Stage containingStage;
@FXML
private VBox buttonsHolder;
@FXML
private VBox displayedDatas;
@FXML
private CheckBox temp;
Expand All @@ -70,12 +72,15 @@ public void handleClick(String room) {
@FXML
private WebView iutschematics;
private WebEngine webEngine;
private JSBridge jsBridge = new JSBridge();
private final JSBridge jsBridge = new JSBridge();
private IoTMainFrame main = new IoTMainFrame();

public void initContext(Stage _containingStage) {
this.containingStage = _containingStage;
this.initWeb();
controlUpdateThread checkingRunnable = new controlUpdateThread();
Thread checkingThread = new Thread(checkingRunnable);
checkingThread.start();
}

private void initWeb(){
Expand Down Expand Up @@ -165,7 +170,7 @@ private void updateDisplayedDatas(){
}


public void displayedListUpdate(String room){
public void displayedListUpdate(String room) throws Exception {
boolean deleted = false;
Node toDelete = null;
for(Node n : displayedDatas.getChildren()){
Expand All @@ -178,64 +183,109 @@ public void displayedListUpdate(String room){
if(deleted) break;
}
if(!deleted) {
TitledPane roomdatas = new TitledPane();
roomdatas.setText(room);
VBox datasStorage = new VBox();
datasStorage.setSpacing(5);
Text tempTitle = new Text(TEXTVALUES.TEMPTITLE.getDisplayText());
tempTitle.setId(TEXTVALUES.TEMPID.getDisplayText());
TextField tempRoom = new TextField("Si vous voyez ça, j'ai mal fait mon boulot "+TEXTVALUES.TEMPUNIT.getDisplayText());
tempRoom.setId(TEXTVALUES.TEMPID.getDisplayText());
tempRoom.setEditable(false);
if(!temp.isSelected()){
tempTitle.setVisible(false);
tempTitle.setManaged(false);
tempRoom.setVisible(false);
tempRoom.setManaged(false);
}
Text co2Title = new Text(TEXTVALUES.CO2TITLE.getDisplayText());
co2Title.setId(TEXTVALUES.CO2ID.getDisplayText());
TextField co2Room = new TextField("Si vous voyez ça, j'ai mal fait mon boulot "+TEXTVALUES.CO2UNIT.getDisplayText());
co2Room.setId(TEXTVALUES.CO2ID.getDisplayText());
co2Room.setEditable(false);
if(!co2.isSelected()){
co2Title.setVisible(false);
co2Title.setManaged(false);
co2Room.setVisible(false);
co2Room.setManaged(false);
}
Text humTitle = new Text(TEXTVALUES.HUMIDITYTITLE.getDisplayText());
humTitle.setId(TEXTVALUES.HUMIDITYID.getDisplayText());
TextField humRoom = new TextField("Si vous voyez ça, j'ai mal fait mon boulot "+TEXTVALUES.HUMIDITYUNIT.getDisplayText());
humRoom.setId(TEXTVALUES.HUMIDITYID.getDisplayText());
humRoom.setEditable(false);
if(!humidity.isSelected()){
humTitle.setVisible(false);
humTitle.setManaged(false);
humRoom.setVisible(false);
humRoom.setManaged(false);
}
datasStorage.getChildren().addAll(tempTitle, tempRoom, co2Title, co2Room, humTitle, humRoom);
roomdatas.setContent(datasStorage);
displayedDatas.getChildren().add(roomdatas);
roomdatas.setExpanded(true);
updateRoom(room);
}else displayedDatas.getChildren().remove(toDelete);
}

private void getCorrespondingData(String room) throws URISyntaxException, IOException {
public void displayedListUpdateSoft(String room) throws Exception {
updateRoom(room);
}

private void updateRoom(String room) throws Exception {
TitledPane roomdatas = new TitledPane();
roomdatas.setText(room);
VBox datasStorage = new VBox();
datasStorage.setSpacing(5);
Text tempTitle = new Text(TEXTVALUES.TEMPTITLE.getDisplayText());
tempTitle.setId(TEXTVALUES.TEMPID.getDisplayText());
TextField tempRoom = new TextField(getCorrespondingData(room, DATA.TEMP)+ TEXTVALUES.TEMPUNIT.getDisplayText());
tempRoom.setId(TEXTVALUES.TEMPID.getDisplayText());
tempRoom.setEditable(false);
if(!temp.isSelected()){
tempTitle.setVisible(false);
tempTitle.setManaged(false);
tempRoom.setVisible(false);
tempRoom.setManaged(false);
}
Text co2Title = new Text(TEXTVALUES.CO2TITLE.getDisplayText());
co2Title.setId(TEXTVALUES.CO2ID.getDisplayText());
TextField co2Room = new TextField(getCorrespondingData(room, DATA.CO2)+ TEXTVALUES.CO2UNIT.getDisplayText());
co2Room.setId(TEXTVALUES.CO2ID.getDisplayText());
co2Room.setEditable(false);
if(!co2.isSelected()){
co2Title.setVisible(false);
co2Title.setManaged(false);
co2Room.setVisible(false);
co2Room.setManaged(false);
}
Text humTitle = new Text(TEXTVALUES.HUMIDITYTITLE.getDisplayText());
humTitle.setId(TEXTVALUES.HUMIDITYID.getDisplayText());
TextField humRoom = new TextField(getCorrespondingData(room, DATA.HUM)+ TEXTVALUES.HUMIDITYUNIT.getDisplayText());
humRoom.setId(TEXTVALUES.HUMIDITYID.getDisplayText());
humRoom.setEditable(false);
if(!humidity.isSelected()){
humTitle.setVisible(false);
humTitle.setManaged(false);
humRoom.setVisible(false);
humRoom.setManaged(false);
}
datasStorage.getChildren().addAll(tempTitle, tempRoom, co2Title, co2Room, humTitle, humRoom);
roomdatas.setContent(datasStorage);
displayedDatas.getChildren().add(roomdatas);
roomdatas.setExpanded(true);
}

private float getCorrespondingData(String room, DATA toFetch) throws URISyntaxException, IOException, Exception {
room=room.toUpperCase();
File folder = new File(Objects.requireNonNull(DonneesActuellesController.class.getClassLoader().getResource("application/AM107/"+room)).toURI());
if(folder.exists()) {
File[] allDatas = folder.listFiles();
System.out.println(allDatas.length);
assert allDatas != null;
File captorData = allDatas[0];
for(File current : allDatas){
if(current.lastModified() > captorData.lastModified()){
captorData = current;
}
}
System.out.println(Files.readString(captorData.toPath()));
return switch (toFetch) {
case CO2 -> DataReader.getCo2(captorData);
case HUM -> DataReader.getHumidities(captorData);
case TEMP -> DataReader.getTemps(captorData);
default -> throw new Exception("Type de donnée inconnue");
};
}
throw new Exception("Erreur de lecture de fichier");
}

private class controlUpdateThread implements Runnable{
boolean terminated;

public controlUpdateThread(){
terminated = false;
}

@Override
public void run() {
Map<File, Integer> fileAmount = new HashMap<>();
File mainFolder = new File(Objects.requireNonNull(DonneesActuellesController.class.getClassLoader().getResource("application/AM107")).toString());
for(File folder : Objects.requireNonNull(mainFolder.listFiles())){
fileAmount.put(folder, Objects.requireNonNull(folder.listFiles()).length);
}
while(!terminated){
for(File folder : Objects.requireNonNull(mainFolder.listFiles())){
if(Objects.requireNonNull(folder.listFiles()).length>fileAmount.get(folder)){
try {
displayedListUpdateSoft(folder.getName().toUpperCase());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}

public void stop(){
this.terminated = true;
}
}
}
2 changes: 2 additions & 0 deletions Code/java/src/main/java/application/view/MenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import application.control.IoTMainFrame;
import javafx.fxml.FXML;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class MenuController {
Expand All @@ -15,6 +16,7 @@ public void initContext(Stage _containingStage) {
}

public void displayDialog(){
this.containingStage.getIcons().add(new Image(this.getClass().getResourceAsStream("app_icon.jpg")));
this.containingStage.show();
}

Expand Down

0 comments on commit 2ea50a0

Please sign in to comment.