成績の設定と更新

このガイドでは、Google Classroom API の採点関連のコードサンプルについて説明します。成績のガイドを読んで、Classroom の成績評価のコンセプトを理解してください。

生徒の提出物の成績を設定する

StudentSubmission リソースには、成績を格納する 2 つのフィールドがあります。assignedGrade は生徒に報告される成績で、draftGrade は教師のみが確認できる暫定的な成績です。これらのフィールドは courses.courseWork.studentSubmissions.patch を使用して更新されます。

PythonJava
studentSubmission = {
 
'assignedGrade': 99,
 
'draftGrade': 80
}

service
.courses().courseWork().studentSubmissions().patch(
    courseId
=course_id,
    courseWorkId
=coursework_id,
    id
=studentsubmission_id,
    updateMask
='assignedGrade,draftGrade',
    body
=studentSubmission).execute()
classroom/snippets/src/main/java/PatchStudentSubmission.java
StudentSubmission studentSubmission = null;
try {
 
// Updating the draftGrade and assignedGrade fields for the specific student submission.
 
StudentSubmission content =
      service
         
.courses()
         
.courseWork()
         
.studentSubmissions()
         
.get(courseId, courseWorkId, id)
         
.execute();
  content
.setAssignedGrade(90.00);
  content
.setDraftGrade(80.00);

 
// The updated studentSubmission object is returned with the new draftGrade and assignedGrade.
  studentSubmission
=
      service
         
.courses()
         
.courseWork()
         
.studentSubmissions()
         
.patch(courseId, courseWorkId, id, content)
         
.set("updateMask", "draftGrade,assignedGrade")
         
.execute();

 
/* Prints the updated student submission. */
 
System.out.printf(
     
"Updated student submission draft grade (%s) and assigned grade (%s).\n",
      studentSubmission
.getDraftGrade(), studentSubmission.getAssignedGrade());
} catch (GoogleJsonResponseException e) {
 
// TODO (developer) - handle error appropriately
 
GoogleJsonError error = e.getDetails();
 
if (error.getCode() == 404) {
   
System.out.printf(
       
"The courseId (%s), courseWorkId (%s), or studentSubmissionId (%s) does "
           
+ "not exist.\n",
        courseId
, courseWorkId, id);
 
} else {
   
throw e;
 
}
} catch (Exception e) {
 
throw e;
}
return studentSubmission;

Classroom UI を使用する場合、教師はまず仮の成績を保存してからでないと、成績を割り当てることができません。割り当てられた成績を生徒に返却できます。アプリケーションは、次の 2 つの方法で生徒の課題を採点できます。

  • draftGrade のみを割り当てます。これは、教師が最終的な成績を決定する前に手動で成績を確認できるようにする場合などに便利です。生徒は下書きの成績を確認できません。

  • draftGradeassignedGrade の両方を割り当てることで、課題を完全に採点できます。

割り当てられた成績を読み取る

特定の課題アイテムのすべての成績を一覧表示するには、courses.courseWork.studentSubmissions.list メソッドのレスポンス オブジェクトを調べます。

PythonJava
response = coursework.studentSubmissions().list(
    courseId
=course_id,
    courseWorkId
=coursework_id,
    pageSize
=10 # optionally include `pageSize` to restrict the number of student submissions included in the response.
).execute()
submissions
.extend(response.get('studentSubmissions', []))

if not submissions:
   
print('No student submissions found.')

print('Student Submissions:')

for submission in submissions:
   
print(f"Submitted at:"
          f
"{(submission.get('userId'), submission.get('assignedGrade'))}")
classroom/snippets/src/main/java/ListStudentSubmissions.java
  ListStudentSubmissionsResponse response =
      service
         
.courses()
         
.courseWork()
         
.studentSubmissions()
         
.list(courseId, courseWorkId)
         
.setPageToken(pageToken)
         
.execute();

 
/* Ensure that the response is not null before retrieving data from it to avoid errors. */
 
if (response.getStudentSubmissions() != null) {
    studentSubmissions
.addAll(response.getStudentSubmissions());
    pageToken
= response.getNextPageToken();
 
}
} while (pageToken != null);

if (studentSubmissions.isEmpty()) {
 
System.out.println("No student submissions found.");
} else {
 
for (StudentSubmission submission : studentSubmissions) {
   
System.out.printf(
       
"User ID %s, Assigned grade: %s\n",
        submission
.getUserId(), submission.getAssignedGrade());
 
}
}

コースの総合成績を決定する

Classroom API では、デベロッパーがコースの全体的な成績を読み書きすることはできませんが、プログラムで計算することはできます。採点の設定に関するヘルプセンター記事では、この計算に関するヒントを紹介しています。Course リソースには、計算に役立つ gradebookSettings フィールドが含まれています。

総合評価を計算する場合は、遅れた課題、許可された課題、提出されていない課題を管理する際に注意すべきヒントをご確認ください。

生徒の回答のステータスを管理する

生徒の回答は、提出の取り消し、提出、返却のいずれかになります。StudentSubmission の state フィールドは、現在の状態を示します。状態を変更するには、次のいずれかのメソッドを呼び出します。

これらのメソッドはすべて、空の body パラメータを受け入れます。次に例を示します。

PythonJava
service.courses().courseWork().studentSubmission().turnIn(
    courseId
=course_id,
    courseWorkId
=coursework_id,
    id
=studentsubmission_id,
    body
={}).execute()
classroom/snippets/src/main/java/ReturnStudentSubmission.java
try {
  service
     
.courses()
     
.courseWork()
     
.studentSubmissions()
     
.classroomReturn(courseId, courseWorkId, id, null)
     
.execute();
} catch (GoogleJsonResponseException e) {
 
// TODO (developer) - handle error appropriately
 
GoogleJsonError error = e.getDetails();
 
if (error.getCode() == 404) {
   
System.out.printf(
       
"The courseId (%s), courseWorkId (%s), or studentSubmissionId (%s) does "
           
+ "not exist.\n",
        courseId
, courseWorkId, id);
 
} else {
   
throw e;
 
}
} catch (Exception e) {
 
throw e;
}

採点用アドオンの添付ファイル

Classroom アドオンのデベロッパーは、個々のアドオンの添付ファイルに成績を設定できます。また、教師が生徒の提出物を確認するときに成績が表示されるように構成することもできます。詳細については、アクティビティ タイプの添付ファイル成績のパスバックのチュートリアルをご覧ください。