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

คู่มือนี้แสดงตัวอย่างโค้ดที่เกี่ยวข้องกับการให้คะแนนสำหรับ 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 ไม่ได้ แต่สามารถอ่านคะแนนได้ ดูข้อมูลเพิ่มเติมได้ที่ คู่มือและข้อจำกัดของเกณฑ์การให้คะแนน