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 {
@Override
public Assessment getAssessmentDataFromDB(StudentIdentifier student) {
return null;
return new AssessmentDBCommunication().getAssessment(student);
}
@Override
......
......@@ -2,7 +2,6 @@ package unipotsdam.gf.modules.assessment.controller.service;
import unipotsdam.gf.core.database.mysql.MysqlConnect;
import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet;
import unipotsdam.gf.core.management.project.Project;
import unipotsdam.gf.modules.assessment.controller.model.Quiz;
import javax.annotation.ManagedBean;
......@@ -59,6 +58,7 @@ public class QuizDBCommunication {
String oldQuestion="";
Boolean correct;
String mcType = "";
Quiz quiz =null;
while (next) {
mcType = vereinfachtesResultSet.getString("mcType");
question = vereinfachtesResultSet.getString("question");
......@@ -71,9 +71,11 @@ public class QuizDBCommunication {
incorrectAnswers.add(answer);
}
}else{
result.add(new Quiz(mcType,question, correctAnswers, incorrectAnswers));
correctAnswers.clear();
incorrectAnswers.clear();
quiz = new Quiz(mcType,oldQuestion, correctAnswers, incorrectAnswers);
result.add(quiz);
quiz=null;
correctAnswers=new ArrayList<String>();
incorrectAnswers=new ArrayList<String>();
if (correct){
correctAnswers.add(answer);
}else{
......@@ -84,6 +86,8 @@ public class QuizDBCommunication {
oldQuestion = question;
next = vereinfachtesResultSet.next();
}
quiz = new Quiz(mcType,oldQuestion, correctAnswers, incorrectAnswers);
result.add(quiz);
return result;
}
......
......@@ -6,6 +6,7 @@ import unipotsdam.gf.modules.assessment.controller.service.PeerAssessment;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
......@@ -18,8 +19,13 @@ public class QuizView implements IPeerAssessment {
@Path("/project/{projectId}/quiz/{quizId}/author/{author}")
@Override
public Quiz getQuiz(@PathParam("projectId") String projectId, @PathParam("quizId") String quizId, @PathParam("author") String author) {
return peer.getQuiz(projectId, quizId, author);
} ///////////////////////////////funktioniert wie geplant//////////////////////////////////
try{
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
@Produces(MediaType.APPLICATION_JSON)
......@@ -44,7 +50,12 @@ public class QuizView implements IPeerAssessment {
@Path("/quiz/{quizId}")
@Override
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////////////////////////////////////////////////////////
......@@ -57,7 +68,6 @@ public class QuizView implements IPeerAssessment {
peer.addAssessmentDataToDB(assessment);
}
@Override
public Assessment getAssessmentDataFromDB(StudentIdentifier student){
return peer.getAssessmentDataFromDB(student);
......@@ -65,7 +75,7 @@ public class QuizView implements IPeerAssessment {
@GET
@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){
StudentIdentifier student = new StudentIdentifier(projectId, studentId);
return getAssessmentDataFromDB(student);
......
......@@ -26,6 +26,6 @@ $(document).ready(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 () {
},
type: 'POST',
success: function(){
location.href="Quiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
},
error: function(a){
}
});
//document.location = "Quiz.jsp?token=" + getUserTokenFromUrl();
});
});
$(document).ready(function() {
$('#notAllRated').hide();
$(".carousel").carousel({
interval: false
});
......@@ -7,21 +8,34 @@ $(document).ready(function() {
});
});
function getUser(){//todo: you can see what you need to do
return "dummy";
}
function assessPeer(){
///////initialize variables///////
var peerRating = {
"fromPeer": getUser(),
"fromPeer": $('#user').html().trim(),
"toPeer": "",
"workRating": []
};
var dataP = [];
var workRating = [];
var rateThis = ['responsibility','partOfWork','cooperation','communication','autonomous'];
///////read values from html///////
var peerStudents =$('.peerStudent');
for (var i=0; i< peerStudents.length; i++){
peerRating.toPeer = peerStudents[i].id;
peerRating.workRating = [5,4,3,2]
for (var peer=0; peer< peerStudents.length; peer++){
for (var rate=0; rate<rateThis.length; rate++ ){
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);
$.ajax({
......
......@@ -33,7 +33,7 @@ $(document).ready(function () {
var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
var quizId = $_GET['quizId'];
var quizId = encodeURIComponent($_GET['quizId']);
var author = $('#user').html().trim();
var projectId = document.getElementById('projectId').innerText.trim();
$.ajax({
......@@ -67,7 +67,7 @@ $(document).ready(function () {
url: '../rest/assessments/quiz/' + encodeURIComponent(quizId),
type: 'POST',
success: function () {
document.location.href="Quiz.jsp?token="+getUserTokenFromUrl();
document.location.href="Quiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
},
error: function(a){
alert(a)
......
......@@ -145,4 +145,19 @@ CREATE TABLE if not exists quiz
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;
\ 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