From db9aa0d8daf62022a1d53abb693bef30f8d42d18 Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 17 Jan 2024 22:48:19 +0100 Subject: [PATCH] Perfezionamento userReport --- src/main/java/model/DAO/DAOExercise.java | 28 ++++++++----------- .../exercise/ExerciseManagerInterface.java | 8 ++++++ src/main/webapp/JSP/userReport.jsp | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/model/DAO/DAOExercise.java b/src/main/java/model/DAO/DAOExercise.java index 2f9cf06..63a5f3c 100644 --- a/src/main/java/model/DAO/DAOExercise.java +++ b/src/main/java/model/DAO/DAOExercise.java @@ -467,20 +467,14 @@ public boolean deleteMultipleExercise(int userId){ } public Map retrieveAllStatsPatientExerciseDone(int userID) { - String query = "SELECT " + - " eg.Type AS ExerciseType," + - " COUNT(*) AS TotalAssigned," + - " COUNT(e.ID_exercise) AS TotalCompleted," + - " (COUNT(e.ID_exercise) / COUNT(*)) * 100 AS CompletionPercentage " + - "FROM " + - " exercise_glossary eg " + - "LEFT JOIN " + - " exercise e ON eg.ID_exercise = e.ID_exercise " + - " AND e.Recommended <> 0 " + - "WHERE " + - " e.ID_user = ? " + - "GROUP BY " + - " eg.Type;"; + String query = "SELECT eg.Type, " + + "COUNT(CASE WHEN e.CompletionDate IS NOT NULL THEN e.ID_exercise END) as CompletedCount, " + + "COUNT(e.ID_exercise) as TotalAssignedCount, " + + "IFNULL(COUNT(CASE WHEN e.CompletionDate IS NOT NULL THEN e.ID_exercise END) / NULLIF(COUNT(e.ID_exercise), 0) * 100, 0) as CompletionPercentage " + + "FROM exercise_glossary eg " + + "LEFT JOIN exercise e ON eg.ID_exercise = e.ID_exercise AND e.ID_user = ? " + + "GROUP BY eg.Type; "; + PreparedStatement preparedStatement = null; ResultSet resultSet = null; Map result = new HashMap<>(); @@ -493,10 +487,10 @@ public Map retrieveAllStatsPatientExerciseDone(int userID) { resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - String exerciseType = resultSet.getString("ExerciseType"); - int completionPercentage = Math.round((float)resultSet.getDouble("CompletionPercentage")); + String exerciseType = resultSet.getString("Type"); // Fix: Use "Type" instead of "ExerciseType" + int completionPercentage = Math.round((float) resultSet.getDouble("CompletionPercentage")); - result.put(exerciseType,completionPercentage); + result.put(exerciseType, completionPercentage); } } catch (SQLException e) { diff --git a/src/main/java/model/service/exercise/ExerciseManagerInterface.java b/src/main/java/model/service/exercise/ExerciseManagerInterface.java index 14622c9..6b6461f 100644 --- a/src/main/java/model/service/exercise/ExerciseManagerInterface.java +++ b/src/main/java/model/service/exercise/ExerciseManagerInterface.java @@ -7,6 +7,7 @@ import java.sql.Blob; import java.sql.Date; import java.util.List; +import java.util.Map; public interface ExerciseManagerInterface { @@ -66,4 +67,11 @@ public interface ExerciseManagerInterface { */ public List retrieveNotDoneExercises(int patientId); + /** + * Recupera i dati riguardanti gli esercizi proposti dal paziente all'utente. + * + * @param id L'ID del paziente. + * @return Una Map con chiave il tipo di esercizio e valore la percentaule di esercizi fatti rispetto a quelli non fatti. + */ + public Map retrieveAllStats(int id); } diff --git a/src/main/webapp/JSP/userReport.jsp b/src/main/webapp/JSP/userReport.jsp index e5cd03c..668ef07 100644 --- a/src/main/webapp/JSP/userReport.jsp +++ b/src/main/webapp/JSP/userReport.jsp @@ -71,7 +71,7 @@ else { %> %> -
Esercizi non disponibili
+
Non ti sono stati proposti esercizi
<% } %>