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

fix: communication to db for workrating works. does not work for quizzes and contributionRating yet

parent 55234f8c
No related branches found
No related tags found
No related merge requests found
Showing
with 107 additions and 37 deletions
...@@ -4,6 +4,7 @@ import unipotsdam.gf.modules.assessment.QuizAnswer; ...@@ -4,6 +4,7 @@ import unipotsdam.gf.modules.assessment.QuizAnswer;
import unipotsdam.gf.modules.assessment.controller.model.*; import unipotsdam.gf.modules.assessment.controller.model.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -77,10 +78,10 @@ public interface IPeerAssessment { ...@@ -77,10 +78,10 @@ public interface IPeerAssessment {
/** /**
* *
* @param studentAndQuiz * @param questions
* @param quizAnswer * @param student
*/ */
void answerQuiz(StudentAndQuiz studentAndQuiz, QuizAnswer quizAnswer); void answerQuiz(Map<String, List<String>> questions, StudentIdentifier student);
void deleteQuiz(String quizId); void deleteQuiz(String quizId);
Map<StudentIdentifier, Double> calculateAssessment(String projectId, String method); Map<StudentIdentifier, Double> calculateAssessment(String projectId, String method);
......
...@@ -86,6 +86,21 @@ class AssessmentDBCommunication { ...@@ -86,6 +86,21 @@ class AssessmentDBCommunication {
return result; return result;
} }
void writeAnsweredQuiz(StudentIdentifier student, Map<String, Boolean> questions) {
MysqlConnect connect = new MysqlConnect();
connect.connect();
for (String question: questions.keySet()){
String mysqlRequest = "INSERT INTO `answeredquiz`(`projectId`, `studentId`, `question`, `correct`) VALUES (?,?,?,?)";
connect.issueInsertOrDeleteStatement(mysqlRequest,
student.getProjectId(),
student.getStudentId(),
question,
questions.get(question)
);
}
connect.close();
}
void writeWorkRatingToDB(StudentIdentifier student, String fromStudent, Map<String, Integer> workRating) { void writeWorkRatingToDB(StudentIdentifier student, String fromStudent, Map<String, Integer> workRating) {
MysqlConnect connect = new MysqlConnect(); MysqlConnect connect = new MysqlConnect();
connect.connect(); connect.connect();
...@@ -96,7 +111,7 @@ class AssessmentDBCommunication { ...@@ -96,7 +111,7 @@ class AssessmentDBCommunication {
"`communication`, " + "`communication`, " +
"`autonomous`" + "`autonomous`" +
") VALUES (?,?,?,?,?,?,?,?)"; ") VALUES (?,?,?,?,?,?,?,?)";
connect.issueSelectStatement(mysqlRequest, student.getProjectId(), student.getStudentId(), fromStudent, connect.issueInsertOrDeleteStatement(mysqlRequest, student.getProjectId(), student.getStudentId(), fromStudent,
workRating.get("responsibility"), workRating.get("responsibility"),
workRating.get("partOfWork"), workRating.get("partOfWork"),
workRating.get("cooperation"), workRating.get("cooperation"),
...@@ -114,7 +129,7 @@ class AssessmentDBCommunication { ...@@ -114,7 +129,7 @@ class AssessmentDBCommunication {
"`eJournal`, " + "`eJournal`, " +
"`research`" + "`research`" +
") VALUES (?,?,?,?,?,?)"; ") VALUES (?,?,?,?,?,?)";
connect.issueSelectStatement(mysqlRequest, student.getProjectId(), student.getStudentId(), fromStudent, connect.issueInsertOrDeleteStatement(mysqlRequest, student.getProjectId(), student.getStudentId(), fromStudent,
contributionRating.get("Dossier"), contributionRating.get("Dossier"),
contributionRating.get("eJournal"), contributionRating.get("eJournal"),
contributionRating.get("research") contributionRating.get("research")
...@@ -126,7 +141,7 @@ class AssessmentDBCommunication { ...@@ -126,7 +141,7 @@ class AssessmentDBCommunication {
MysqlConnect connect = new MysqlConnect(); MysqlConnect connect = new MysqlConnect();
connect.connect(); connect.connect();
String mysqlRequest = "INSERT INTO `grades`(`projectId`, `studentId`, `grade`) VALUES (?,?,?)"; String mysqlRequest = "INSERT INTO `grades`(`projectId`, `studentId`, `grade`) VALUES (?,?,?)";
connect.issueSelectStatement(mysqlRequest, connect.issueInsertOrDeleteStatement(mysqlRequest,
grade.getStudentIdentifier().getProjectId(), grade.getStudentIdentifier().getProjectId(),
grade.getStudentIdentifier().getStudentId(), grade.getStudentIdentifier().getStudentId(),
grade.getGrade() grade.getGrade()
...@@ -134,17 +149,20 @@ class AssessmentDBCommunication { ...@@ -134,17 +149,20 @@ class AssessmentDBCommunication {
connect.close(); connect.close();
} }
void writeAnsweredQuiz(StudentIdentifier student, String question, Boolean correct) { public Map<String, Boolean> getAnswers(String projectId, String question) {
MysqlConnect connect = new MysqlConnect(); MysqlConnect connect = new MysqlConnect();
connect.connect(); connect.connect();
String mysqlRequest = "INSERT INTO `answeredquiz`(`projectId`, `studentId`, `question`, `correct`) VALUES (?,?,?,?)"; Map<String, Boolean> result = new HashMap<>();
connect.issueSelectStatement(mysqlRequest, String mysqlRequest = "SELECT * FROM `quiz` WHERE `projectId`=? AND `question`=?";
student.getProjectId(), VereinfachtesResultSet vereinfachtesResultSet =
student.getStudentId(), connect.issueSelectStatement(mysqlRequest, projectId, question);
question, boolean next = vereinfachtesResultSet.next();
correct while (next) {
); result.put(vereinfachtesResultSet.getString("answer"), vereinfachtesResultSet.getBoolean("correct"));
next = vereinfachtesResultSet.next();
}
connect.close(); connect.close();
return result;
} }
} }
...@@ -4,6 +4,7 @@ import unipotsdam.gf.modules.assessment.QuizAnswer; ...@@ -4,6 +4,7 @@ import unipotsdam.gf.modules.assessment.QuizAnswer;
import unipotsdam.gf.modules.assessment.controller.model.*; import unipotsdam.gf.modules.assessment.controller.model.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -60,7 +61,7 @@ public class FBAssessement extends AssessmentDAO { ...@@ -60,7 +61,7 @@ public class FBAssessement extends AssessmentDAO {
} }
@Override @Override
public void answerQuiz(StudentAndQuiz studentAndQuiz, QuizAnswer quizAnswer) { public void answerQuiz(Map<String, List<String>> questions, StudentIdentifier student) {
} }
......
...@@ -202,13 +202,24 @@ public class PeerAssessment implements IPeerAssessment { ...@@ -202,13 +202,24 @@ public class PeerAssessment implements IPeerAssessment {
public void postPeerRating(ArrayList<PeerRating> peerRatings, String projectId) { public void postPeerRating(ArrayList<PeerRating> peerRatings, String projectId) {
for (PeerRating peer: peerRatings){ for (PeerRating peer: peerRatings){
StudentIdentifier student = new StudentIdentifier(projectId, peer.getToPeer()); StudentIdentifier student = new StudentIdentifier(projectId, peer.getToPeer());
//new AssessmentDBCommunication().writeWorkRatingToDB(student, peerRatings.get(1).getFromPeer(), peerRatings.get(1).getWorkRating()); new AssessmentDBCommunication().writeWorkRatingToDB(student, peerRatings.get(1).getFromPeer(), peerRatings.get(1).getWorkRating());
} }
} }
@Override @Override
public void answerQuiz(StudentAndQuiz studentAndQuiz, QuizAnswer quizAnswer) { public void answerQuiz(Map<String, List<String>> questions, StudentIdentifier student) {
for (String question: questions.keySet()){
Map<String, Boolean> whatAreAnswers = new AssessmentDBCommunication().getAnswers(student.getProjectId(), question);
Map<String, Boolean> wasQuestionAnsweredCorrectly = new HashMap<>();
Boolean correct = true;
for (String studentAnswer: questions.get(question)){
if (!whatAreAnswers.get(studentAnswer)){
correct=false;
}
}
wasQuestionAnsweredCorrectly.put(question, correct);
new AssessmentDBCommunication().writeAnsweredQuiz(student, wasQuestionAnsweredCorrectly);
}
} }
private Comparator<Map<String, Double>> byMean = (o1, o2) -> { private Comparator<Map<String, Double>> byMean = (o1, o2) -> {
......
...@@ -66,7 +66,7 @@ public class PeerAssessmentDummy implements IPeerAssessment { ...@@ -66,7 +66,7 @@ public class PeerAssessmentDummy implements IPeerAssessment {
} }
@Override @Override
public void answerQuiz(StudentAndQuiz studentAndQuiz, QuizAnswer quizAnswer) { public void answerQuiz(Map<String, List<String>> questions, StudentIdentifier student) {
NotImplementedLogger.logAssignment(Assignee.AXEL, IPeerAssessment.class); NotImplementedLogger.logAssignment(Assignee.AXEL, IPeerAssessment.class);
} }
...@@ -124,23 +124,23 @@ public class PeerAssessmentDummy implements IPeerAssessment { ...@@ -124,23 +124,23 @@ public class PeerAssessmentDummy implements IPeerAssessment {
quiz2.add(1); quiz2.add(1);
quiz2.add(0); quiz2.add(0);
quiz2.add(0); quiz2.add(0);
Map work = new HashMap<String, Double>(); Map<String, Double> work = new HashMap<>();
work.put("responsibility", 1.); work.put("responsibility", 1.);
work.put("partOfWork", 1.); work.put("partOfWork", 1.);
work.put("cooperation", 1.); work.put("cooperation", 1.);
work.put("communication", 1.); work.put("communication", 1.);
work.put("autonomous", 1.); work.put("autonomous", 1.);
Map work2 = new HashMap<String, Double>(); Map<String, Double> work2 = new HashMap<>();
work2.put("responsibility", 3.); work2.put("responsibility", 3.);
work2.put("partOfWork", 4.); work2.put("partOfWork", 4.);
work2.put("cooperation", 5.); work2.put("cooperation", 5.);
work2.put("communication", 3.); work2.put("communication", 3.);
work2.put("autonomous", 4.); work2.put("autonomous", 4.);
Map contribution1 = new HashMap<String, Double>(); Map<String, Double> contribution1 = new HashMap<>();
contribution1.put("Dossier", 4.); contribution1.put("Dossier", 4.);
contribution1.put("eJournal", 2.); contribution1.put("eJournal", 2.);
contribution1.put("research", 4.); contribution1.put("research", 4.);
Map contribution2 = new HashMap<String, Double>(); Map<String, Double> contribution2 = new HashMap<>();
contribution2.put("Dossier", 2.); contribution2.put("Dossier", 2.);
contribution2.put("eJournal", 3.); contribution2.put("eJournal", 3.);
contribution2.put("research", 4.); contribution2.put("research", 4.);
......
...@@ -46,8 +46,12 @@ public class QuizView { ...@@ -46,8 +46,12 @@ public class QuizView {
peer.postPeerRating(peerRatings, projectId); peer.postPeerRating(peerRatings, projectId);
} }
public void answerQuiz(StudentAndQuiz studentAndQuiz, QuizAnswer quizAnswer) { @POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/quizAnswer/projectId/{projectId}/studentId/{studentId}/")
public void answerQuiz(Map<String, List<String>> questions, @PathParam("projectId") String projectId, @PathParam("studentId") String studentId) {
StudentIdentifier student = new StudentIdentifier(projectId, studentId);
peer.answerQuiz(questions, student);
} }
@POST @POST
......
...@@ -9,14 +9,14 @@ $(document).ready(function() { ...@@ -9,14 +9,14 @@ $(document).ready(function() {
}); });
function assessPeer(){ function assessPeer(){
var peerStudents =$('.peerStudent');
///////initialize variables/////// ///////initialize variables///////
var dataP = []; var dataP = new Array(peerStudents.size());
var workRating = {};
var rateThis = ['responsibility','partOfWork','cooperation','communication','autonomous']; var rateThis = ['responsibility','partOfWork','cooperation','communication','autonomous'];
///////read values from html/////// ///////read values from html///////
var peerStudents =$('.peerStudent');
for (var peer=0; peer< peerStudents.length; peer++){ for (var peer=0; peer< peerStudents.length; peer++){
var workRating = {};
var peerRating = { var peerRating = {
"fromPeer": $('#user').html().trim(), "fromPeer": $('#user').html().trim(),
"toPeer": peerStudents[peer].id, "toPeer": peerStudents[peer].id,
...@@ -33,9 +33,8 @@ function assessPeer(){ ...@@ -33,9 +33,8 @@ function assessPeer(){
} }
} }
peerRating.workRating = workRating; peerRating.workRating = workRating;
workRating=[];
//////write values in Post-Variable //////write values in Post-Variable
dataP.push(peerRating); dataP[peer]=peerRating;
} }
var projectId=$('#projectId').html().trim(); var projectId=$('#projectId').html().trim();
$.ajax({ $.ajax({
......
...@@ -29,6 +29,7 @@ $(document).ready(function () { ...@@ -29,6 +29,7 @@ $(document).ready(function () {
}; };
var projectId = document.getElementById('projectId').innerText.trim(); var projectId = document.getElementById('projectId').innerText.trim();
var studentId = document.getElementById('user').innerText.trim();
$.ajax({ $.ajax({
url: '../rest/assessments/project/'+projectId+'/quiz/', url: '../rest/assessments/project/'+projectId+'/quiz/',
type: 'GET', type: 'GET',
...@@ -40,7 +41,7 @@ $(document).ready(function () { ...@@ -40,7 +41,7 @@ $(document).ready(function () {
var colspan = answers.length; var colspan = answers.length;
var trQuestion = document.createElement('TR'); var trQuestion = document.createElement('TR');
var tdQuestion = '<td colspan="' + colspan + '"' + var tdQuestion = '<td colspan="' + colspan + '"' +
'data-toggle="collapse" href="#'+question+'" aria-expanded="false" aria-controls="'+question+'">' + ' data-toggle="collapse" href="#'+question+'" aria-expanded="false" aria-controls="'+question+'">' +
'' + data[quiz].question + '</td>'; '' + data[quiz].question + '</td>';
trQuestion.innerHTML = tdQuestion; trQuestion.innerHTML = tdQuestion;
var trAnswers = document.createElement('TR'); var trAnswers = document.createElement('TR');
...@@ -64,12 +65,12 @@ $(document).ready(function () { ...@@ -64,12 +65,12 @@ $(document).ready(function () {
table.appendChild(trAnswers); table.appendChild(trAnswers);
} }
}, },
error: function (a, b, c) { error: function (a) {
alert('Fehler ' + a); alert('Fehler ' + a);
} }
}); });
$("#submitQuiz").on("click", function () { $("#submitQuiz").on("click", function () {
document.location="rateContribution.jsp?token="+getUserTokenFromUrl()+'&projectId='+$('#projectId').html().trim(); safeQuizAnswers();
}); });
}); });
...@@ -82,4 +83,39 @@ function shuffle(a) { ...@@ -82,4 +83,39 @@ function shuffle(a) {
a[j] = x; a[j] = x;
} }
return a; return a;
}
function safeQuizAnswers(){ //todo: just written before going home. not tested yet, wont work
var quizzes = $('.quiz');
///////initialize variables///////
var dataP = new Array(quizzes.size());
///////read values from html///////
for (var quiz=0; quiz<quizzes.size(); quiz++){
var answerList = [];
$(quizzes[quiz]+":input:checkbox[name=type]:checked").each(function(){
answerList.push($(this).val());
});
var question = quizzes[quiz].id;
var quizAnswers={question: answerList};
//////write values in Post-Variable
dataP[quiz]=quizAnswers;
}
var projectId=$('#projectId').html().trim();
var studentId=$('#user').html().trim();
$.ajax({
url:'../rest/assessments/quizAnswer/projectId/'+projectId+'/studentId/'+studentId,
type: 'POST',
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-cache"
},
data: JSON.stringify(dataP),
success: function(){
location.href="takeQuiz.jsp?token="+getUserTokenFromUrl()+"&projectId="+$('#projectId').html().trim();
},
error: function(a,b,c){
}
});
} }
\ No newline at end of file
...@@ -171,10 +171,10 @@ public class ActivityFlowTest { ...@@ -171,10 +171,10 @@ public class ActivityFlowTest {
// create quiz TODO@Axel this should be a quiz dependend on the student for easier initialization and // create quiz TODO@Axel this should be a quiz dependend on the student for easier initialization and
// de-coupling // de-coupling
StudentAndQuiz studentAndQuiz = factory.manufacturePojo(StudentAndQuiz.class); //StudentAndQuiz studentAndQuiz = factory.manufacturePojo(StudentAndQuiz.class);
QuizAnswer quizAnswer = factory.manufacturePojo(QuizAnswer.class); //QuizAnswer quizAnswer = factory.manufacturePojo(QuizAnswer.class);
iPeerAssessment.createQuiz(studentAndQuiz); //iPeerAssessment.createQuiz(studentAndQuiz);
iPeerAssessment.answerQuiz(studentAndQuiz, quizAnswer); //iPeerAssessment.answerQuiz(studentAndQuiz, quizAnswer);
// finales Portfolio zusammenstellen // finales Portfolio zusammenstellen
java.util.List<Journal> journalEntries = new ArrayList<Journal>(); java.util.List<Journal> journalEntries = new ArrayList<Journal>();
......
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