Search in sources :

Example 1 with FeedbackSessionResultsBundle

use of teammates.common.datatransfer.FeedbackSessionResultsBundle in project teammates by TEAMMATES.

the class InstructorStudentRecordsAjaxPageAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
    String targetSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, targetSessionName);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId));
    StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
    if (student == null) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, StatusMessageColor.DANGER));
        isError = true;
        return createRedirectResult(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
    }
    List<FeedbackSessionAttributes> feedbacks = logic.getFeedbackSessionsListForInstructor(account.googleId, false);
    filterFeedbackSessions(courseId, feedbacks, instructor, student);
    List<SessionAttributes> sessions = new ArrayList<>();
    sessions.addAll(feedbacks);
    sessions.sort(SessionAttributes.DESCENDING_ORDER);
    List<FeedbackSessionResultsBundle> results = new ArrayList<>();
    for (SessionAttributes session : sessions) {
        if (session instanceof FeedbackSessionAttributes) {
            if (!targetSessionName.isEmpty() && targetSessionName.equals(session.getSessionName())) {
                FeedbackSessionResultsBundle result = logic.getFeedbackSessionResultsForInstructor(session.getSessionName(), courseId, instructor.email);
                results.add(result);
            }
        } else {
            Assumption.fail("Unknown session type");
        }
    }
    statusToAdmin = "instructorStudentRecords Ajax Page Load<br>" + "Viewing <span class=\"bold\">" + studentEmail + "'s</span> records " + "for session <span class=\"bold\">[" + targetSessionName + "]</span> " + "in course <span class=\"bold\">[" + courseId + "]</span>";
    InstructorStudentRecordsAjaxPageData data = new InstructorStudentRecordsAjaxPageData(account, student, sessionToken, results);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS_AJAX, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorStudentRecordsAjaxPageData(teammates.ui.pagedata.InstructorStudentRecordsAjaxPageData) SessionAttributes(teammates.common.datatransfer.attributes.SessionAttributes) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Example 2 with FeedbackSessionResultsBundle

use of teammates.common.datatransfer.FeedbackSessionResultsBundle in project teammates by TEAMMATES.

the class FeedbackRubricQuestionDetails method getPerRecipientStatisticsSorted.

public List<Map.Entry<String, RubricRecipientStatistics>> getPerRecipientStatisticsSorted(List<FeedbackResponseAttributes> responses, FeedbackSessionResultsBundle bundle) {
    Map<String, RubricRecipientStatistics> recipientToRecipientStats = new HashMap<>();
    for (FeedbackResponseAttributes response : responses) {
        recipientToRecipientStats.computeIfAbsent(response.recipient, recipient -> {
            String recipientTeam = bundle.getTeamNameForEmail(recipient);
            String recipientName = bundle.getNameForEmail(recipient);
            return new RubricRecipientStatistics(recipient, recipientName, recipientTeam);
        }).addResponseToRecipientStats(response);
    }
    List<Map.Entry<String, RubricRecipientStatistics>> recipientStatsList = new LinkedList<>(recipientToRecipientStats.entrySet());
    recipientStatsList.sort(Comparator.comparing((Map.Entry<String, RubricRecipientStatistics> obj) -> obj.getValue().recipientTeam.toLowerCase()).thenComparing(obj -> obj.getValue().recipientName));
    return recipientStatsList;
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Const(teammates.common.util.Const) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle) DecimalFormat(java.text.DecimalFormat) Slots(teammates.common.util.Templates.FeedbackQuestion.Slots) SanitizationHelper(teammates.common.util.SanitizationHelper) HashMap(java.util.HashMap) StringHelper(teammates.common.util.StringHelper) Collectors(java.util.stream.Collectors) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) ArrayList(java.util.ArrayList) HttpRequestHelper(teammates.common.util.HttpRequestHelper) List(java.util.List) Templates(teammates.common.util.Templates) InstructorFeedbackResultsResponseRow(teammates.ui.template.InstructorFeedbackResultsResponseRow) FormTemplates(teammates.common.util.Templates.FeedbackQuestion.FormTemplates) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) Map(java.util.Map) Assumption(teammates.common.util.Assumption) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) Logger(teammates.common.util.Logger) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 3 with FeedbackSessionResultsBundle

use of teammates.common.datatransfer.FeedbackSessionResultsBundle in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method testGetFeedbackSessionResultsForUser.

private void testGetFeedbackSessionResultsForUser() throws Exception {
    // This file contains a session with a private session + a standard
    // session which needs to have enough qn/response combinations to cover as much
    // of the SUT as possible
    DataBundle responseBundle = loadDataBundle("/FeedbackSessionResultsTest.json");
    removeAndRestoreDataBundle(responseBundle);
    ______TS("standard session with varied visibilities");
    FeedbackSessionAttributes session = responseBundle.feedbackSessions.get("standard.session");
    /**
     * Test result bundle for student1 **
     */
    StudentAttributes student = responseBundle.students.get("student1InCourse1");
    FeedbackSessionResultsBundle results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
    // We just check for correct session once
    assertEquals(session.toString(), results.feedbackSession.toString());
    // Student can see responses: q1r1, q2r1,3, q3r1, qr4r2-3, q5r1, q7r1-2, q8r1-2
    // We don't check the actual IDs as this is also implicitly tested
    // later when checking the visibility table.
    assertEquals(11, results.responses.size());
    assertEquals(7, results.questions.size());
    // Test the user email-name maps used for display purposes
    String mapString = results.emailNameTable.toString();
    List<String> expectedStrings = new ArrayList<>();
    String student2AnonEmail = getStudentAnonEmail(responseBundle, "student2InCourse1");
    String student2AnonName = getStudentAnonName(responseBundle, "student2InCourse1");
    String student4AnonEmail = getStudentAnonEmail(responseBundle, "student4InCourse1");
    String student4AnonName = getStudentAnonName(responseBundle, "student4InCourse1");
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "Team 1.1</td></div>'\"=Team 1.1</td></div>'\"", "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.student1InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student2InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student4InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.2", student2AnonEmail + "=" + student2AnonName, student4AnonEmail + "=" + student4AnonName);
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student1InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt's Team=", "FSRTest.student4InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.1</td></div>'\"=", "Team 1.3=", "Team 1.2=", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors", student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student4AnonEmail + "=" + student4AnonName + Const.TEAM_OF_EMAIL_OWNER);
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailTeamNameTable.size());
    // Test 'Append TeamName to Name' for display purposes with Typical Cases
    expectedStrings.clear();
    List<String> actualStrings = new ArrayList<>();
    for (FeedbackResponseAttributes response : results.responses) {
        String giverName = results.getNameForEmail(response.giver);
        String giverTeamName = results.getTeamNameForEmail(response.giver);
        giverName = results.appendTeamNameToName(giverName, giverTeamName);
        String recipientName = results.getNameForEmail(response.recipient);
        String recipientTeamName = results.getTeamNameForEmail(response.recipient);
        recipientName = results.appendTeamNameToName(recipientName, recipientTeamName);
        actualStrings.add(giverName);
        actualStrings.add(recipientName);
    }
    Collections.addAll(expectedStrings, getStudentAnonName(responseBundle, "student2InCourse1"), getStudentAnonName(responseBundle, "student4InCourse1"), "student1 In Course1</td></div>'\" (Team 1.1</td></div>'\")", "student2 In Course1 (Team 1.1</td></div>'\")", "student4 In Course1 (Team 1.2)", "Instructor1 Course1 (Instructors)", "Team 1.1</td></div>'\"", "Team 1.2", "Team 1.3", "Team 1.4");
    AssertHelper.assertContains(expectedStrings, actualStrings.toString());
    // Test 'Append TeamName to Name' for display purposes with Special Cases
    expectedStrings.clear();
    actualStrings.clear();
    // case: Unknown User
    String unknownUserName = Const.USER_UNKNOWN_TEXT;
    String someTeamName = "Some Team Name";
    unknownUserName = results.appendTeamNameToName(unknownUserName, someTeamName);
    actualStrings.add(unknownUserName);
    // case: Nobody
    String nobodyUserName = Const.USER_NOBODY_TEXT;
    nobodyUserName = results.appendTeamNameToName(nobodyUserName, someTeamName);
    actualStrings.add(nobodyUserName);
    // case: Anonymous User
    String anonymousUserName = Const.DISPLAYED_NAME_FOR_ANONYMOUS_PARTICIPANT + " " + System.currentTimeMillis();
    anonymousUserName = results.appendTeamNameToName(anonymousUserName, someTeamName);
    actualStrings.add(anonymousUserName);
    Collections.addAll(expectedStrings, Const.USER_UNKNOWN_TEXT, Const.USER_NOBODY_TEXT, anonymousUserName);
    assertEquals(expectedStrings.toString(), actualStrings.toString());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn1.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={true,true}", getResponseId("qn3.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={false,true}", getResponseId("qn5.resp1", responseBundle) + "={true,false}", getResponseId("qn7.resp1", responseBundle) + "={true,true}", getResponseId("qn7.resp2", responseBundle) + "={true,true}", getResponseId("qn8.resp1", responseBundle) + "={true,true}", getResponseId("qn8.resp2", responseBundle) + "={true,true}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(11, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 within a course **
     */
    InstructorAttributes instructor = responseBundle.instructors.get("instructor1OfCourse1");
    results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
    // Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
    assertEquals(10, results.responses.size());
    // Instructor should still see all questions
    assertEquals(8, results.questions.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    String student1AnonEmail = getStudentAnonEmail(responseBundle, "student1InCourse1");
    String student1AnonName = getStudentAnonName(responseBundle, "student1InCourse1");
    String student3AnonEmail = getStudentAnonEmail(responseBundle, "student3InCourse1");
    String student3AnonName = getStudentAnonName(responseBundle, "student3InCourse1");
    String student6AnonEmail = getStudentAnonEmail(responseBundle, "student6InCourse1");
    String student6AnonName = getStudentAnonName(responseBundle, "student6InCourse1");
    String instructor1AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
    String instructor1AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
    String instructor2AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
    String instructor2AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
    Collections.addAll(expectedStrings, "%GENERAL%=%NOBODY%", "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student3InCourse1@gmail.tmt=student3 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "FSRTest.student5InCourse1@gmail.tmt=student5 In Course1", "FSRTest.student6InCourse1@gmail.tmt=student6 In Course1", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.instr2@course1.tmt=Instructor2 Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, instructor2AnonEmail + "=" + instructor2AnonName, "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(18, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "%GENERAL%=", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student3InCourse1@gmail.tmt=Team 1.2", "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student5InCourse1@gmail.tmt=Team 1.3", "FSRTest.student6InCourse1@gmail.tmt=Team 1.4", "FSRTest.instr2@course1.tmt=Instructors", "FSRTest.instr1@course1.tmt=Instructors", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor2AnonEmail + "=" + instructor2AnonName + Const.TEAM_OF_EMAIL_OWNER, "Team 1.3=", "Team 1.2=", "Team 1.4=");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(18, results.emailTeamNameTable.size());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn2.resp1", responseBundle) + "={false,false}", getResponseId("qn2.resp2", responseBundle) + "={false,false}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn3.resp2", responseBundle) + "={false,false}", getResponseId("qn4.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn5.resp1", responseBundle) + "={false,true}", getResponseId("qn6.resp1", responseBundle) + "={true,true}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(10, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 within a section **
     */
    results = fsLogic.getFeedbackSessionResultsForInstructorInSection(session.getFeedbackSessionName(), session.getCourseId(), instructor.email, "Section A");
    // Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
    assertEquals(7, results.responses.size());
    // Instructor should still see all questions
    assertEquals(8, results.questions.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailTeamNameTable.size());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn2.resp1", responseBundle) + "={false,false}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(7, results.visibilityTable.size());
    // TODO: test student2 too.
    ______TS("private session");
    session = responseBundle.feedbackSessions.get("private.session");
    /**
     * Test result bundle for student1 **
     */
    student = responseBundle.students.get("student1InCourse1");
    results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
    assertEquals(0, results.questions.size());
    assertEquals(0, results.responses.size());
    assertEquals(0, results.emailNameTable.size());
    assertEquals(0, results.emailTeamNameTable.size());
    assertEquals(0, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 **
     */
    instructor = responseBundle.instructors.get("instructor1OfCourse1");
    results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
    // Can see all responses regardless of visibility settings.
    assertEquals(2, results.questions.size());
    assertEquals(2, results.responses.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "Team 1.2=Team 1.2", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructor1 Course1");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(4, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.2=", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructors");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(4, results.emailTeamNameTable.size());
    // Test that name visibility is adhered to even when
    // it is a private session. (to protect anonymity during session type conversion)"
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("p.qn1.resp1", responseBundle) + "={true,true}", getResponseId("p.qn2.resp1", responseBundle) + "={true,false}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(2, results.visibilityTable.size());
    ______TS("failure: no session");
    try {
        fsLogic.getFeedbackSessionResultsForInstructor("invalid session", session.getCourseId(), instructor.email);
        signalFailureToDetectException("Did not detect that session does not exist.");
    } catch (EntityDoesNotExistException e) {
        assertEquals("Trying to view a non-existent feedback session: " + session.getCourseId() + "/" + "invalid session", e.getMessage());
    }
// TODO: check for cases where a person is both a student and an instructor
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) DataBundle(teammates.common.datatransfer.DataBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 4 with FeedbackSessionResultsBundle

use of teammates.common.datatransfer.FeedbackSessionResultsBundle in project teammates by TEAMMATES.

the class FeedbackSessionsLogic method getFeedbackSessionResultsSummaryInSectionAsCsv.

public String getFeedbackSessionResultsSummaryInSectionAsCsv(String feedbackSessionName, String courseId, String userEmail, String section, String questionId, boolean isMissingResponsesShown, boolean isStatsShown) throws EntityDoesNotExistException, ExceedingRangeException {
    FeedbackSessionResultsBundle results;
    int indicatedRange = section == null ? Const.INSTRUCTOR_VIEW_RESPONSE_LIMIT : -1;
    if (questionId == null) {
        results = getFeedbackSessionResultsForInstructorInSectionWithinRangeFromView(feedbackSessionName, courseId, userEmail, section, indicatedRange, Const.FeedbackSessionResults.GRQ_SORT_TYPE);
    } else if (section == null) {
        results = getFeedbackSessionResultsForInstructorFromQuestion(feedbackSessionName, courseId, userEmail, questionId);
    } else {
        results = getFeedbackSessionResultsForInstructorFromQuestionInSection(feedbackSessionName, courseId, userEmail, questionId, section);
    }
    if (!results.isComplete) {
        throw new ExceedingRangeException(ERROR_NUMBER_OF_RESPONSES_EXCEEDS_RANGE);
    }
    // sort responses by giver > recipient > qnNumber
    results.responses.sort(results.compareByGiverRecipientQuestion);
    StringBuilder exportBuilder = new StringBuilder(100);
    exportBuilder.append(String.format("Course,%s", SanitizationHelper.sanitizeForCsv(results.feedbackSession.getCourseId()))).append(System.lineSeparator()).append(String.format("Session Name,%s", SanitizationHelper.sanitizeForCsv(results.feedbackSession.getFeedbackSessionName()))).append(System.lineSeparator());
    if (section != null) {
        exportBuilder.append(String.format("Section Name,%s", SanitizationHelper.sanitizeForCsv(section))).append(System.lineSeparator());
    }
    exportBuilder.append(System.lineSeparator()).append(System.lineSeparator());
    Set<Entry<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>>> entrySet = results.getQuestionResponseMap().entrySet();
    for (Map.Entry<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> entry : entrySet) {
        exportBuilder.append(getFeedbackSessionResultsForQuestionInCsvFormat(results, entry, isMissingResponsesShown, isStatsShown, section));
    }
    return exportBuilder.toString();
}
Also used : Entry(java.util.Map.Entry) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ExceedingRangeException(teammates.common.exception.ExceedingRangeException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Example 5 with FeedbackSessionResultsBundle

use of teammates.common.datatransfer.FeedbackSessionResultsBundle in project teammates by TEAMMATES.

the class InstructorFeedbackResponseCommentAddAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    String feedbackQuestionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_ID, feedbackQuestionId);
    String feedbackResponseId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponseId);
    String commentId = getRequestParamValue(Const.ParamsNames.COMMENT_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COMMENT_ID, commentId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    FeedbackResponseAttributes response = logic.getFeedbackResponse(feedbackResponseId);
    Assumption.assertNotNull(response);
    boolean isCreatorOnly = true;
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.giverSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.recipientSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    InstructorFeedbackResponseCommentAjaxPageData data = new InstructorFeedbackResponseCommentAjaxPageData(account, sessionToken);
    String giverEmail = response.giver;
    String recipientEmail = response.recipient;
    FeedbackSessionResultsBundle bundle = logic.getFeedbackSessionResultsForInstructor(feedbackSessionName, courseId, instructor.email);
    String giverName = bundle.getGiverNameForResponse(response);
    String giverTeamName = bundle.getTeamNameForEmail(giverEmail);
    data.giverName = bundle.appendTeamNameToName(giverName, giverTeamName);
    String recipientName = bundle.getRecipientNameForResponse(response);
    String recipientTeamName = bundle.getTeamNameForEmail(recipientEmail);
    data.recipientName = bundle.appendTeamNameToName(recipientName, recipientTeamName);
    // Set up comment text
    String commentText = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, commentText);
    if (commentText.trim().isEmpty()) {
        data.errorMessage = Const.StatusMessages.FEEDBACK_RESPONSE_COMMENT_EMPTY;
        data.isError = true;
        return createAjaxResult(data);
    }
    FeedbackResponseCommentAttributes feedbackResponseComment = FeedbackResponseCommentAttributes.builder(courseId, feedbackSessionName, instructor.email, new Text(commentText)).withFeedbackQuestionId(feedbackQuestionId).withFeedbackResponseId(feedbackResponseId).withCreatedAt(Instant.now()).withGiverSection(response.giverSection).withReceiverSection(response.recipientSection).build();
    // Set up visibility settings
    String showCommentTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWCOMMENTSTO);
    String showGiverNameTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWGIVERTO);
    feedbackResponseComment.showCommentTo = new ArrayList<>();
    if (showCommentTo != null && !showCommentTo.isEmpty()) {
        String[] showCommentToArray = showCommentTo.split(",");
        for (String viewer : showCommentToArray) {
            feedbackResponseComment.showCommentTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    feedbackResponseComment.showGiverNameTo = new ArrayList<>();
    if (showGiverNameTo != null && !showGiverNameTo.isEmpty()) {
        String[] showGiverNameToArray = showGiverNameTo.split(",");
        for (String viewer : showGiverNameToArray) {
            feedbackResponseComment.showGiverNameTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    FeedbackResponseCommentAttributes createdComment = null;
    try {
        createdComment = logic.createFeedbackResponseComment(feedbackResponseComment);
        logic.putDocument(createdComment);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
        data.errorMessage = e.getMessage();
        data.isError = true;
    }
    if (!data.isError) {
        statusToAdmin += "InstructorFeedbackResponseCommentAddAction:<br>" + "Adding comment to response: " + feedbackResponseComment.feedbackResponseId + "<br>" + "in course/feedback session: " + feedbackResponseComment.courseId + "/" + feedbackResponseComment.feedbackSessionName + "<br>" + "by: " + feedbackResponseComment.giverEmail + " at " + feedbackResponseComment.createdAt + "<br>" + "comment text: " + feedbackResponseComment.commentText.getValue();
    }
    if (createdComment == null) {
        data.showCommentToString = "";
        data.showGiverNameToString = "";
    } else {
        data.showCommentToString = StringHelper.toString(createdComment.showCommentTo, ",");
        data.showGiverNameToString = StringHelper.toString(createdComment.showGiverNameTo, ",");
    }
    data.comment = createdComment;
    data.commentId = commentId;
    data.instructorEmailNameTable = bundle.instructorEmailNameTable;
    data.question = logic.getFeedbackQuestion(feedbackQuestionId);
    data.sessionTimeZone = session.getTimeZone();
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_RESPONSE_COMMENTS_ADD, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorFeedbackResponseCommentAjaxPageData(teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Aggregations

FeedbackSessionResultsBundle (teammates.common.datatransfer.FeedbackSessionResultsBundle)9 ArrayList (java.util.ArrayList)7 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)7 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 HashMap (java.util.HashMap)5 List (java.util.List)5 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)5 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)5 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)5 HashSet (java.util.HashSet)3 Set (java.util.Set)3 FeedbackSessionResponseStatus (teammates.common.datatransfer.FeedbackSessionResponseStatus)3 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)3 Map (java.util.Map)2 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)2 Text (com.google.appengine.api.datastore.Text)1 DecimalFormat (java.text.DecimalFormat)1 Comparator (java.util.Comparator)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1