Online learning systems have many settings – sometimes, you need to make a similar change across dozens or hundreds of assignments. Codio has an API that can automate bulk tasks quickly to make this easier.
To get a working copy of the examples below and step-by-step setup instructions, use the Hello Codio API Starter Pack.
Example 1: Set Time-Based Accommodations
At the beginning of the semester, you can easily add the correct time limit extensions on all exams for students who receive extra time accommodations. In the code below, you can easily specify the course, student, and accommodation to quickly apply it to all timed course assignments.
require('dotenv').config() import codio from 'codio-api-js' import _ from 'lodash' const api = codio.v1
const clientId = process.env['CLIENT'] || 'clientId' const secret = process.env['SECRET'] || 'secret'
// hardcoded values const courseId = 'courseId' const studentEmail = 'student@email.com' const multiplier = 1.5
async function main() { await api.auth(clientId, secret) // finds the student using their email which is specified above const students = await api.course.getStudents(courseId) const student = _.find(students, {email: studentEmail}) if (_.isUndefined(student)) { throw new Error(`${studentEmail} student not found`) } // get all assignments in the course const course = await api.course.info(courseId) for (const module of course.modules) { console.log(`${module.name} :`) for (const assignment of module.assignments) { // check if assignment is timed const settings = await api.assignment.getSettings(courseId, assignment.id) if (!settings.examMode || !settings.examMode.timedExamMode.enabled) { // not an exam continue } // extends time limit based on multiplier specified above const timeLimit = settings.examMode.timedExamMode.duration * multiplier console.log(`Extending ${assignment.name} from ${settings.examMode.timedExamMode.duration} minutes to ${timeLimit} minutes for student ${student.name}`) const extension = timeLimit - settings.examMode.timedExamMode.duration await api.assignment.updateStudentTimeExtension(courseId, assignment.id, student.id, { extendedTimeLimit: extension }) } } }
main().catch(_ => { console.error(_); process.exit(1) })
|
In the code above, Codio’s API allows you to get the list of students in the course quickly and the list of course assignments, get each assignment’s settings, and set an extension.
Example 2: Configuring Late Penalties for Entire Course
Use one script to set all of your course assignments' late penalties. For example, in the code below, you can easily specify the course to apply late penalties to all course assignments quickly.
require('dotenv').config() import codio from 'codio-api-js' import _ from 'lodash' import { Penalty } from 'codio-api-js/lib/lib/assignment' const api = codio.v1
const clientId = process.env['CLIENT'] || 'clientId' const secret = process.env['SECRET'] || 'secret'
// hardcoded values const courseId = 'courseId'
function setDate(date: Date, shiftDays = 0, shiftHours = 0, shiftMinutes = 0): Date { const res = new Date(date); res.setDate(res.getDate() + shiftDays) res.setHours(res.getHours() + shiftHours) res.setMinutes(res.getMinutes() + shiftMinutes) return res }
async function main() { await api.auth(clientId, secret)
const course = await api.course.info(courseId) for (const assignment of course.assignments) { const settings = await api.assignment.getSettings(courseId, assignment.id) console.log(`Updating ${assignment.name}`) if (!settings.endTime) { continue } const penalties: Penalty[] = [] // Assignments can be up to 3 days late with a 10% penalty and up to 7 days late with a 30% penalty const dueDate = new Date(settings.endTime) dueDate.setDate(dueDate.getDate() - 10) // set Due Date 10 days before the end final date
penalties.push({ id: 1, percent: 10, datetime: setDate(dueDate, 3), message: '10%' }) penalties.push({ id: 2, percent: 30, datetime: setDate(dueDate, 7), message: '30%' }) await api.assignment.updateSettings(courseId, assignment.id, {penalties}) } }
main().catch(_ => { console.error(_); process.exit(1) })
|
In the code above, Codio’s API lets you quickly get the list of course assignments, get each assignment’s settings, including the End Date, and set the late penalties.
Have a few different late policies based on assignment type? Check out the more complex example in the Hello Codio API Starter Pack.
Example 3: Give students extensions
Use a script to quickly add extensions for a student who is out sick for specific assignments and/or modules. For example, in the code below, you can easily specify the course, student, modules, or assignments and how much of an extension to apply.
require('dotenv').config() import codio from 'codio-api-js' import { Assignment } from 'codio-api-js/lib/lib/course' import _ from 'lodash' const api = codio.v1
const clientId = process.env['CLIENT'] || 'clientId' const secret = process.env['SECRET'] || 'secret'
// hardcoded values const courseId = 'courseId' const studentEmail = 'student@email.com' let moduleName = 'module name' let assignmentNames = 'assignment 1,assignment 2' let shiftDays = 2 let shiftHours = 12 let shiftMinutes = 30
async function main() { await api.auth(clientId, secret) const assignments = _.compact(assignmentNames.split(','))
// finds the student using their email which is specified above const students = await api.course.getStudents(courseId) const student = _.find(students, {email: studentEmail}) if (_.isUndefined(student)) { throw new Error(`${studentEmail} student not found`) } const course = await api.course.info(courseId) const toExtend: Assignment[] = [] // finds all assignments in specified modules for (const module of course.modules) { if (module.name === moduleName) { toExtend.push.apply(module.assignments) continue } // finds specified assignments for (const assignment of module.assignments) { if (assignments.includes(assignment.name)) { toExtend.push(assignment) } } }
// shifts the deadlines for specified student const extend = shiftDays * 24 * 60 + shiftHours * 60 + shiftMinutes
for(const assignment of toExtend) { console.log(`Extending ${assignment.name} for ${student.name} by ${extend} minutes`) await api.assignment.updateStudentTimeExtension(courseId, assignment.id, student.id, { extendedDeadline: extend }) } }
main().catch(_ => { console.error(_); process.exit(1) })
|
In the code above, Codio’s API allows you to quickly get the list of students in the course along with the list of course assignments and set an extension.
To see a different example script for extensions that sets all assignments in a date range to a single due date, check out the Hello Codio API Starter Pack.
Codio’s API can be used for various use cases in addition to the examples described above. If you need functionality added to our API, you can make a feature request in the product using the Feedback menu item or email help@codio.com.