Skip to content

Commit

Permalink
Merge branch 'Adrien_branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienTheophile committed Dec 5, 2024
2 parents 0592ee2 + c26af6b commit f940916
Show file tree
Hide file tree
Showing 13 changed files with 13,812 additions and 127 deletions.
57 changes: 56 additions & 1 deletion Application/app/src/main/java/sae/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import java.util.Map;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
Expand All @@ -17,7 +17,9 @@
import sae.view.AppState;
import sae.view.AfficherDonneesController;
import sae.view.ConfigController;
import sae.view.EvolutionGrapheController;
import sae.view.FreqConfigController;
import sae.view.GrapheSalleController;
import sae.view.MenuController;
import sae.view.ParametrageChoixSalles;
import sae.view.ParametrageSolar;
Expand Down Expand Up @@ -350,4 +352,57 @@ public void loadSeuilConfig() {
public static void main2(String[] args) {
Application.launch(args);
}

public void loadGraphe(String numSalle, Map<String, Object> map) {
try {

FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("view/grapheSalle.fxml"));

BorderPane vueListe = loader.load();

GrapheSalleController graphe = loader.getController();

// Transmission des données nécessaires au contrôleur
graphe.setDatas(stage, this);
graphe.populateHistogram(numSalle, map);

// Remplacement du contenu central de rootPane par la vue chargée
this.rootPane.setCenter(vueListe);

} catch (IOException e) {
// Gestion des erreurs si le fichier FXML est introuvable ou mal configuré
System.out.println("Ressource FXML non disponible : grapheSalle.fxml");
e.printStackTrace();
System.exit(1);
}
}

public void loadGraphe2(String numSalle, Map< String, Map<String, Object> > map) {
try {

FXMLLoader loader = new FXMLLoader();
loader.setLocation(App.class.getResource("view/grapheEvolutifSalle.fxml"));

BorderPane vueListe = loader.load();

EvolutionGrapheController graphe = loader.getController();

// Transmission des données nécessaires au contrôleur
graphe.setDatas(stage, this,vueListe);
graphe.afficherGraphes(numSalle, map);


// Remplacement du contenu central de rootPane par la vue chargée
this.rootPane.setCenter(vueListe);

} catch (IOException e) {
// Gestion des erreurs si le fichier FXML est introuvable ou mal configuré
System.out.println("Ressource FXML non disponible : grapheEvolutifSalle.fxml");
e.printStackTrace();
System.exit(1);
}
}


}
85 changes: 13 additions & 72 deletions Application/app/src/main/java/sae/appli/TypeDonnee.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,15 @@
package sae.appli;

public enum TypeDonnee {
TEMPERATURE("temperature", 20, 30),
HUMIDITY("humidity", 50, 70),
CO2("co2", 450, 1500),
TVOC("tvoc", 200, 400),
ACTIVITY("activity", 100, 500),
ILLUMINATION("illumination", 1, 60),
INFRARED("infrared", 1, 15),
INFRARED_AND_VISIBLE("infrared_and_visible", 1, 40),
PRESSURE("pressure", 980, 990);

private final String nom; // Nom de la donnée
private int seuilMin; // Seuil minimum (modifiable)
private int seuilMax; // Seuil maximum (modifiable)

// Constructeur pour initialiser les données
TypeDonnee(String nom, int seuilMin, int seuilMax) {
this.nom = nom;
this.seuilMin = seuilMin;
this.seuilMax = seuilMax;
}

// Récupérer le nom de la donnée
public String getNom() {
return nom;
}

// Récupérer le seuil minimum
public int getSeuilMin() {
return seuilMin;
}

// Récupérer le seuil maximum
public int getSeuilMax() {
return seuilMax;
}

// Méthode pour récupérer les seuils sous forme d'un tableau
public int[] getSeuils() {
return new int[]{seuilMin, seuilMax};
}

// Méthode statique pour obtenir les seuils en fonction du nom de la donnée
public static int[] getSeuilsByNom(String nom) {
for (TypeDonnee donnee : TypeDonnee.values()) {
if (donnee.getNom().equalsIgnoreCase(nom)) {
return donnee.getSeuils();
}
}
return null; // Retourne null si le nom n'est pas trouvé
}

// Méthode pour vérifier si un type donné est valide
public static boolean containsType(String nom) {
for (TypeDonnee donnee : TypeDonnee.values()) {
if (donnee.getNom().equalsIgnoreCase(nom)) {
return true;
}
}
return false;
}

// Méthode pour modifier dynamiquement les seuils
public static void setSeuilsByNom(String nom, int seuilMin, int seuilMax) {
for (TypeDonnee donnee : TypeDonnee.values()) {
if (donnee.getNom().equalsIgnoreCase(nom)) {
donnee.seuilMin = seuilMin;
donnee.seuilMax = seuilMax;
}
}
}
}
public enum TypeDonnee{

temperature,
humidity,
co2,
tvoc,
activity,
illumination,
infrared,
infrared_and_visible,
pressure;

}
110 changes: 65 additions & 45 deletions Application/app/src/main/java/sae/view/AfficherDonneesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
Expand All @@ -25,18 +30,29 @@ public class AfficherDonneesController {
@FXML
private Label titreSalle;

private String numSalle;

@FXML
private GridPane gridDynamique;

private ArrayList<String> donnees = new ArrayList<>();

private JSONObject sallesData; // Champ pour stocker les données JSON

Map<String, Object> dicoTypeValeur ; //recupere toutes les valeurs du config.ini
Map<String, Object> dicoGraphe ; //recupere seulement les données selectionnées

Map<String, Map<String, Object> > dicoHist ; //recupere l'historique des données


public void setDatas(Stage fenetre, App app) {
this.application = app;
this.fenetrePrincipale = fenetre;
}

public void setSalle(String salle) {
this.titreSalle.setText(salle);
this.numSalle = salle;
}

public void setTab(ArrayList<String> list) {
Expand All @@ -45,10 +61,9 @@ public void setTab(ArrayList<String> list) {

@FXML
private void actionAfficher() {
System.out.println("A faire !");
// lecture();
System.out.println(donnees);
chargerFichierSalle();
System.out.println(dicoHist);
application.loadGraphe(numSalle, dicoGraphe);
application.loadGraphe2(numSalle, dicoHist);
}

@FXML
Expand All @@ -57,62 +72,67 @@ private void actionRetour() {
}

public void afficherDonnees() {
for (int i = 0; i < donnees.size(); i++) {
gridDynamique.add(new Label(donnees.get(i) + " :"), 0, i);
}
}
chargerFichierSalle();
dicoGraphe = new HashMap<String,Object>();

public void chargerFichierSalle() {
for (int i = 0; i < donnees.size(); i++) {
gridDynamique.add(new Label( donnees.get(i).toUpperCase() + " :"), 0, i);
gridDynamique.add(new Label( dicoTypeValeur.get(donnees.get(i)) + "" ), 1, i);

JSONParser parser = new JSONParser();
dicoGraphe.put(donnees.get(i), dicoTypeValeur.get(donnees.get(i)));
}

for (Map.Entry<String, Map<String, Object>> entry1 : dicoHist.entrySet()) {
entry1.getValue().entrySet().removeIf((entry) -> {
return !donnees.contains(entry.getKey());
}); //retire les valeurs qui n'existe pas dans le tableau
}

try {
URL resource = getClass().getClassLoader().getResource("Iot/salles.json");

if (resource == null) {
System.out.println("Le fichier salles.json est introuvable.");
return;
}
}

FileReader reader = new FileReader(Paths.get(resource.toURI()).toFile());
JSONObject jsonObject = (JSONObject) parser.parse(reader);
public void chargerFichierSalle() {

// Test: Afficher le contenu du fichier JSON
System.out.println("Fichier chargé avec succès : ");
// System.out.println(jsonObject.toJSONString()); // Affiche le contenu du JSON
// en format lisible
JSONParser parser = new JSONParser();

// Recherche de la salle B110
if (jsonObject.containsKey("E004")) {
JSONObject salleB110 = (JSONObject) jsonObject.get("E004");
System.out.println(salleB110.toJSONString());
} else {
System.out.println("La salle E004 n'existe pas dans le fichier JSON.");
}
try {
File file = new File("Iot/salles.json");

} catch (Exception e) {
e.printStackTrace();
}
if (!file.exists()) {
Alert alert = new Alert(AlertType.ERROR, "Erreur : Le fichier salles.json est introuvable !");
alert.show();
}

}
// Lire et analyser le fichier JSON
FileReader reader = new FileReader(file);
JSONObject json = (JSONObject) parser.parse(reader);

public void modifConfig() {
// Stocker les données dans la variable
this.sallesData = json;

}
if (json.containsKey(numSalle)) {
JSONObject salleChoisie = (JSONObject) json.get(numSalle);
this.dicoHist = salleChoisie;
//attribut toutes les données existantes dans un dictionnaire

public void lecture() {
// Récupérer toutes les valeurs pour cette clé spécifique
Set<String> allKeys = salleChoisie.keySet();

// Chemin relatif du fichier Python
String pythonScriptPath = "main2.py"; // Le fichier Python est dans le même dossier
JSONObject dernierClé = (JSONObject) salleChoisie.get( (allKeys.size() - 1) + "" );
this.dicoTypeValeur = dernierClé;
//récupère les dernières données de la salle et les attributs à un dictionnaire

// Créer un objet File avec le chemin relatif
File file = new File(pythonScriptPath);
} else {
Alert alert = new Alert(AlertType.ERROR, "Erreur : La salle n'existe pas !");
alert.show();
}

// Vérifier si le fichier existe
if (file.exists())
System.out.println("Le fichier Python existe : " + pythonScriptPath);
else
System.out.println("nexiste pas");
reader.close();

} catch (Exception e) {
System.out.println("Erreur lors du chargement du fichier salles.json : " + e.getMessage());
e.printStackTrace();
}

}

Expand Down
Loading

0 comments on commit f940916

Please sign in to comment.