Friday, October 21, 2016

Google Classroom Assignment Completion Leaderboard

I've been using Google Classroom to post a lot of assignments that students can work on at their own pace; some of them are optional assignments, but most are required. We also have incentives set up for milestones such as 500 assignments completed by the class.

Rather than having to go through each assignment and see how many have been completed, and how many each student has completed, I've written a script that logs that information to a Google Spreadsheet. In case you'd like to do the same, here's the code and some basic instructions on how to set it up for yourself.
  1. Create a Google spreadsheet with a list of student email addresses in column A starting at row 2.
  2. Rename the sheet Achievements (or change line 17 of the code below).
  3. Under the Tools menu choose Script editor and paste in the code below.
  4. Follow the directions at https://developers.google.com/classroom/quickstart/apps-script to authorize your script.
  5. Run (play) the function listCourses to find the courseId for the course that you want to run this on
  6. Set up a trigger to run the function countClassroomAssignments() every morning or every week.

// Create a Google spreadsheet with a list of student email addresses in column A starting at row 2.
// Rename the sheet Achievements or change line 17 of this code.
// Under the Tools menu choose Script editor and paste in this code.
// Follow the directions at https://developers.google.com/classroom/quickstart/apps-script to authorize your script.
// Set up a trigger to run countClassroomAssignments() every morning or every week.
// https://developers.google.com/apps-script/reference/spreadsheet/sheet
function listCourses() {
// Run this then check the execution logs to find the courseId for your desired course
var courses = Classroom.Courses.list().courses;
for (x = 0; x < courses.length; x++) {
Logger.log('%s : %s', courses[x].id, courses[x].name);
}
}
function countClassroomAssignments() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Achievements");
var lastRow = sheet.getMaxRows();
var range = sheet.getRange(2, 1, lastRow); // row 2, column A, numberOfRows
var users = range.getValues();
for (i = 0; i < lastRow-1; i++) {
var email = users[i] + domain;
var numberSubmitted = countWork(email);
//Logger.log(email)
//Logger.log(numberSubmitted);
sheet.getRange(i+2, 2).setValue(numberSubmitted);
}
}
function countWork(email) {
var courseId = ""; // get this from the output of function listCourses() and put it between the quotation marks
var numberSubmitted = 0; // the variable we'll use for counting
var assignments = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, "-", {userId:email});
var submissions = assignments.studentSubmissions;
for (j = 0; j < submissions.length; j++) {
var submission = submissions[j];
var state = submission.state;
if (state == "TURNED_IN" || state == "RETURNED") {numberSubmitted++;} // add 1 if it has been turned in or returned
var grade = submission.assignedGrade;
var draftGrade = submission.draftGrade;
if (grade == 0 || draftGrade == 0) {numberSubmitted--;} // subtract 1 if you've given it a zero for being blank
}
return numberSubmitted;
}

No comments: