Skip to content
Snippets Groups Projects
Commit c2d60979 authored by Axel's avatar Axel
Browse files

fix: getQuizzes from DB was corrupted

feat: workRating for peers are written to DB
feat: 2 new tables in DB
parent 52b6a3ba
No related branches found
No related tags found
No related merge requests found
Showing
with 285 additions and 116 deletions
package unipotsdam.gf.modules.assessment.controller.service;
import unipotsdam.gf.core.database.mysql.MysqlConnect;
import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet;
import unipotsdam.gf.modules.assessment.controller.model.Assessment;
import unipotsdam.gf.modules.assessment.controller.model.Performance;
import unipotsdam.gf.modules.assessment.controller.model.Quiz;
import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
import javax.annotation.ManagedBean;
import javax.annotation.Resource;
import javax.inject.Singleton;
import java.util.ArrayList;
@ManagedBean
@Resource
@Singleton
public class AssessmentDBCommunication {
public Assessment getAssessment(StudentIdentifier student){
MysqlConnect connect = new MysqlConnect();
connect.connect();
String mysqlRequest = "SELECT * FROM `peerAssessment` WHERE `projectId`=? AND `studentId`=?";
VereinfachtesResultSet vereinfachtesResultSet =
connect.issueSelectStatement(mysqlRequest, student.getProjectId(), student.getStudentId());
boolean next = vereinfachtesResultSet.next();
String question = "";
ArrayList<String> correctAnswers = new ArrayList<String>();
ArrayList<String> incorrectAnswers = new ArrayList<String>();
String answer;
Boolean correct;
String mcType = "";
while (next) {
mcType = vereinfachtesResultSet.getString("mcType");
question = vereinfachtesResultSet.getString("question");
answer = vereinfachtesResultSet.getString("answer");
correct = vereinfachtesResultSet.getBoolean("correct");
if (correct){
correctAnswers.add(answer);
}else{
incorrectAnswers.add(answer);
}
next = vereinfachtesResultSet.next();
}
Performance performance=null;
Assessment assessment = new Assessment(student, performance);
connect.close();
return assessment;
}
public void deleteQuiz(String quizId) {
MysqlConnect connect = new MysqlConnect();
connect.connect();
String mysqlRequest = "DELETE FROM quiz where question = (?)";
connect.issueInsertOrDeleteStatement(mysqlRequest, quizId);
connect.close();
}
}
...@@ -26,7 +26,7 @@ public class PeerAssessment implements IPeerAssessment { ...@@ -26,7 +26,7 @@ public class PeerAssessment implements IPeerAssessment {
@Override @Override
public Assessment getAssessmentDataFromDB(StudentIdentifier student) { public Assessment getAssessmentDataFromDB(StudentIdentifier student) {
return null; return new AssessmentDBCommunication().getAssessment(student);
} }
@Override @Override
......
...@@ -2,7 +2,6 @@ package unipotsdam.gf.modules.assessment.controller.service; ...@@ -2,7 +2,6 @@ package unipotsdam.gf.modules.assessment.controller.service;
import unipotsdam.gf.core.database.mysql.MysqlConnect; import unipotsdam.gf.core.database.mysql.MysqlConnect;
import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet; import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet;
import unipotsdam.gf.core.management.project.Project;
import unipotsdam.gf.modules.assessment.controller.model.Quiz; import unipotsdam.gf.modules.assessment.controller.model.Quiz;
import javax.annotation.ManagedBean; import javax.annotation.ManagedBean;
...@@ -59,6 +58,7 @@ public class QuizDBCommunication { ...@@ -59,6 +58,7 @@ public class QuizDBCommunication {
String oldQuestion=""; String oldQuestion="";
Boolean correct; Boolean correct;
String mcType = ""; String mcType = "";
Quiz quiz =null;
while (next) { while (next) {
mcType = vereinfachtesResultSet.getString("mcType"); mcType = vereinfachtesResultSet.getString("mcType");
question = vereinfachtesResultSet.getString("question"); question = vereinfachtesResultSet.getString("question");
...@@ -71,9 +71,11 @@ public class QuizDBCommunication { ...@@ -71,9 +71,11 @@ public class QuizDBCommunication {
incorrectAnswers.add(answer); incorrectAnswers.add(answer);
} }
}else{ }else{
result.add(new Quiz(mcType,question, correctAnswers, incorrectAnswers)); quiz = new Quiz(mcType,oldQuestion, correctAnswers, incorrectAnswers);
correctAnswers.clear(); result.add(quiz);
incorrectAnswers.clear(); quiz=null;
correctAnswers=new ArrayList<String>();
incorrectAnswers=new ArrayList<String>();
if (correct){ if (correct){
correctAnswers.add(answer); correctAnswers.add(answer);
}else{ }else{
...@@ -84,6 +86,8 @@ public class QuizDBCommunication { ...@@ -84,6 +86,8 @@ public class QuizDBCommunication {
oldQuestion = question; oldQuestion = question;
next = vereinfachtesResultSet.next(); next = vereinfachtesResultSet.next();
} }
quiz = new Quiz(mcType,oldQuestion, correctAnswers, incorrectAnswers);
result.add(quiz);
return result; return result;
} }
......
...@@ -6,6 +6,7 @@ import unipotsdam.gf.modules.assessment.controller.service.PeerAssessment; ...@@ -6,6 +6,7 @@ import unipotsdam.gf.modules.assessment.controller.service.PeerAssessment;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -18,8 +19,13 @@ public class QuizView implements IPeerAssessment { ...@@ -18,8 +19,13 @@ public class QuizView implements IPeerAssessment {
@Path("/project/{projectId}/quiz/{quizId}/author/{author}") @Path("/project/{projectId}/quiz/{quizId}/author/{author}")
@Override @Override
public Quiz getQuiz(@PathParam("projectId") String projectId, @PathParam("quizId") String quizId, @PathParam("author") String author) { public Quiz getQuiz(@PathParam("projectId") String projectId, @PathParam("quizId") String quizId, @PathParam("author") String author) {
return peer.getQuiz(projectId, quizId, author); try{
} ///////////////////////////////funktioniert wie geplant////////////////////////////////// String question=java.net.URLDecoder.decode(quizId,"UTF-8");
return peer.getQuiz(projectId, question, author);
}catch(UnsupportedEncodingException e){
throw new AssertionError("UTF-8 is unknown");
}
} ///////////////////////////////funktioniert//////////////////////////////////
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
...@@ -44,7 +50,12 @@ public class QuizView implements IPeerAssessment { ...@@ -44,7 +50,12 @@ public class QuizView implements IPeerAssessment {
@Path("/quiz/{quizId}") @Path("/quiz/{quizId}")
@Override @Override
public void deleteQuiz(@PathParam("quizId") String quizId) { public void deleteQuiz(@PathParam("quizId") String quizId) {
peer.deleteQuiz(quizId); try {
String question = java.net.URLDecoder.decode(quizId, "UTF-8");
peer.deleteQuiz(question);
}catch(UnsupportedEncodingException e){
throw new AssertionError("UTF-8 is unknown");
}
} }
////////////////////////////funktioniert//////////////////////////////////////////////////////// ////////////////////////////funktioniert////////////////////////////////////////////////////////
...@@ -57,7 +68,6 @@ public class QuizView implements IPeerAssessment { ...@@ -57,7 +68,6 @@ public class QuizView implements IPeerAssessment {
peer.addAssessmentDataToDB(assessment); peer.addAssessmentDataToDB(assessment);
} }
@Override @Override
public Assessment getAssessmentDataFromDB(StudentIdentifier student){ public Assessment getAssessmentDataFromDB(StudentIdentifier student){
return peer.getAssessmentDataFromDB(student); return peer.getAssessmentDataFromDB(student);
...@@ -65,7 +75,7 @@ public class QuizView implements IPeerAssessment { ...@@ -65,7 +75,7 @@ public class QuizView implements IPeerAssessment {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/project/{projectId}/student/{studentId}") @Path("/get/project/{projectId}/student/{studentId}")
public Assessment getAssessmentDataFromDB(@PathParam("projectId") String projectId,@PathParam("studentId") String studentId){ public Assessment getAssessmentDataFromDB(@PathParam("projectId") String projectId,@PathParam("studentId") String studentId){
StudentIdentifier student = new StudentIdentifier(projectId, studentId); StudentIdentifier student = new StudentIdentifier(projectId, studentId);
return getAssessmentDataFromDB(student); return getAssessmentDataFromDB(student);
......
...@@ -26,6 +26,6 @@ $(document).ready(function(){ ...@@ -26,6 +26,6 @@ $(document).ready(function(){
}); });
$('#newQuiz').on('click', function(){ $('#newQuiz').on('click', function(){
location.href="createQuiz.jsp?token="+getUserTokenFromUrl(); location.href="createQuiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
}); });
}); });
...@@ -61,12 +61,11 @@ $(document).ready(function () { ...@@ -61,12 +61,11 @@ $(document).ready(function () {
}, },
type: 'POST', type: 'POST',
success: function(){ success: function(){
location.href="Quiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
}, },
error: function(a){ error: function(a){
} }
}); });
//document.location = "Quiz.jsp?token=" + getUserTokenFromUrl();
}); });
}); });
$(document).ready(function() { $(document).ready(function() {
$('#notAllRated').hide();
$(".carousel").carousel({ $(".carousel").carousel({
interval: false interval: false
}); });
...@@ -7,21 +8,34 @@ $(document).ready(function() { ...@@ -7,21 +8,34 @@ $(document).ready(function() {
}); });
}); });
function getUser(){//todo: you can see what you need to do
return "dummy";
}
function assessPeer(){ function assessPeer(){
///////initialize variables///////
var peerRating = { var peerRating = {
"fromPeer": getUser(), "fromPeer": $('#user').html().trim(),
"toPeer": "", "toPeer": "",
"workRating": [] "workRating": []
}; };
var dataP = []; var dataP = [];
var workRating = [];
var rateThis = ['responsibility','partOfWork','cooperation','communication','autonomous'];
///////read values from html///////
var peerStudents =$('.peerStudent'); var peerStudents =$('.peerStudent');
for (var i=0; i< peerStudents.length; i++){ for (var peer=0; peer< peerStudents.length; peer++){
peerRating.toPeer = peerStudents[i].id; for (var rate=0; rate<rateThis.length; rate++ ){
peerRating.workRating = [5,4,3,2] workRating.push($('input[name='+rateThis[rate]+peerStudents[peer].id+']:checked').val());
}
for (var i=0; i<workRating.length; i++){
if(workRating[i]===undefined){
$('#notAllRated').show();
return;
}
}
peerRating.toPeer = peerStudents[peer].id;
peerRating.workRating = workRating;
workRating=[];
//////write values in Post-Variable
dataP.push(peerRating);
} }
dataP.push(peerRating); dataP.push(peerRating);
$.ajax({ $.ajax({
......
...@@ -33,7 +33,7 @@ $(document).ready(function () { ...@@ -33,7 +33,7 @@ $(document).ready(function () {
var temp = parts[i].split("="); var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]); $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
} }
var quizId = $_GET['quizId']; var quizId = encodeURIComponent($_GET['quizId']);
var author = $('#user').html().trim(); var author = $('#user').html().trim();
var projectId = document.getElementById('projectId').innerText.trim(); var projectId = document.getElementById('projectId').innerText.trim();
$.ajax({ $.ajax({
...@@ -67,7 +67,7 @@ $(document).ready(function () { ...@@ -67,7 +67,7 @@ $(document).ready(function () {
url: '../rest/assessments/quiz/' + encodeURIComponent(quizId), url: '../rest/assessments/quiz/' + encodeURIComponent(quizId),
type: 'POST', type: 'POST',
success: function () { success: function () {
document.location.href="Quiz.jsp?token="+getUserTokenFromUrl(); document.location.href="Quiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
}, },
error: function(a){ error: function(a){
alert(a) alert(a)
......
...@@ -145,4 +145,19 @@ CREATE TABLE if not exists quiz ...@@ -145,4 +145,19 @@ CREATE TABLE if not exists quiz
ENGINE = InnoDB ENGINE = InnoDB
DEFAULT CHARSET = utf8;
CREATE TABLE if not exists grades
(
projectId varchar(400) NOT NULL,
studentId varchar(400) NOT NULL,
grade double NOT NULL
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8; DEFAULT CHARSET = utf8;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment