Last active
October 21, 2016 13:35
-
-
Save misterhay/b4b9135f584834290d65d24ac243d26b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment