Tuesday, February 4, 2014

Creating Individualized Math Quizzes using Google Forms

I have been working on using Google Apps to give problems individualized math assignments. It is quite an arduous task since nice Math Type doesn't play so well with Google Apps since they got rid of their LaTeX editor back in 2009 or 2010...

I resorted to running the LaTex through the Google Charts API which creates an image of the math with "nice" formatting. See my post here detailing the process: Blog Post
Then I created a set of problems in Mathematica, exported them in TeX format as a .csv and then uploaded them to my Google Sheet.
I needed to have them URLencoded to play well with the Google Charts API so I created a custom function in the Spreadsheet to do that and then Concatenated them.

Now I have a list of problems in the right form in the spreadsheet (see the Questions tab in my example below).
I then created a script that will create a Form for each student and add questions to it so each student will get an individualized quiz. (I do need to randomize the questions, but that wasn't the focus of my creation. I needed it to run first :)
The script also writes the answer key to the problems it chooses on the Student Data sheet.

I will work on randomizing the questions and post when it is finished (hopefully tomorrow), but here is an example:

http://goo.gl/of3NZu

Here is the script (it is still an alpha copy,  I need to stop the script when there are no more names). You also will need to add the URLencoder script if you don't copy the Spreadsheet:

function createForm(){
  //get the student data from the spreadsheet
  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);
 
  //get the student info by row from the student sheet
  for (var i = 0; i < studentObjects.length; ++i)
  {
   var currentStudentObject = studentObjects[i]  //get the ith row of data from the studentObjects array
   Logger.log(currentStudentObject);
   //This fetches a document by ID (found in the URL) and opens it up.
   var studentLastName = currentStudentObject.lastName;
   var studentFirstName = currentStudentObject.firstName;
   var studentEmailAddress = currentStudentObject.emailAddress;
   
    // Create a new form, then add image item followed by a blank text item for the student response from https://developers.google.com/apps-script/reference/forms/
   var form = FormApp.create('New Quiz for ' + studentFirstName + " " + studentLastName);
   
   //find out where the form is
   var publishedURL = form.getPublishedUrl();
   var editURL = form.getEditUrl();
   //write the URLs to the spreadsheet on the Student Data sheet in column D and E respectively
   var rowNumber = i + 2;
   var publishedURLCell = 'D' + rowNumber;
   var writePublishedURL = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange(publishedURLCell).setValue(publishedURL);
   var editURLCell = 'E' + rowNumber;
   var writeEditURL = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange(editURLCell).setValue(editURL);
   
   //find the question from column G on the Questions sheet (Need to randomize later)
   //find the answer from column G on the Questions sheet (Need to randomize later)
   var problemCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('G'+ (i+2)).getValue();
   var answerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('C'+ (i+2)).getValue();
 
   //Problem 1
   //add the question to the form
   var problem = UrlFetchApp.fetch(problemCell);
    form.addImageItem() //add an image item
     .setTitle('Please write your answer in the box below the problem')
     .setHelpText('Solve This Problem') // The help text is the image description
     .setImage(problem); //the actual image with the question in LaTeX format
    form.addTextItem(); //puts a blank text question below so the student can answer the imageproblem
   
   //write the answer to the spreadsheet
   var problemAnswer = answerCell;
   var writeAnswerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange('F'+ (i+2)).setValue(problemAnswer);
 
   //Problem 2
    //find the question from column G on the Questions sheet (Need to randomize later)
   //find the answer from column G on the Questions sheet (Need to randomize later)
   var problemCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('G'+ (i+3)).getValue();
   var answerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('C'+ (i+3)).getValue();
   //add the question to the form
   var problem = UrlFetchApp.fetch(problemCell);
    form.addImageItem() //add an image item
     .setTitle('Please write your answer in the box below the problem')
     .setHelpText('Solve This Problem') // The help text is the image description
     .setImage(problem); //the actual image with the question in LaTeX format
    form.addTextItem(); //puts a blank text question below so the student can answer the imageproblem
   
   //write the answer to the spreadsheet
   var problemAnswer = answerCell;
   var writeAnswerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange('G'+ (i+2)).setValue(problemAnswer);
   
   
   //Problem 3
   //find the question from column G on the Questions sheet (Need to randomize later)
   //find the answer from column G on the Questions sheet (Need to randomize later)
   var problemCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('G'+ (i+4)).getValue();
   var answerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Questions').getRange('C'+ (i+4)).getValue();
   //add the question to the form
   var problem = UrlFetchApp.fetch(problemCell);
    form.addImageItem() //add an image item
     .setTitle('Please write your answer in the box below the problem')
     .setHelpText('Solve This Problem') // The help text is the image description
     .setImage(problem); //the actual image with the question in LaTeX format
    form.addTextItem(); //puts a blank text question below so the student can answer the imageproblem
   
   //write the answer to the spreadsheet
   var problemAnswer = answerCell;
   var writeAnswerCell = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Student Data').getRange('H'+ (i+2)).setValue(problemAnswer);
 
 

   }
 
}




No comments:

Post a Comment