我在google表单上创建了这个心理学调查。除了通常的电子邮件,名称等之外,它还有大约20个选择题。所以你看到没有任何正确/错误的答案。
如何伪造结果,或创建50个表单提交?请原谅我的无知,但结果是否会出现在Google电子表格中?我应该在Google电子表格中填写50个详细信息吗?
如何伪造结果,或创建50个表单提交?
见Use App Scripts to open form and make a selection。
请原谅我的无知,但结果是否会出现在Google电子表格中?我应该在Google电子表格中填写50个详细信息吗?
答复将记录在两个地方;在表单本身(您可以在其中查看响应摘要)以及电子表格中。如果您的目的是验证提交回复的过程,那么您应该模拟提交。
@Mogsdad's answer引用了一个基于URL的解决方案,在该解决方案中,您的脚本不知道可以针对给定问题(或多少个问题等)提出何种答案,这在某些用例中可能会出现问题。
您可以使用Forms Service以编程方式为Google表单创建响应,该表单允许您从可用选项中随机选择可能的答案(例如,引用预定义的“书面”答案库,例如文本/段落答案) 。
假设您有一个仅供多项选择的测试,每个问题的选择具有非常数的选择:
function foo() {
const form = FormApp.openById("some form id");
const randomSubs = [], nSubs = 50;
while (randomSubs.length < nSubs)
randomSubs.push(createRandomSubmission_(form).submit());
// doAwesomeAnalysis(randomSubs); // etc.
}
// Constructs a random response for the given form, and returns it to the caller (e.g. for submission, etc).
function createRandomSubmission_(form) {
const resp = form.createResponse();
const questions = form.getItems().filter(isAnswerable_);
questions.forEach(function (question) {
var answer = getRandomAnswer_(question);
resp.withItemResponse(answer);
});
return resp;
}
var iTypes = FormApp.ItemType;
function isAnswerable_(item, index, allItems) {
const iType = item.getType();
switch (iType) {
case iTypes.MULTIPLE_CHOICE:
case iTypes.CHECKBOX:
/** add more type cases here as you implement the relevant answer generator */
return true;
default:
return false;
}
}
// Uses the item type to call the appropriate answer generator.
function getRandomAnswer_(q) {
const qType = q.getType();
switch (qType) {
case iTypes.MULTIPLE_CHOICE:
return getRandomMultipleChoiceAnswer_(q.asMultipleChoiceItem());
/** add more type cases + handlers here as you implement the relevant answer generator */
default:
throw new TypeError("Answering questions of type '" + qType + "' is not yet implemented");
}
}
// Uniformly samples possible choices (including the "other" option, if enabled).
// Returns the item's ItemResponse
function getRandomMultipleChoiceAnswer_(mcItem) {
const choices = mcItem.getChoices();
const i = Math.floor( Math.random() * (choices.length + mcItem.hasOtherOption()) );
return mcItem.createResponse( (i < choices.length) ?
choices[i] : getRandomMCOtherOption_(mcItem)
);
}
function getRandomMCOtherOption_(mcItem) {
// This function will be highly dependent on your situation.
// It's your choice how you identify the MC item to determine what an "other" option could
// be for a given question. getTitle() and getIndex() may be useful too.
switch (mcItem.getId()) {
default:
throw new Error("Not Implemented Yet");
}
}