From be212d7e69f6821391a9ad5a564712f5b5914b1c Mon Sep 17 00:00:00 2001
From: Axel <wiepke@uni-potsdam.de>
Date: Thu, 26 Jul 2018 11:06:59 +0200
Subject: [PATCH] feat: calculate assessment for finalized project works as a
 dummy

---
 .../controller/service/PeerAssessment.java    | 47 +++++++++++++++++--
 .../service/PeerAssessmentDummy.java          |  2 +-
 .../assessment/controller/view/QuizView.java  |  1 +
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessment.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessment.java
index 7b0d3bd0..fe4f1845 100644
--- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessment.java
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessment.java
@@ -2,10 +2,9 @@ package unipotsdam.gf.modules.assessment.controller.service;
 
 import unipotsdam.gf.interfaces.IPeerAssessment;
 import unipotsdam.gf.modules.assessment.controller.model.*;
-import unipotsdam.gf.core.database.mysql.MysqlConnect;
-import unipotsdam.gf.modules.assessment.controller.service.QuizDBCommunication;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 public class PeerAssessment implements IPeerAssessment {
@@ -41,7 +40,49 @@ public class PeerAssessment implements IPeerAssessment {
 
     @Override
     public List<Grading> calculateAssessment(ArrayList<Performance> totalPerformance) {
-        return null;
+        List<Grading> quizMean = meanOfQuizzes(totalPerformance);
+        List<Grading> workRateMean = meanOfWorkRate(totalPerformance);
+        Grading[] grading = new Grading[totalPerformance.size()];
+        for (int i=0; i<quizMean.size(); i++){
+            double grade = quizMean.get(i).getGrade() * workRateMean.get(i).getGrade();
+            grading[i] = new Grading(totalPerformance.get(i).getStudentIdentifier(), grade);
+        }
+
+        return Arrays.asList(grading);
+    }
+
+    private List<Grading> meanOfQuizzes(ArrayList<Performance> totalPerformance){
+        double[] allAssessments = new double[totalPerformance.size()];
+        Grading[] grading = new Grading[totalPerformance.size()];
+
+        for (int i = 0; i < totalPerformance.size(); i++) {
+            for (int j = 0; j < totalPerformance.get(i).getQuizAnswer().length; j++) {
+                allAssessments[i] += totalPerformance.get(i).getQuizAnswer()[j];
+            }
+            allAssessments[i] = allAssessments[i] / totalPerformance.get(i).getQuizAnswer().length;
+        }
+        for (int i = 0; i < totalPerformance.size(); i++) {
+            Grading shuttle = new Grading(totalPerformance.get(i).getStudentIdentifier(), allAssessments[i]);
+            grading[i] = shuttle;
+        }
+        return Arrays.asList(grading);
+    }
+
+    private List<Grading> meanOfWorkRate(ArrayList<Performance> totalPerformance){
+        double[] allAssessments = new double[totalPerformance.size()];
+        Grading[] grading = new Grading[totalPerformance.size()];
+
+        for (int i = 0; i < totalPerformance.size(); i++) {
+            for (int j = 0; j < totalPerformance.get(i).getWorkRating().length; j++) {
+                allAssessments[i] += 6-totalPerformance.get(i).getWorkRating()[j];
+            }
+            allAssessments[i] = allAssessments[i] / totalPerformance.get(i).getWorkRating().length;
+        }
+        for (int i = 0; i < totalPerformance.size(); i++) {
+            Grading shuttle = new Grading(totalPerformance.get(i).getStudentIdentifier(), allAssessments[i]);
+            grading[i] = shuttle;
+        }
+        return Arrays.asList(grading);
     }
 
     @Override
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessmentDummy.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessmentDummy.java
index efe2cd75..f6fd95c5 100644
--- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessmentDummy.java
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/service/PeerAssessmentDummy.java
@@ -88,7 +88,7 @@ public class PeerAssessmentDummy implements IPeerAssessment {
         Grading[] grading = new Grading[totalPerformance.size()];
 
         for (int i = 0; i < totalPerformance.size(); i++) {
-            for (int j = 0; j < totalPerformance.get(i).getQuizAnswer().length; j++) {
+            for (int j = totalPerformance.get(i).getQuizAnswer().length; j > 0; j--) {
                 allAssessments[i] += totalPerformance.get(i).getQuizAnswer()[j];
             }
             allAssessments[i] = allAssessments[i] / totalPerformance.get(i).getQuizAnswer().length;
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/QuizView.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/QuizView.java
index e34e1e9a..ef64442c 100644
--- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/QuizView.java
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/QuizView.java
@@ -3,6 +3,7 @@ package unipotsdam.gf.modules.assessment.controller.view;
 import unipotsdam.gf.interfaces.IPeerAssessment;
 import unipotsdam.gf.modules.assessment.controller.model.*;
 import unipotsdam.gf.modules.assessment.controller.service.PeerAssessment;
+import unipotsdam.gf.modules.assessment.controller.service.PeerAssessmentDummy;
 
 import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
-- 
GitLab