기준표 시작하기

rubric는 교사가 학생 제출물을 평가할 때 사용할 수 있는 템플릿입니다. Classroom API를 사용하면 교사를 대신하여 이러한 기준표를 관리할 수 있습니다.

클래스룸 UI의 기준표 보기그림 1. 클래스룸 과제에 대한 샘플 기준표 보기

이 가이드에서는 Rubrics API의 기본 개념과 기능을 설명합니다. 기준표의 일반 구조와 클래스룸 UI에서 기준표 채점이 이루어지는 방식을 알아보려면 이 고객센터 도움말을 참고하세요.

기본 요건

이 가이드에서는 다음 권한이 있다고 가정합니다.

데스크톱 애플리케이션에 대한 사용자 인증 정보 승인

최종 사용자로 인증하고 앱의 사용자 데이터에 액세스하려면 OAuth 2.0 클라이언트 ID를 하나 이상 만들어야 합니다. 클라이언트 ID는 Google OAuth 서버에서 단일 앱을 식별하는 데 사용됩니다. 앱이 여러 플랫폼에서 실행되는 경우 플랫폼마다 별도의 클라이언트 ID를 만들어야 합니다.

  1. Google Cloud 콘솔에서 GCP 사용자 인증 정보 페이지로 이동합니다.
  2. 사용자 인증 정보 만들기 > OAuth 클라이언트 ID를 클릭합니다.
  3. 애플리케이션 유형 > 데스크톱 앱을 클릭합니다.
  4. 이름 입력란에 사용자 인증 정보의 이름을 입력합니다. 이 이름은 Google Cloud 콘솔에만 표시됩니다. 예: '기준표 미리보기 클라이언트'
  5. 만들기를 클릭합니다. OAuth 클라이언트 생성 완료 화면이 표시되고 새 클라이언트 ID와 클라이언트 보안 비밀번호가 표시됩니다.
  6. JSON 다운로드를 클릭한 후 확인을 클릭합니다. 새로 생성된 사용자 인증 정보가 OAuth 2.0 클라이언트 ID 아래에 표시됩니다.
  7. 다운로드한 JSON 파일을 credentials.json로 저장하고 파일을 작업 디렉터리로 이동합니다.
  8. 사용자 인증 정보 만들기 > API 키를 클릭하고 API 키를 기록합니다.

자세한 내용은 액세스 사용자 인증 정보 만들기를 참고하세요.

OAuth 범위 구성

프로젝트의 기존 OAuth 범위에 따라 추가 범위를 구성해야 할 수 있습니다.

  1. OAuth 동의 화면으로 이동합니다.
  2. Edit App > Save and Continue를 클릭하여 범위 화면으로 이동합니다.
  3. 범위 추가/삭제를 클릭합니다.
  4. 다음 범위가 없는 경우 추가합니다.
    • https://www.googleapis.com/auth/classroom.coursework.students
    • https://www.googleapis.com/auth/classroom.courses
  5. 그런 다음 업데이트 > 저장 후 계속 > 저장 후 계속 > 대시보드로 돌아가기를 클릭합니다.

자세한 내용은 OAuth 동의 화면 구성을 참고하세요.

classroom.coursework.students 범위를 사용하면 기준표에 대한 읽기 및 쓰기 액세스 권한과 CourseWork에 대한 액세스가 허용되며 classroom.courses 범위를 사용하면 과정 읽기 및 쓰기가 가능합니다.

특정 메서드에 필요한 범위는 메서드의 참조 문서에 나열되어 있습니다. 예시는 courses.courseWork.rubrics.create 승인 범위를 참조하세요. Google API의 OAuth 2.0 범위에서 모든 클래스룸 범위를 확인할 수 있습니다. API가 아직 미리보기 상태이므로 기준표는 여기서 언급되지 않습니다.

샘플 구성

작업 디렉터리에 Python용 Google 클라이언트 라이브러리를 설치합니다.

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

클라이언트 라이브러리를 빌드하고 YOUR_API_KEY 대신 API 키를 사용하여 사용자를 승인하는 main.py라는 파일을 만듭니다.

import json
import os.path

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/classroom.courses',
          'https://www.googleapis.com/auth/classroom.coursework.students']

def build_authenticated_service(api_key):
    """Builds the Classroom service."""
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run.
        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    try:
        # Build the Classroom service.
        service = build(
            serviceName="classroom",
            version="v1",
            credentials=creds,
            discoveryServiceUrl=f"https://classroom.googleapis.com/$discovery/rest?labels=DEVELOPER_PREVIEW&key={api_key}")

        return service

    except HttpError as error:
        print('An error occurred: %s' % error)

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

python main.py를 사용하여 스크립트를 실행합니다. 로그인하여 OAuth 범위에 동의하라는 메시지가 표시됩니다.

과제 만들기

기준표는 과제 또는 CourseWork와 연결되며 CourseWork 컨텍스트에서만 의미가 있습니다. 기준표는 상위 CourseWork 항목을 만든 Google Cloud 프로젝트에서만 만들 수 있습니다. 이 가이드에서는 스크립트를 사용하여 새 CourseWork 할당을 만듭니다.

다음을 main.py에 추가합니다.

def get_latest_course(service):
    """Retrieves the last created course."""
    try:
        response = service.courses().list(pageSize=1).execute()
        courses = response.get("courses", [])
        if not courses:
            print("No courses found. Did you remember to create one in the UI?")
            return
        course = courses[0]
        return course

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

def create_coursework(service, course_id):
    """Creates and returns a sample coursework."""
    try:
        coursework = {
            "title": "Romeo and Juliet analysis.",
            "description": """Write a paper arguing that Romeo and Juliet were
                                time travelers from the future.""",
            "workType": "ASSIGNMENT",
            "state": "PUBLISHED",
        }
        coursework = service.courses().courseWork().create(
            courseId=course_id, body=coursework).execute()
        return coursework

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

이제 main.py를 업데이트하여 방금 만든 테스트 클래스의 course_id를 가져오고 새 샘플 과제를 만든 후 과제의 coursework_id를 가져옵니다.

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

    course = get_latest_course(service)
    course_id = course.get("id")
    course_name = course.get("name")
    print(f"'{course_name}' course ID: {course_id}")

    coursework = create_coursework(service, course_id)
    coursework_id = coursework.get("id")
    print(f"Assignment created with ID {coursework_id}")

    #TODO(developer): Save the printed course and coursework IDs.

course_idcoursework_id를 저장합니다. 이는 모든 기준표 CRUD 작업에 필요합니다.

이제 클래스룸에 CourseWork 샘플이 있어야 합니다.

클래스룸 UI의 과제 보기그림 2. 클래스룸의 샘플 과제 화면

기준표 만들기

이제 기준표를 관리할 준비가 되었습니다.

기준표는 전체 기준표 객체를 포함하는 Create 호출을 사용하여 CourseWork에서 만들 수 있습니다. 기준 및 수준의 ID 속성은 생략됩니다(생성 시 생성됨).

다음 함수를 main.py에 추가합니다.

def create_rubric(service, course_id, coursework_id):
    """Creates an example rubric on a coursework."""
    try:
        body = {
            "criteria": [
                {
                    "title": "Argument",
                    "description": "How well structured your argument is.",
                    "levels": [
                        {"title": "Convincing",
                         "description": "A compelling case is made.", "points": 30},
                        {"title": "Passable",
                         "description": "Missing some evidence.", "points": 20},
                        {"title": "Needs Work",
                         "description": "Not enough strong evidence..", "points": 0},
                    ]
                },
                {
                    "title": "Spelling",
                    "description": "How well you spelled all the words.",
                    "levels": [
                        {"title": "Perfect",
                         "description": "No mistakes.", "points": 20},
                        {"title": "Great",
                         "description": "A mistake or two.", "points": 15},
                        {"title": "Needs Work",
                         "description": "Many mistakes.", "points": 5},
                    ]
                },
                {
                    "title": "Grammar",
                    "description": "How grammatically correct your sentences are.",
                    "levels": [
                        {"title": "Perfect",
                         "description": "No mistakes.", "points": 20},
                        {"title": "Great",
                         "description": "A mistake or two.", "points": 15},
                        {"title": "Needs Work",
                         "description": "Many mistakes.", "points": 5},
                    ]
                },
            ]
        }

        rubric = service.courses().courseWork().rubrics().create(
            courseId=course_id, courseWorkId=coursework_id, body=body,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
            ).execute()
        print(f"Rubric created with ID {rubric.get('id')}")
        return rubric

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

그런 다음 main.py를 업데이트하고 실행하여 앞에서 만든 CourseCourseWork ID를 사용하여 기준표 예시를 만듭니다.

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

    rubric = create_rubric(service, YOUR_COURSE_ID, YOUR_COURSEWORK_ID)
    print(json.dumps(rubric, indent=4))

기준표 표현에 관한 몇 가지 요점은 다음과 같습니다.

  • 기준 및 레벨 순서는 클래스룸 UI에 반영됩니다.
  • 점수가 매겨진 수준 (points 속성이 있는 수준)은 포인트를 기준으로 오름차순 또는 내림차순으로 정렬해야 합니다 (임의로 정렬할 수 없음).
  • 교사는 UI에서 기준과 점수를 재정렬할 수 있습니다 (점수가 없는 수준은 아님). 그러면 데이터의 순서가 변경됩니다.

기준표 구조에 대한 추가 주의사항은 제한사항을 참조하세요.

UI로 돌아가면 과제에 대한 기준표를 확인할 수 있습니다.

클래스룸 UI의 기준표 보기그림 3. 클래스룸 과제에 대한 샘플 기준표 보기

기준표 보기

기준표는 표준 ListGet 메서드로 읽을 수 있습니다.

과제에는 기준표가 최대 1개 있을 수 있으므로 List가 직관적이지 않을 수 있지만 기준표 ID가 없는 경우 유용합니다. CourseWork와 연결된 기준표가 없으면 List 응답은 비어 있습니다.

다음 함수를 main.py에 추가합니다.

def get_rubric(service, course_id, coursework_id):
    """
    Get the rubric on a coursework. There can only be at most one.
    Returns null if there is no rubric.
    """
    try:
        response = service.courses().courseWork().rubrics().list(
            courseId=course_id, courseWorkId=coursework_id,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
            ).execute()

        rubrics = response.get("rubrics", [])
        if not rubrics:
            print("No rubric found for this assignment.")
            return
        rubric = rubrics[0]
        return rubric

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

main.py를 업데이트하고 실행하여 추가한 기준표를 가져옵니다.

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

    rubric = get_rubric(service, YOUR_COURSE_ID, YOUR_COURSEWORK_ID)
    print(json.dumps(rubric, indent=4))

    #TODO(developer): Save the printed rubric ID.

이후 단계를 위해 기준표에서 id 속성을 확인합니다.

기준표 ID가 있으면 Get가 제대로 작동합니다. 대신 함수에 Get를 사용하는 방법은 다음과 같습니다.

def get_rubric(service, course_id, coursework_id, rubric_id):
    """
    Get the rubric on a coursework. There can only be at most one.
    Returns a 404 if there is no rubric.
    """
    try:
        rubric = service.courses().courseWork().rubrics().get(
            courseId=course_id,
            courseWorkId=coursework_id,
            id=rubric_id,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
        ).execute()

        return rubric

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

이 구현은 기준표가 없는 경우 404를 반환합니다.

기준표 업데이트

기준표 업데이트는 Patch 호출을 통해 이루어집니다. 기준표의 복잡한 구조로 인해 전체 criteria 속성이 바뀌는 읽기-수정-쓰기 패턴으로 업데이트를 수행해야 합니다.

업데이트 규칙은 다음과 같습니다.

  1. ID 없이 추가된 기준 또는 수준은 추가로 간주됩니다.
  2. 이전에 누락된 기준 또는 레벨은 삭제로 간주됩니다.
  3. 기존 ID가 있지만 데이터가 수정된 기준이나 수준은 edits로 간주됩니다. 수정되지 않은 속성은 그대로 유지됩니다.
  4. 새 ID 또는 알 수 없는 ID와 함께 제공된 기준이나 수준은 오류로 간주됩니다.
  5. 새로운 기준과 수준의 순서는 새로운 UI 순서(앞서 언급한 제한사항이 적용됨)로 간주됩니다.

기준표 업데이트를 위한 함수를 추가합니다.

def update_rubric(service, course_id, coursework_id, rubric_id, body):
    """
    Updates the rubric on a coursework.
    """
    try:
        rubric = service.courses().courseWork().rubrics().patch(
            courseId=course_id,
            courseWorkId=coursework_id,
            id=rubric_id,
            body=body,
            updateMask='criteria',
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
        ).execute()

        return rubric

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

이 예시에서는 criteria 필드가 updateMask로 수정을 위해 지정됩니다.

그런 다음 main.py를 수정하여 앞서 언급한 각 업데이트 규칙을 변경합니다.

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

    # Get the latest rubric.
    rubric = get_rubric(service, YOUR_COURSE_ID, YOUR_COURSEWORK_ID)
    criteria = rubric.get("criteria")
    """
    The "criteria" property should look like this:
    [
        {
            "id": "NkEyMdMyMzM2Nxkw",
            "title": "Argument",
            "description": "How well structured your argument is.",
            "levels": [
                {
                    "id": "NkEyMdMyMzM2Nxkx",
                    "title": "Convincing",
                    "description": "A compelling case is made.",
                    "points": 30
                },
                {
                    "id": "NkEyMdMyMzM2Nxky",
                    "title": "Passable",
                    "description": "Missing some evidence.",
                    "points": 20
                },
                {
                    "id": "NkEyMdMyMzM2Nxkz",
                    "title": "Needs Work",
                    "description": "Not enough strong evidence..",
                    "points": 0
                }
            ]
        },
        {
            "id": "NkEyMdMyMzM2Nxk0",
            "title": "Spelling",
            "description": "How well you spelled all the words.",
            "levels": [...]
        },
        {
            "id": "NkEyMdMyMzM2Nxk4",
            "title": "Grammar",
            "description": "How grammatically correct your sentences are.",
            "levels": [...]
        }
    ]
    """

    # Make edits. This example will make one of each type of change.

    # Add a new level to the first criteria. Levels must remain sorted by
    # points.
    new_level = {
        "title": "Profound",
        "description": "Truly unique insight.",
        "points": 50
    }
    criteria[0]["levels"].insert(0, new_level)

    # Remove the last criteria.
    del criteria[-1]

    # Update the criteria titles with numeric prefixes.
    for index, criterion in enumerate(criteria):
        criterion["title"] = f"{index}: {criterion['title']}"

    # Resort the levels from descending to ascending points.
    for criterion in criteria:
        criterion["levels"].sort(key=lambda level: level["points"])

    # Update the rubric with a patch call.
    new_rubric = update_rubric(
        service, YOUR_COURSE_ID, YOUR_COURSEWORK_ID, YOUR_RUBRIC_ID, rubric)

    print(json.dumps(new_rubric, indent=4))

이제 변경사항이 클래스룸에 있는 교사에게 반영됩니다.

클래스룸 UI에서 업데이트된 기준표 보기그림 4. 업데이트된 기준표 보기

기준표로 채점된 제출물 보기

현재 학생 제출물은 API를 사용하여 기준표를 사용해 채점할 수 없지만, 클래스룸 UI에서 기준표를 사용해 채점된 제출물의 기준표 성적은 확인할 수 있습니다.

클래스룸 UI에서 학생으로서 샘플 과제를 작성하여 제출합니다. 그런 다음 교사는 기준표를 사용하여 과제를 채점합니다.

클래스룸 UI에서 기준표 성적 보기그림 5. 채점 시 기준표에 대한 교사용 화면

기준표를 사용해 채점된 학생 제출물에는 draftRubricGradesassignedRubricGrades라는 두 가지 새로운 속성이 있으며, 이 속성은 각각 초안 및 할당된 채점 상태에서 교사가 선택한 점수와 수준을 나타냅니다.

또한 연결된 기준표가 있는 학생 제출물에는 채점하기 전이라도 rubricId 필드가 포함됩니다. 이 값은 CourseWork와 연결된 최신 기준표를 나타내며 교사가 기준표를 삭제하고 다시 만들면 이 값이 변경될 수 있습니다.

기존의 studentSubmissions.GetstudentSubmissions.List 메서드를 사용하여 채점된 제출물을 볼 수 있습니다.

main.py에 다음 함수를 추가하여 학생 제출물을 나열합니다.

def get_latest_submission(service, course_id, coursework_id):
    """Retrieves the last submission for an assignment."""
    try:
        response = service.courses().courseWork().studentSubmissions().list(
            courseId = course_id,
            courseWorkId = coursework_id,
            pageSize=1,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
        ).execute()
        submissions = response.get("studentSubmissions", [])
        if not submissions:
            print(
                """No submissions found. Did you remember to turn in and grade
                   the assignment in the UI?""")
            return
        submission = submissions[0]
        return submission

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

그런 다음 main.py를 업데이트하고 실행하여 제출물 성적을 확인합니다.

if __name__ == '__main__':
    service = build_authenticated_service(YOUR_API_KEY)

    submission = get_latest_submission(
        service, YOUR_COURSE_ID, YOUR_COURSEWORK_ID)
    print(json.dumps(submission, indent=4))

draftRubricGradesassignedRubricGrades에는 다음이 포함됩니다.

  • 해당하는 기준표 기준의 criterionId입니다.
  • 교사가 각 기준에 할당한 points 이는 선택한 수준일 수도 있고 교사가 덮어쓸 수도 있습니다.
  • 각 기준에 대해 선택된 등급의 levelId입니다. 교사가 등급을 선택하지 않았지만 기준에 점수를 할당한 경우에는 이 필드가 표시되지 않습니다.

이 목록에는 교사가 레벨을 선택했거나 점수를 설정한 기준의 항목만 포함됩니다. 예를 들어 교사가 채점 중에 하나의 기준만 사용하기로 선택하면 기준표에 여러 기준이 있더라도 draftRubricGradesassignedRubricGrades에는 항목이 하나만 있습니다.

기준표 삭제하기

기준표는 표준 Delete 요청으로 삭제할 수 있습니다. 다음 코드는 완전성을 위한 예시 함수를 보여주지만 채점이 이미 시작되었으므로 현재 기준표를 삭제할 수 없습니다.

def delete_rubric(service, course_id, coursework_id, rubric_id):
    """Deletes the rubric on a coursework."""
    try:
        service.courses().courseWork().rubrics().delete(
            courseId=course_id,
            courseWorkId=coursework_id,
            id=rubric_id,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
        ).execute()

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

기준표 내보내기 및 가져오기

기준표는 교사가 재사용할 수 있도록 수동으로 Google 스프레드시트로 내보낼 수 있습니다.

코드에서 기준표 기준을 지정하는 것 외에도 criteria 대신 기준표 본문에 sourceSpreadsheetId를 지정하여 내보낸 시트에서 기준표를 만들고 업데이트할 수 있습니다.

def create_rubric_from_sheet(service, course_id, coursework_id, sheet_id):
    """Creates an example rubric on a coursework."""
    try:
        body = {
            "sourceSpreadsheetId": sheet_id
        }

        rubric = service.courses().courseWork().rubrics().create(
            courseId=course_id, courseWorkId=coursework_id, body=body,
            # Specify the preview version. Rubrics CRUD capabilities are
            # supported in V1_20231110_PREVIEW and later.
            previewVersion="V1_20231110_PREVIEW"
            ).execute()

        print(f"Rubric created with ID {rubric.get('id')}")
        return rubric

    except HttpError as error:
        print(f"An error occurred: {error}")
        return error

의견

문제를 발견했거나 의견이 있으면 의견을 공유해 주세요.