Search in sources :

Example 36 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackSessionResultsBundle method getQuestionResponseMapByRecipientTeam.

/**
 * Returns an ordered Map with {@code recipientTeam} name as key
 * sorted by recipientTeam > question > recipientName > giverTeam > giverName.
 */
public Map<String, Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> getQuestionResponseMapByRecipientTeam() {
    LinkedHashMap<String, Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> sortedMap = new LinkedHashMap<>();
    responses.sort(compareByTeamQuestionRecipientTeamGiver);
    for (FeedbackResponseAttributes response : responses) {
        String recipientTeam = getTeamNameForEmail(response.recipient);
        if (recipientTeam.isEmpty()) {
            recipientTeam = getNameForEmail(response.recipient);
        }
        Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> responsesForOneRecipient = sortedMap.computeIfAbsent(recipientTeam, key -> new LinkedHashMap<>());
        FeedbackQuestionAttributes question = questions.get(response.feedbackQuestionId);
        List<FeedbackResponseAttributes> responsesForOneRecipientOneQuestion = responsesForOneRecipient.computeIfAbsent(question, key -> new ArrayList<>());
        responsesForOneRecipientOneQuestion.add(response);
    }
    return sortedMap;
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackSessionResultsBundle method getQuestionResponseMapSortedByRecipient.

public Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> getQuestionResponseMapSortedByRecipient() {
    if (questions == null || responses == null) {
        return null;
    }
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> sortedMap = new LinkedHashMap<>();
    List<FeedbackQuestionAttributes> sortedQuestions = new ArrayList<>(questions.values());
    // sorts the questions by its natural ordering, which is by question number
    sortedQuestions.sort(null);
    for (FeedbackQuestionAttributes question : sortedQuestions) {
        sortedMap.put(question, new ArrayList<FeedbackResponseAttributes>());
    }
    for (FeedbackResponseAttributes response : responses) {
        FeedbackQuestionAttributes question = questions.get(response.feedbackQuestionId);
        List<FeedbackResponseAttributes> responsesForQuestion = sortedMap.get(question);
        responsesForQuestion.add(response);
    }
    for (List<FeedbackResponseAttributes> responsesForQuestion : sortedMap.values()) {
        responsesForQuestion.sort(compareByRecipientNameEmailGiverNameEmail);
    }
    return sortedMap;
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackSessionResultsBundle method getResponsesSortedByRecipientQuestionGiver.

/**
 * Returns responses as a {@code Map<recipientName, Map<question, List<response>>>}
 * Where the responses are sorted in the order of recipient, question, giver.
 * @return responses sorted by Recipient > Question > Giver
 */
public Map<String, Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> getResponsesSortedByRecipientQuestionGiver(boolean sortByTeam) {
    Map<String, Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> sortedMap = new LinkedHashMap<>();
    if (sortByTeam) {
        responses.sort(compareByTeamRecipientQuestionTeamGiver);
    } else {
        responses.sort(compareByRecipientQuestionTeamGiver);
    }
    for (FeedbackResponseAttributes response : responses) {
        String recipientEmail = response.recipient;
        Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> responsesForOneRecipient = sortedMap.computeIfAbsent(recipientEmail, key -> new LinkedHashMap<>());
        FeedbackQuestionAttributes question = questions.get(response.feedbackQuestionId);
        responsesForOneRecipient.computeIfAbsent(question, key -> new ArrayList<>()).add(response);
    }
    return sortedMap;
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) Set(java.util.Set) SanitizationHelper(teammates.common.util.SanitizationHelper) HashMap(java.util.HashMap) StringHelper(teammates.common.util.StringHelper) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) ZoneId(java.time.ZoneId) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Map(java.util.Map) Element(org.jsoup.nodes.Element) Text(com.google.appengine.api.datastore.Text) Jsoup(org.jsoup.Jsoup) Elements(org.jsoup.select.Elements) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) Comparator(java.util.Comparator) Logger(teammates.common.util.Logger) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 39 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackResponsesLogicTest method testUpdateFeedbackResponsesForChangingTeam_deleteNotLastResponse_sameResponseRate.

private void testUpdateFeedbackResponsesForChangingTeam_deleteNotLastResponse_sameResponseRate() throws Exception {
    FeedbackResponseAttributes responseToBeDeleted = getResponseFromDatastore(questionTypeBundle, "response1ForQ1S5C1");
    // make sure it's not the last response by the student
    assertTrue(1 < numResponsesFromGiverInSession(responseToBeDeleted.giver, responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId));
    StudentAttributes student = questionTypeBundle.students.get("student1InCourse1");
    StudentEnrollDetails enrollmentDetailsToTriggerDeletion = new StudentEnrollDetails(StudentUpdateStatus.MODIFIED, student.course, student.email, student.team, student.team + "tmp", student.section, student.section + "tmp");
    int originalResponseRate = getResponseRate(responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId);
    assertTrue(frLogic.updateFeedbackResponseForChangingTeam(enrollmentDetailsToTriggerDeletion, responseToBeDeleted));
    int responseRateAfterDeletion = getResponseRate(responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId);
    assertEquals(originalResponseRate, responseRateAfterDeletion);
    // restore DataStore so other tests are unaffected
    restoreStudentFeedbackResponseToDatastore(responseToBeDeleted);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 40 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackResponsesLogicTest method getResponseFromDatastore.

private FeedbackResponseAttributes getResponseFromDatastore(DataBundle dataBundle, String jsonId) {
    FeedbackResponseAttributes response = dataBundle.feedbackResponses.get(jsonId);
    String qnId;
    try {
        int qnNumber = Integer.parseInt(response.feedbackQuestionId);
        qnId = fqLogic.getFeedbackQuestion(response.feedbackSessionName, response.courseId, qnNumber).getId();
    } catch (NumberFormatException e) {
        qnId = response.feedbackQuestionId;
    }
    return frLogic.getFeedbackResponse(qnId, response.giver, response.recipient);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes)

Aggregations

FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)143 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)70 ArrayList (java.util.ArrayList)63 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)36 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)35 List (java.util.List)29 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)28 HashMap (java.util.HashMap)27 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)22 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)20 Map (java.util.Map)18 Test (org.testng.annotations.Test)18 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)18 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)18 Text (com.google.appengine.api.datastore.Text)15 Set (java.util.Set)11 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)10 Comparator (java.util.Comparator)9 FeedbackParticipantType (teammates.common.datatransfer.FeedbackParticipantType)9