Can you Set a Default Grade With a Default Comment?

Jump to solution
JB12345
Community Member

Is there a way to set a default grade with a default comment? It is really takes a lot of time to have to individually copy and paste the SAME comment into each student's assignment using speedgrader such as "Good job on this assignment!" Can we get Canvas admin to add this as an option?

Labels (1)
0 Likes
2 Solutions
Gabriel33
Community Participant

It doesn't seem there is an inbuilt solution, it has been requested as an idea since 2016: [Gradebook] Default Comment - Page 3 - Instructure Community - 375680

But it is possible to do that using the canvas API. Here's one script I generated (with ChatGPT's help) that does the job for Python using the canvasapi module. Note that it requires the assignment id, so if you are using a quiz, you need to get the assignment id for that quiz (different from the quiz id).

You can also select the grade to give the comment to, so you can run it once to give "Great job!!!" for a 10, then once again to give a "Great job!" for a 9, then again for "Great Job..." for an 8, and so on. It's possible to add ranges, or have a dictionary of grades to comments, but I didn't want to over complicate it.

 

 

Spoiler
from canvasapi import Canvas

def add_comment_to_submissions(api_url, api_key, course_id, assignment_id, target_grade, comment_text):
    # Initialize the Canvas object
    canvas = Canvas(api_url, api_key)
    
    # Get the course and assignment objects
    course = canvas.get_course(course_id)
    assignment = course.get_assignment(assignment_id)
    
    # Create a dictionary mapping user IDs to student names
    dict_users = {}
    for user in course.get_users():
        dict_users[user.id] = user.name
    
    # Retrieve all submissions for the assignment
    submissions = assignment.get_submissions()
    
    for submission in submissions:
        student_name = dict_users.get(submission.user_id, "Unknown")
        
        # Check if a grade exists for the submission
        if submission.grade is not None:
            try:
                # Convert the grade to a float for numerical comparison
                grade = float(submission.grade)
            except ValueError:
                print(f"Skipping {student_name}: grade '{submission.grade}' is not numeric.")
                continue

            # If the submission's grade matches the target grade condition (exact match)
            if grade == target_grade:
                print(f"Adding comment for {student_name} with grade {grade}.")
                # Post a comment using the "text_comment" field
                submission.edit(comment={"text_comment": comment_text})
            else:
                print(f"Skipping {student_name}: grade {grade} does not match target grade {target_grade}.")
        else:
            print(f"No grade available for {student_name}; skipping.")

# Example usage:
if __name__ == "__main__":
    # Replace these values with your actual Canvas API details
    API_URL = "https://canvas.instructure.com"
    API_KEY = "your_canvas_api_key"
    COURSE_ID = 123456
    ASSIGNMENT_ID = 654321
    TARGET_GRADE = 85.0
    COMMENT_TEXT = "Great job on your assignment!"

    add_comment_to_submissions(API_URL, API_KEY, COURSE_ID, ASSIGNMENT_ID, TARGET_GRADE, COMMENT_TEXT)

 

 

 

View solution in original post

dbrace
Community Coach
Community Coach

Hi @JB12345,

While not the same as using a default comment but another option besides copying and pasting, have you considered using the comment library in the SpeedGrader?

How do I use the Comment Library in SpeedGrader? - Instructure Community - 469482

-Doug

View solution in original post