ตั้งค่าและอัปเดตคะแนน

คู่มือนี้มีตัวอย่างโค้ดที่เกี่ยวข้องกับการให้คะแนนสำหรับ Classroom API เอกสารนี้มุ่งเน้นที่เส้นทางการให้คะแนนหลักของ Classroom ซึ่งได้แก่ การจัดการสถานะStudentSubmission และคะแนน

อ่านคู่มือคะแนนเพื่อทำความคุ้นเคยกับแนวคิดการให้คะแนนใน Classroom

จัดการสถานะ StudentSubmission

StudentSubmission อาจยกเลิกการส่ง ส่ง หรือส่งคืนได้ ฟิลด์ state จะระบุสถานะปัจจุบัน โดยปกติแล้ว การให้คะแนนจะดำเนินการหลังจากที่StudentSubmissionอยู่ในสถานะTURNED_IN

หากต้องการเปลี่ยนสถานะโดยใช้ Classroom API ให้เรียกใช้เมธอดใดเมธอดหนึ่งต่อไปนี้

  • courses.courseWork.studentSubmissions.turnIn: มีเพียงนักเรียนที่เป็นเจ้าของStudentSubmissionเท่านั้นที่ส่งได้
  • courses.courseWork.studentSubmissions.reclaim: มีเพียงนักเรียน/นักศึกษาที่เป็นเจ้าของStudentSubmissionเท่านั้นที่จะอ้างสิทธิ์ได้ คุณจะขอรับสิทธิ์ส่งคืนได้ก็ต่อเมื่อส่งงานแล้วเท่านั้น
  • courses.courseWork.studentSubmissions.return: เฉพาะครูใน หลักสูตรเท่านั้นที่ส่งStudentSubmissionคืนได้ ระบบจะส่งคืนงานได้ก็ต่อเมื่อนักเรียนส่งงานแล้วเท่านั้น

วิธีการเหล่านี้ทั้งหมดยอมรับพารามิเตอร์ body ที่ว่างเปล่า ดังที่แสดงในตัวอย่างต่อไปนี้

Python

service.courses().courseWork().studentSubmission().turnIn(
    courseId=course_id,
    courseWorkId=coursework_id,
    id=studentsubmission_id,
    body={}).execute()

Java

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;
}

ให้คะแนนงานที่นักเรียนส่ง

ทรัพยากร StudentSubmission มี 2 ฟิลด์สำหรับจัดเก็บคะแนนโดยรวมของงาน CourseWork ที่ให้คะแนนแล้ว ดังนี้

  • draftGrade เป็นคะแนนเบื้องต้นที่ครูเท่านั้นที่จะเห็น
  • assignedGrade คือคะแนนที่รายงานให้นักเรียนทราบ

ระบบจะอัปเดตช่องเหล่านี้โดยใช้ courses.courseWork.studentSubmissions.patch ดังที่แสดงใน ตัวอย่างต่อไปนี้

Python

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()

Java

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;

เมื่อทำงานกับ UI ของ Classroom ครูจะตั้งค่า assignedGrade ไม่ได้จนกว่าจะบันทึก draftGrade ก่อน จากนั้นคุณจะส่งassignedGrade คืนให้นักเรียนได้ แอปพลิเคชันของคุณให้คะแนนงานของนักเรียนได้ 2 วิธี ดังนี้

  • กำหนดเฉพาะ draftGrade ซึ่งมีประโยชน์ เช่น ในการอนุญาตให้ ครูตรวจสอบคะแนนด้วยตนเองก่อนที่จะสรุปคะแนน นักเรียนจะไม่เห็นคะแนนฉบับร่าง

  • กำหนดทั้ง draftGrade และ assignedGrade เพื่อให้คะแนนงานได้อย่างสมบูรณ์

ใช้อาร์กิวเมนต์ updateMask เพื่อกำหนดค่าช่องที่จะตั้งค่า

ดูเพิ่มไฟล์แนบในคำตอบของนักเรียนเพื่อทำความเข้าใจขอบเขตและสิทธิ์ ที่จำเป็นในการแก้ไข StudentSubmissions

อ่านคะแนนที่มอบหมาย

คุณเข้าถึงเกรดทั้งหมดสำหรับCourseWorkที่เฉพาะเจาะจงได้โดยใช้วิธีการ courses.courseWork.studentSubmissions.list เพื่อดึงข้อมูลStudentSubmissionsที่เกี่ยวข้องทั้งหมด และตรวจสอบช่อง assignedGrade และ draftGrade ที่เหมาะสม

Python

response = coursework.studentSubmissions().list(
    courseId=course_id,
    courseWorkId=coursework_id,
    # optionally include `pageSize` to restrict the number of student
    # submissions included in the response.
    pageSize=10
).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'))}")

Java

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());
  }
}

ดูดึงคำตอบของนักเรียนเพื่อทำความเข้าใจขอบเขตและสิทธิ์ที่จำเป็น ในการอ่าน StudentSubmissions

กำหนดคะแนนรวมของหลักสูตร

Classroom API ไม่อนุญาตให้นักพัฒนาแอปอ่านหรือเขียน คะแนนรวมของหลักสูตร แต่คุณสามารถคำนวณได้โดยใช้โปรแกรม หากต้องการคำนวณคะแนนโดยรวม โปรดอ่านคู่มือการให้คะแนนเพื่อทำความเข้าใจ แนวคิดสำคัญๆ เช่น CourseWorkที่ยกเว้น ช่วงการให้คะแนน และระบบการให้คะแนนต่างๆ

ไฟล์แนบของส่วนเสริมการให้คะแนน

หากคุณเป็นนักพัฒนาส่วนเสริมของ Classroom คุณสามารถตั้งค่าคะแนนสำหรับไฟล์แนบของส่วนเสริมแต่ละรายการ และกำหนดค่าให้ครูมองเห็นคะแนนเมื่อตรวจงานของนักเรียนได้ ดูข้อมูลเพิ่มเติมได้ที่ไฟล์แนบประเภทกิจกรรมและคำแนะนำแบบทีละขั้นตอนสำหรับการส่งคืนคะแนน

คะแนนเกณฑ์การให้คะแนน

StudentSubmissions มีฟิลด์ที่แสดงคะแนนที่ให้ตาม Rubrics:

  • draftRubricGrade คือชุดคะแนนCriterionที่ยังไม่แน่นอนซึ่งจะแสดงต่อครูเท่านั้น
  • assignedRubricGrade คือชุดคะแนน Criterion ที่รายงานต่อ นักเรียน

คุณตั้งคะแนนรูบริกโดยใช้ Google Classroom API ไม่ได้ แต่จะอ่านได้ ดูข้อมูลเพิ่มเติมได้ที่คู่มือเกณฑ์การให้คะแนนและข้อจำกัด