我正在尝试创建一个选择题测试,它使用GOOGLE 从一个问题库接受问题,结果存储在一个电子表格中。我已经知道如何创建一个测试,并将数据存储在电子表格中,但我不知道如何使用一个问题库。有人能帮我吗?
提前谢谢。
发布于 2017-05-08 00:28:01
最近,谷歌宣布表示,他们在Google脚本表单服务中添加了几种方法,使其能够以编程方式处理Google测试。
多亏了这一点,现在可以使用Google脚本从Google试题库创建测试了。这实际上和从电子表格中创建Google表单是一样的。
相关问题:
发布于 2017-07-30 20:54:08
我对这个话题也很感兴趣,但我是个完全的新手。从现有的代码片段中汲取灵感,我编写了一个简单的脚本,让我感到非常惊讶的是,它似乎有效。我在下面描述它,但请记住,这篇文章更多地是一个问题,而不是一个。我想听取更有经验的程序员的意见,因为我不确定我做的一切都还好。
因此,在我的简单方案中,问题库看起来像像这样 (请自己复制)。这应该是很清楚的,但是
A栏: Id (目前尚未使用,但今后可能有用);
列B:应该包含问题的文本(到目前为止,只有一个占位符,如Q1、Q2等)
C栏:每个问题的多重选择数
D列:正确的选择(其序号在下列列中)
E栏及以下:多重选择的文本,与C栏一样多(同样,暂时只有占位符。A3Q2是回答问题2的3);
脚本如下所示。我在里面写了很多评论。基本上,它创建一个名为"QBANK_1_form“的表单,其中包含电子表格中列出的选择题的子集。表单是在变量destinationFolder指定的文件夹中创建的。脚本确保没有重复的文件(我在调试时得到了很多文件)。
再说一遍,我真的很想从更严肃的程序员那里得到一些见解。这是我的第一次尝试,可能会很笨拙。我甚至很惊讶它能起作用。
function myFunction() {
// Id of the spreadsheet containing the question bank
var questionBankId = "1QCO-W2PxR9sLf2HtXreaEslyGTBdjswTgqxWDFycgKc";
// name of the output form
var formName = "QBANK_1_form";
// Id of the destination folder (not root to keep things tidy)
var destinationFolder = "ID_OF_YOUR_FOLDER_HERE"; // <-- change accordingly
// variable containg the total number of questions in the question bank (read from spreadsheet)
var question_num;
// number of questions in the output form (question_req <= question_num)
var question_req = 3; // chosen programmatically for the moment
// other variables
var r;
var c;
var ans;
var item;
var content;
var choices =[];
var nchoices;
var correct;
var iscorrect;
// ======================================================================================
// Delete possible files by the same name from target folder, to avoid duplicates
// ======================================================================================
// get target folder by ID
var myFolder = DriveApp.getFolderById('0Bw56O_ircsfpSWM2N2FQbm1fUWM');
// check if other files with the chosen name exist in the folder,
var thisFile = myFolder.getFilesByName(formName);
// if this is the case, iterate over them
while (thisFile.hasNext()) {
// get next file
var eachFile = thisFile.next();
// get its Id
var idToDLET = DriveApp.getFileById(eachFile.getId());
// delete the file
DriveApp.getFolderById(destinationFolder).removeFile(idToDLET);
}
// --------------------------------------------------------------------------------------
// ======================================================================================
// CREATE AND POPULATE THE FORM
// ======================================================================================
// --------------------------------------------------------------------------------------
// create the form
var form = FormApp.create(formName);
// ======================================================================================
// move the form to the desired folder (just for the sake of "housekeeping")
// ======================================================================================
// get Id of the file
var formFile = DriveApp.getFileById( form.getId() );
// add the to the desired folder
DriveApp.getFolderById(destinationFolder).addFile( formFile );
// delete the file from the roor folder
DriveApp.getRootFolder().removeFile(formFile);
// ======================================================================================
// start populating the form
// ======================================================================================
// open spreadsheet containing the question bank
var ss = SpreadsheetApp.openById(questionBankId);
// get number of questions in the question bank (number of rows-1);
var sheet = ss.getSheets()[0];
question_num = sheet.getLastRow() - 1;
// if question_req > question_num then set question_req=question_num, and the following is just a reshuffling of
// the questions in the question bank
if(question_req>question_num) {
question_req=question_num;
}
// get random indexes for the question subset
var index = questions(question_num,question_req);
// Make sure the form is a quiz.
form.setIsQuiz(true);
// iteration of reading spreadsheet and writing form accordingly
for(r = 0; r<question_req ; r++){
// create new multiple choice question
item = form.addMultipleChoiceItem();
// set value if correct
item.setPoints(10);
// get question text from question bank and write it in form
content = sheet.getRange(index[r]+1,2).getValue();
item.setTitle(content);
// get number of choices from question bank
nchoices = sheet.getRange(index[r]+1,3).getValue();
// get position of correct choice from question bank
correct = sheet.getRange(index[r]+1,4).getValue();
// create choice array
for(c = 1; c<nchoices+1;c++){
// determine whether the choice is correct
iscorrect = (c==correct);
// read choice from question bank
content = sheet.getRange(index[r]+1,c+4).getValue();
// add choice to choice array
choices[c-1] = item.createChoice(content,iscorrect);
}
// set choices
item.setChoices(choices);
}
}
// ------------------------------------------------------------------------------
// this function extracts question_req unique integers between 1 and question_num
// ------------------------------------------------------------------------------
function questions(question_num,question_req){
var index = [];
var ilist = [];
var i;
var n;
// create and populate index list
for (i = 0; i < question_num; i++) {
ilist[i]=i+1;
}
// create indexes of random questions
i = 0;
while(i<question_req){
n = Math.floor(Math.random() * (question_num-1));
if(ilist[n]==n+1){
index[i]=n+1;
ilist[n]=-1;
i++;
}
}
return index;
}https://stackoverflow.com/questions/39435580
复制相似问题