Created
April 18, 2014 07:14
-
-
Save biarm/11028870 to your computer and use it in GitHub Desktop.
Google Apps script for creating test forms based on a question bank
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
function onOpen() { | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu('Баба ЕГЭ') | |
.addItem('Задать количество вопросов', 'setNumQuestions') | |
.addSeparator() | |
.addItem('Создать тест', 'makeRandomTest') | |
.addToUi(); | |
} | |
function setNumQuestions() { | |
var app = UiApp.createApplication(); | |
app.setTitle("Сколько вопросов должно быть в тесте?"); | |
var panel = app.createVerticalPanel(); | |
var textBox = app.createTextBox(); | |
textBox.setName('myTextBox').setId('myTextBox'); | |
var button = app.createButton('Отправить'); | |
panel.add(textBox); | |
panel.add(button); | |
var clickHandler = app.createServerClickHandler("respondToSubmit"); | |
button.addClickHandler(clickHandler); | |
clickHandler.addCallbackElement(panel); | |
app.add(panel); | |
var doc = SpreadsheetApp.getActive(); | |
doc.show(app); | |
} | |
function respondToSubmit(e) { | |
var app = UiApp.getActiveApplication(); | |
var textBoxValue = e.parameter.myTextBox; | |
var num = parseInt(textBoxValue); | |
Logger.log(num); | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var s = ss.getActiveSheet(); | |
ss.getRange("I2").setValue(num); | |
return app.close(); | |
} | |
function makeRandomTest() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var s = ss.getActiveSheet(); | |
var headers = s.getRange(1, 1, 1, s.getLastColumn()).getValues()[0]; | |
var rows = s.getRange(1, 1, s.getLastRow()).getValues(); | |
var num = ss.getRange("I2").getValue() | |
var rowsNumbers = []; | |
for (j = 1; j < rows.length; j++) { | |
rowsNumbers.push(j); | |
} | |
Shuffle(rowsNumbers); | |
var day = new Date(); | |
day.setDate(day.getDate()) | |
var form = FormApp.create('Проверочный тест' + ' ' + day); | |
form.addTextItem() | |
.setTitle("Ваше имя?"); | |
for (i = 1; i < num+1; i++) { | |
var question = s.getRange(rowsNumbers[i]+1,1).getValue(); | |
var choice1 = s.getRange(rowsNumbers[i]+1,2).getValue(); | |
var choice2 = s.getRange(rowsNumbers[i]+1,3).getValue(); | |
var choice3 = s.getRange(rowsNumbers[i]+1,4).getValue(); | |
var choice4 = s.getRange(rowsNumbers[i]+1,5).getValue(); | |
var item = form.addMultipleChoiceItem(); | |
item.setTitle(question) | |
.setChoiceValues([choice1,choice2,choice3,choice4]); | |
var idForm = form.getId(); | |
ss.getRange('I3').setValue('https://docs.google.com/forms/d/' + idForm); | |
} | |
} | |
function Shuffle(o) { | |
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); | |
return o; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment