diff --git a/src/main/java/com/example/exammen/Controller/RestController.java b/src/main/java/com/example/exammen/Controller/RestController.java index 9b6d5af..0466ea8 100644 --- a/src/main/java/com/example/exammen/Controller/RestController.java +++ b/src/main/java/com/example/exammen/Controller/RestController.java @@ -11,6 +11,7 @@ import java.lang.reflect.Array; import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,10 +77,9 @@ public double calculateCorrelation() { return i.calculateCorrelation(circonfData, ageData); } @GetMapping("/arbres-density") - public String calculateArbresDensityByQuartier(Model model) { - Map quartierDensityMap = i.calculateArbresDensityByQuartier(); - model.addAttribute("quartierDensityMap", quartierDensityMap); - return "arbresd"; // Ceci correspondra au nom du fichier HTML (arbres-density.html) + public ResponseEntity> getArbresDensityByArrondissement() { + Map densityMap = i.calculateArbresDensityByQuartier(); + return ResponseEntity.ok(densityMap); } @PostMapping("/ajouter") @@ -98,4 +98,22 @@ public String distributionEspeces(Model model) { model.addAttribute("especesCount", especesCount); return "dis"; // Nom de la vue HTML } + + @GetMapping("/arbres-genres-photos") + @ResponseBody + public List getArbresGenresAndPhotos() { + return i.getAllGenresAndPhotos(); + } + + @GetMapping("/pie-chart") + public ResponseEntity> generatePieChart() { + Map data = new HashMap<>(); + List genres = i.getAllGenres(); + List counts = i.getCountByGenre(); + + data.put("genres", genres); + data.put("counts", counts); + + return ResponseEntity.ok(data); + } } diff --git a/src/main/java/com/example/exammen/Repository/ArbresRepository.java b/src/main/java/com/example/exammen/Repository/ArbresRepository.java index c667e7c..e154fa0 100644 --- a/src/main/java/com/example/exammen/Repository/ArbresRepository.java +++ b/src/main/java/com/example/exammen/Repository/ArbresRepository.java @@ -10,9 +10,10 @@ import java.util.List; @Repository -public interface ArbresRepository extends JpaRepository{ +public interface ArbresRepository extends JpaRepository { List findByArbresDomanialite(String arbresDomanialite); + List findByArbresDomanialiteContaining(String arbresDomanialite); @Query("SELECT a.arbresCirconferenceencm FROM Arbres a") @@ -26,5 +27,5 @@ public interface ArbresRepository extends JpaRepository{ List countArbresByEspece(); - + long countByArbresGenre(String genre); } diff --git a/src/main/java/com/example/exammen/Service/IService.java b/src/main/java/com/example/exammen/Service/IService.java index 74ced71..ba02541 100644 --- a/src/main/java/com/example/exammen/Service/IService.java +++ b/src/main/java/com/example/exammen/Service/IService.java @@ -19,4 +19,10 @@ public interface IService { void deleteArbreByArbresIdbase(BigDecimal arbresIdbase); public List countArbresByEspece(); + + public List getAllGenresAndPhotos(); + + public List getAllGenres(); + public List getCountByGenre(); + } diff --git a/src/main/java/com/example/exammen/Service/ServiceImpl.java b/src/main/java/com/example/exammen/Service/ServiceImpl.java index aaaa867..68313a0 100644 --- a/src/main/java/com/example/exammen/Service/ServiceImpl.java +++ b/src/main/java/com/example/exammen/Service/ServiceImpl.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @AllArgsConstructor @@ -96,4 +97,23 @@ public List countArbresByEspece() { return arbrerepo.countArbresByEspece(); } + @Override + public List getAllGenresAndPhotos() { + return arbrerepo.findAll(); + } + + @Override + public List getAllGenres() { + return getAllArbres().stream() + .map(Arbres::getArbresGenre) + .distinct() + .collect(Collectors.toList()); + } + + @Override + public List getCountByGenre() { + return getAllGenres().stream() + .map(genre -> arbrerepo.countByArbresGenre(genre)) + .collect(Collectors.toList()); + } } diff --git a/src/main/resources/static/arbresd.html b/src/main/resources/static/arbresd.html index 2edb027..49b94b1 100644 --- a/src/main/resources/static/arbresd.html +++ b/src/main/resources/static/arbresd.html @@ -29,7 +29,7 @@

Densité des Arbres par Quartier

var canvas = document.getElementById("densityChart"); var ctx = canvas.getContext("2d"); - // Créez le graphique à barres en utilisant Chart.js + var densityChart = new Chart(ctx, { type: 'bar', // Type de graphique : barres data: { diff --git a/src/main/resources/static/densi.html b/src/main/resources/static/densi.html new file mode 100644 index 0000000..411188d --- /dev/null +++ b/src/main/resources/static/densi.html @@ -0,0 +1,64 @@ + + + + + Densité des Arbres par Arrondissement + + + + +

Densité des Arbres par Arrondissement

+ + + + + + + diff --git a/src/main/resources/static/genre.html b/src/main/resources/static/genre.html new file mode 100644 index 0000000..9c0b70e --- /dev/null +++ b/src/main/resources/static/genre.html @@ -0,0 +1,93 @@ + + + + + Genres d'arbres et photos + + + +

Genres d'arbres et leurs photos

+ + + + + + + + + + +
Genre d'arbrePhoto
+ + + + diff --git a/src/main/resources/static/pie.html b/src/main/resources/static/pie.html new file mode 100644 index 0000000..995fbf4 --- /dev/null +++ b/src/main/resources/static/pie.html @@ -0,0 +1,61 @@ + + + + + Pie Chart des Genres d'Arbres + + + + +

Pie Chart des Genres d'Arbres

+
+ + +
+ + + + +