Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout des dernières data dans ma branche #68

Merged
merged 13 commits into from
Dec 6, 2024
Merged
Next Next commit
Ajout de l'affichage des solaredge au temps réel (quelques correctifs…
… sont toujours requis mais l'application est fonctionnelle)
  • Loading branch information
NariaReynhard committed Dec 3, 2024
commit 2bca05591e4fa2b19beec5e69d3460285e41b5ba
8 changes: 5 additions & 3 deletions Code/java/src/main/java/application/tools/DataReader.java
Original file line number Diff line number Diff line change
@@ -53,14 +53,16 @@ public static float getCo2(File datasToFetch){
return co2ToReturn;
}

private static Map<String, Float> getDict(File datasToFetch){
public static Map<String, Float> getDict(File datasToFetch){
Map<String, Float> dictToReturn = new HashMap<>();
try {
String data = Files.readString(datasToFetch.toPath());
data = data.replace("{","").replace("}","").replace("'","");
String[] splittedValues = data.split(", |: ");
for(int i = 0; i<splittedValues.length;i+=2){
dictToReturn.put(splittedValues[i], Float.parseFloat(splittedValues[i+1]));
for(int i = 0; i<splittedValues.length-1;i+=2){
try {
dictToReturn.put(splittedValues[i], Float.parseFloat(splittedValues[i + 1]));
} catch (NumberFormatException ignored) {}
}
} catch (IOException e) {
throw new RuntimeException(e);
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
import application.tools.DataReader;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebEngine;
@@ -59,16 +59,47 @@ public void handleClick(String room) {
}
}

private Node webviewerMemory;
private Node displayedDatasMemory;

private Stage containingStage;
@FXML
private BorderPane mainContainer;
@FXML
private VBox displayedDatas;
@FXML
private VBox alerts;
@FXML
private VBox warnings;
@FXML
private CheckBox temp;
@FXML
private CheckBox co2;
@FXML
private CheckBox humidity;

@FXML
private RadioMenuItem am107;
@FXML
private RadioMenuItem solaredge;

@FXML
private void changeInterface()throws Exception {
if(am107.isSelected()){
mainContainer.setCenter(displayedDatas);
Node temp = mainContainer.getRight();
mainContainer.setRight(displayedDatasMemory);
displayedDatasMemory=temp;
}else if(solaredge.isSelected()){
webviewerMemory=mainContainer.getCenter();
Node temp = mainContainer.getRight();
mainContainer.setCenter(displayedDatasMemory);
displayedDatasMemory=temp;
mainContainer.setRight(null);
}else{
throw new Exception("Une a été rencontrée lors de la séléction des capteurs.");
}
}
@FXML
private WebView iutschematics;
private WebEngine webEngine;
@@ -77,12 +108,50 @@ public void handleClick(String room) {

public void initContext(Stage _containingStage) {
this.containingStage = _containingStage;
this.displayedDatasMemory = setUpSolaredge();
this.initWeb();
controlUpdateThread checkingRunnable = new controlUpdateThread();
Thread checkingThread = new Thread(checkingRunnable);
checkingThread.start();
/*
Test pour les notifications
*/
newWarning("b113");
newWarning("B113");
}

private Node setUpSolaredge(){
TitledPane solaredge = new TitledPane();
solaredge.setText("Solaredge");
solaredge.setCollapsible(false);
solaredge.setExpanded(true);
solaredge.setId("solaredge");
VBox container = new VBox();
container.setFillWidth(true);
solaredge.setContent(container);
File solarEdgefolder = null;
try {
solarEdgefolder = new File(Objects.requireNonNull(DonneesActuellesController.class.getClassLoader().getResource("application/capteur/solaredge")).toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
System.out.println(solarEdgefolder.getAbsolutePath());
System.out.println(solarEdgefolder.exists());
File lastestSolarEdge = Objects.requireNonNull(solarEdgefolder.listFiles())[0];
for(File current : Objects.requireNonNull(solarEdgefolder.listFiles())){
if (lastestSolarEdge.lastModified()> current.lastModified()) lastestSolarEdge = current;
}
for(Map.Entry<String, Float> entry : DataReader.getDict(lastestSolarEdge).entrySet()){
Text tempText = new Text(entry.getKey());
tempText.setId(entry.getKey());
TextField tempField = new TextField(String.valueOf(entry.getValue()));
tempField.setId(entry.getValue().toString());
tempField.setEditable(false);
container.getChildren().add(tempText);
container.getChildren().add(tempField);
}
return solaredge;
}
private void initWeb(){
String pathSvg = Objects.requireNonNull(DonneesActuellesController.class.getClassLoader().getResource("application/svg/demoSVG.html")).toString();

@@ -171,11 +240,12 @@ private void updateDisplayedDatas(){


public void displayedListUpdate(String room) throws Exception {
System.out.println("Debug : "+room);
boolean deleted = false;
Node toDelete = null;
for(Node n : displayedDatas.getChildren()){
if(n instanceof TitledPane checking){
if (checking.getText().equals(room)){
if (checking.getText().equals(room.toUpperCase())){
toDelete = n;
deleted = true;
}
@@ -193,7 +263,7 @@ public void displayedListUpdateSoft(String room) throws Exception {

private void updateRoom(String room) throws Exception {
TitledPane roomdatas = new TitledPane();
roomdatas.setText(room);
roomdatas.setText(room.toUpperCase());
VBox datasStorage = new VBox();
datasStorage.setSpacing(5);
Text tempTitle = new Text(TEXTVALUES.TEMPTITLE.getDisplayText());
@@ -238,7 +308,6 @@ private void updateRoom(String room) throws Exception {
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/capteur/AM107/"+room)).toURI());
System.out.println(folder.getAbsolutePath());
if(folder.exists()) {
File[] allDatas = folder.listFiles();
assert allDatas != null;
@@ -257,6 +326,53 @@ private float getCorrespondingData(String room, DATA toFetch) throws URISyntaxEx
throw new Exception("Erreur de lecture de fichier");
}

private void newWarning(String room){
boolean exists = false;
for(Node existingrooms : warnings.getChildren()){
if (existingrooms instanceof Button){
if (existingrooms.getId().equals(room.toLowerCase())) {
exists = true;
}
}
}
if(!exists) {
Button warningRoom = notificationHandle(room);
this.warnings.getChildren().add(warningRoom);
}
}

private void newAlert(String room){
boolean exists = false;
for(Node existingrooms : alerts.getChildren()){
if (existingrooms instanceof Button){
if (existingrooms.getId().equals(room.toLowerCase())) {
exists = true;
}
}
}
if(!exists) {
Button alertButton = notificationHandle(room);
this.alerts.getChildren().add(alertButton);
}
}

private Button notificationHandle(String room) {
Button newButton = new Button();
newButton.setText(room.toUpperCase());
newButton.setId(room.toLowerCase());
newButton.setMaxHeight(Double.MAX_VALUE);
newButton.setMaxWidth(Double.MAX_VALUE);
newButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
try {
displayedListUpdate(room);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
);
return newButton;
}

private class controlUpdateThread implements Runnable{
boolean terminated;

125 changes: 68 additions & 57 deletions Code/java/src/main/resources/application/view/affichageTpsReel.fxml
Original file line number Diff line number Diff line change
@@ -38,11 +38,12 @@
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.RadioMenuItem?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
@@ -51,7 +52,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.web.WebView?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.view.DonneesActuellesController">
<BorderPane fx:id="mainContainer" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.view.DonneesActuellesController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
@@ -63,6 +64,16 @@
<MenuItem mnemonicParsing="false" onAction="#fermer" text="Fermer" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Capteurs">
<items>
<RadioMenuItem fx:id="am107" mnemonicParsing="false" onAction="#changeInterface" selected="true" text="AM107">
<toggleGroup>
<ToggleGroup fx:id="captor" />
</toggleGroup>
</RadioMenuItem>
<RadioMenuItem fx:id="solaredge" mnemonicParsing="false" onAction="#changeInterface" text="SolarEdge" toggleGroup="$captor" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
@@ -85,65 +96,65 @@
</padding>
</HBox>
</bottom>
<center>
<SplitPane dividerPositions="0.2505567928730512, 0.7505567928730512" focusTraversable="true" prefHeight="-1.0" prefWidth="-1.0" BorderPane.alignment="CENTER">
<items>
<VBox prefWidth="150.0">
<children>
<CheckBox fx:id="temp" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Température">
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</CheckBox>
<CheckBox fx:id="co2" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Co2">
<padding>
<Insets bottom="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="humidity" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Humidité">
<padding>
<Insets bottom="5.0" />
</padding>
</CheckBox>
<TitledPane animated="false" text="Alertes :">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true">
<content>
<VBox>
<children>
<ToggleButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Example critical room" />
</children>
</VBox>
</content>
</ScrollPane>
</content>
</TitledPane>
<TitledPane animated="false" text="Attention :">
<left>
<VBox prefWidth="150.0" BorderPane.alignment="CENTER">
<children>
<CheckBox fx:id="temp" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Température">
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</CheckBox>
<CheckBox fx:id="co2" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Co2">
<padding>
<Insets bottom="5.0" />
</padding>
</CheckBox>
<CheckBox fx:id="humidity" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#updateDisplayedDatas" selected="true" text="Humidité">
<padding>
<Insets bottom="5.0" />
</padding>
</CheckBox>
<TitledPane animated="false" text="Alertes :">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true">
<content>
<VBox>
<children>
<ToggleButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Exemple dangerous room" />
</children>
</VBox>
</content>
</ScrollPane>
<VBox fx:id="alerts">
<children>
<ToggleButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Example critical room" />
</children>
</VBox>
</content>
</TitledPane>
</children>
</VBox>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="-1.0" prefWidth="-1.0">
<content>
<WebView fx:id="iutschematics" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" />
</ScrollPane>
</content>
</ScrollPane>
<ScrollPane fitToWidth="true" prefWidth="200.0">
</TitledPane>
<TitledPane animated="false" text="Attention :">
<content>
<VBox fx:id="displayedDatas" />
<ScrollPane fitToHeight="true" fitToWidth="true">
<content>
<VBox fx:id="warnings">
<children>
<ToggleButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Exemple dangerous room" />
</children>
</VBox>
</content>
</ScrollPane>
</content>
</ScrollPane>
</items>
</SplitPane>
</TitledPane>
</children>
</VBox>
</left>
<right>
<ScrollPane fitToWidth="true" prefWidth="175.0" BorderPane.alignment="CENTER">
<content>
<VBox fx:id="displayedDatas" />
</content>
</ScrollPane>
</right>
<center>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="-1.0" prefWidth="-1.0" BorderPane.alignment="CENTER">
<content>
<WebView fx:id="iutschematics" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" />
</content>
</ScrollPane>
</center>
</BorderPane>