Wednesday, February 5, 2014

Getting the student responses from the Individualized Math Quizzes

In my post yesterday I detailed how to make Individualized Math Quizzes for students using Google Forms. I have updated that script to now go to the forms and pull the responses back into the spreadsheet.

You can find the testing spreadsheet at the same location,  containing the updated script in the Script Editor:

The additions I made were to add a Menu, which currently has 2 items: the quiz generator and the response puller.

Some things I still am working on when I get some more spare time this week:
1. I want to add are better functionality of the number of questions and make them dynamic.
2. I will also add the function to grade the quiz based on the student response.
3. I will also work on the randomization of questions.
4. Make an option for a level of difficulty. For example, you could have 3 levels of questions Basic, Intermediate, and Advanced and choose from those questions.
5. I need to stop the script when there are no names left in the spreadsheet.

Hope you can find something useful here!

The menu was created using this script:
// The onOpen function is executed automatically every time a Spreadsheet is loaded
 function onOpen() {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var menuEntries = [];
    menuEntries.push({name: "Create Individualized Quizzes", functionName: "createForm"});
    menuEntries.push(null); // line separator
   menuEntries.push({name: "Pull First Student Response from Quiz", functionName: "pullResponses"});
   ss.addMenu("Individualized Quiz Creator Menu", menuEntries);

The script to pull the responses is here:
function pullResponses(){
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];
 var studentInformationRange = sheet.getRange(2,1,sheet.getMaxRows()-1,sheet.getMaxColumns());
 var studentObjects = getRowsData(sheet, studentInformationRange); 
 for (var i = 0; i < 3; ++i)  
 var currentStudentObject = studentObjects[i]  //get the ith row of data from the studentObjects array
 var formURL = currentStudentObject.urlOfPublishedForm; //get the URL of the form for the student
 // Open a form by URL and log the responses to each question. from:
 var form = FormApp.openByUrl(formURL);
 var formResponses = form.getResponses(); //get all of the responses
  for (var k = 0; k < formResponses.length; k++) {
   var formResponse = formResponses[k]; //get each response (this is a submission)
   var itemResponses = formResponse.getItemResponses(); //get all of the item responses
   for (var j = 0; j < itemResponses.length; j++) {  
     var itemResponse = itemResponses[j];  //take each item response 1 by 1
     //now write the student response into the spreadsheet
     //**need to index the columns by number dynamically, right now I use j+9
     var writeStudentAnswerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange(i+2, j+9).setValue(itemResponse.getResponse());