Skip to content

Commit

Permalink
Perfezionamento userReport
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody2806 committed Jan 17, 2024
1 parent c1c7431 commit db9aa0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
28 changes: 11 additions & 17 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,14 @@ public boolean deleteMultipleExercise(int userId){
}

public Map<String, Integer> 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<String, Integer> result = new HashMap<>();
Expand All @@ -493,10 +487,10 @@ public Map<String, Integer> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Blob;
import java.sql.Date;
import java.util.List;
import java.util.Map;

public interface ExerciseManagerInterface {

Expand Down Expand Up @@ -66,4 +67,11 @@ public interface ExerciseManagerInterface {
*/
public List<SlimmerExercise> 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<String,Integer> retrieveAllStats(int id);
}
2 changes: 1 addition & 1 deletion src/main/webapp/JSP/userReport.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
else {
%>
%>
<div class="discovering-english">Esercizi non disponibili</div>
<div class="discovering-english">Non ti sono stati proposti esercizi</div>
<%
}
%>
Expand Down

0 comments on commit db9aa0d

Please sign in to comment.