Skip to content

Commit

Permalink
userReport page and function
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody2806 committed Jan 17, 2024
1 parent e2646cb commit c5866de
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/controller/AddRemovePatientCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@WebServlet("/AddRemovePatientCondition")
public class AddRemovePatientCondition extends HttpServlet {

//mammt
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String referer = request.getHeader("Referer");
ConditionManager conditionService= new ConditionManager();
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* The DAOExercise class provides methods for retrieving Exercise information from a database.
Expand Down Expand Up @@ -464,5 +466,52 @@ 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;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
Map<String, Integer> result = new HashMap<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, userID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
String exerciseType = resultSet.getString("ExerciseType");
int completionPercentage = Math.round((float)resultSet.getDouble("CompletionPercentage"));

result.put(exerciseType,completionPercentage);
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}

return result;
}

}
6 changes: 6 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.sql.Blob;
import java.sql.Date;
import java.util.List;
import java.util.Map;

public class ExerciseManager implements ExerciseManagerInterface {
private final DAOExerciseGlossary daoEG = new DAOExerciseGlossary();
Expand Down Expand Up @@ -63,4 +64,9 @@ public boolean changeMultipleReccomandation(String action, int userId){
return daoE.deleteMultipleExercise(userId);
}
}

public Map<String,Integer> retrieveAllStats(int id)
{
return daoE.retrieveAllStatsPatientExerciseDone(id);
}
}
92 changes: 92 additions & 0 deletions src/main/webapp/JSP/userReport.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<%@ page import="model.service.exercise.ExerciseManager" %>
<%@ page import="model.entity.Exercise" %>
<%@ page import="java.util.List" %>
<%@ page import="model.entity.ExerciseGlossary" %>
<%@ page import="java.util.Map" %>
<!DOCTYPE html>
<html lang="it" style="background-color: #f7fcff; ">
<%
Integer userIdp = (Integer) session.getAttribute("id");
if(userIdp == null) {
response.sendRedirect("../errorPage/403.html");
}
else {
int userId = (Integer) session.getAttribute("id");
%>
<head>
<%@page contentType="text/html;charset=UTF-8"%>
<meta charset="utf-8" />
<link href="../CSS/userReport.css" type="text/css" rel = "stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>
<body>
<script>
let varcalc;
</script>
<div class="container">
<div class="up">
<div class="div_up">
<img src="../Image/pngwing.com.png" id="back">
<h2>Report del vostro progresso</h2>
</div>
</div>
<img src="../Image/profilo_utente.png" id="paziente">
<div class="down">
<div class="container">
<div class="margin20">
<div class="navigation-title">
<div class="current-lesson">Resoconto progressi:</div>
</div>
</div>

<%
ExerciseManager exerciseManager = new ExerciseManager();
Map<String,Integer> dict = exerciseManager.retrieveAllStats((int)session.getAttribute("id"));
if(!dict.isEmpty()){
int Counter = 0;
for(Map.Entry<String, Integer> exercise : dict.entrySet()) {
%>
<div class="prova">
<h2><%= exercise.getKey()%></h2>
<svg class="eimg" width="160" height="160" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>

<circle id="circle_animation<%=Counter%>" class="circle_animation" r="69.85699" cy="81" cx="81" stroke-width="8" stroke="#6fdb6f" fill="none"></circle>
<text x="81" y="81" font-size="30" text-anchor="middle" dominant-baseline="middle" fill="green"><%=exercise.getValue()%>%</text>
</g>
</svg>
</div>

<script>
varcalc= (440 / 100 * <%=exercise.getValue()%>)+440;
document.querySelector('#circle_animation<%=Counter%>').style.strokeDashoffset = varcalc; // 50%
</script>
<%
Counter++;
}
}
else {
%>
%>
<div class="discovering-english">Esercizi non disponibili</div>
<%
}
%>

</div>
<div>
<jsp:include page="navbar.jsp"></jsp:include>
<div id="userInfo" hidden
data-type = "<%= session.getAttribute("type")%>"
></div>
</div>
</div>
</div>
</body>
</html>
<%
}
%>

0 comments on commit c5866de

Please sign in to comment.