【问题标题】:Google forms - Autofill a multiple choice surveyGoogle 表单 - 自动填写多项选择调查
【发布时间】:2014-12-17 13:09:07
【问题描述】:

我在谷歌表单上创建了这个心理学调查。除了通常的电子邮件、姓名等之外,它还有大约 20 个多项选择题。因此,您会看到没有任何正确/错误的答案。

我如何伪造结果,或者创建 50 个表单提交?请原谅我的无知,但结果会在 Google 电子表格中吗?那么我应该在 Google 电子表格上填写 50 个详细信息吗?

【问题讨论】:

    标签: google-apps-script google-forms autofill survey


    【解决方案1】:

    我如何伪造结果,或者创建 50 个表单提交?

    Use App Scripts to open form and make a selection

    请原谅我的无知,但结果会在 Google 电子表格中吗?那我应该在 Google 电子表格上填写 50 个详细信息吗?

    回复将记录在两个地方;在表单本身(您可以在其中查看响应摘要)以及电子表格中。如果您的意图是验证提交响应的过程,那么您应该模拟提交。

    【讨论】:

      【解决方案2】:

      @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");
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-13
        • 2021-10-29
        • 1970-01-01
        • 2013-07-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多