Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgspghf7ea7bw10untitledPlain Text
const TEST_CONFIG = {
total: 1, // Start with one test response
dryRun: true, // Set false to submit
ratingWeights: [25, 25, 25, 25]
// Weights for ratings 1, 2, 3, 4
};
function generateMindScapeTestData() {
const form = FormApp.getActiveForm();
if (!form) {
throw new Error(
"Open this script from the Google Form editor."
);
}
const items = form.getItems();
for (let n = 1; n <= TEST_CONFIG.total; n++) {
const response = form.createResponse();
const testId = String(n).padStart(4, "0");
let answered = 0;
const skipped = [];
for (const item of items) {
const type = item.getType();
const title = item.getTitle();
let answer = null;
try {
if (type === FormApp.ItemType.CHECKBOX) {
const field = item.asCheckboxItem();
const choices = field.getChoices()
.map(c => c.getValue());
if (title === "Consent to Participate") {
// This is a synthetic test, not real consent.
answer = field.createResponse([choices[0]]);
} else {
const count = randomInt(
1,
choices.length
);
const selected = shuffle([...choices])
.slice(0, count);
answer = field.createResponse(selected);
}
}
else if (type === FormApp.ItemType.TEXT) {
const field = item.asTextItem();
answer = field.createResponse(
`SYNTHETIC TEST ${testId}`
);
}
else if (
type === FormApp.ItemType.MULTIPLE_CHOICE
) {
const field = item.asMultipleChoiceItem();
const choices = field.getChoices()
.map(c => c.getValue());
let selected;
if (title.includes("age group")) {
selected = randomChoice(choices);
}
else if (
title.includes("category best describes")
) {
selected = randomChoice(choices);
}
else if (
choices.every(c =>
/^[1-4] - /.test(c)
)
) {
const rating = weightedRating();
selected = choices.find(c =>
c.startsWith(rating + " - ")
);
}
else {
selected = randomChoice(choices);
}
answer = field.createResponse(selected);
}
else if (
type === FormApp.ItemType.PARAGRAPH_TEXT
) {
// Optional fields are left blank.
// No fabricated participant comments.
continue;
}
if (answer) {
response.withItemResponse(answer);
answered++;
} else if (
typeof item.isRequired === "function" &&
item.isRequired()
) {
skipped.push(title);
}
} catch (error) {
skipped.push(`${title}: ${error.message}`);
}
}
Logger.log(
`Test ${testId}: ${answered} answers prepared`
);
if (skipped.length) {
Logger.log(
"Skipped required questions: " +
JSON.stringify(skipped)
);
continue;
}
if (TEST_CONFIG.dryRun) {
Logger.log(
"DRY RUN: No response submitted."
);
continue;
}
try {
response.submit();
Logger.log(`SUCCESS: Test ${testId}`);
} catch (error) {
Logger.log(
`FAILED: Test ${testId}: ${error.message}`
);
}
}
}
function randomChoice(values) {
return values[
Math.floor(Math.random() * values.length)
];
}
function randomInt(min, max) {
return Math.floor(
Math.random() * (max - min + 1)
) + min;
}
function shuffle(values) {
for (let i = values.length - 1; i > 0; i--) {
const j = randomInt(0, i);
[values[i], values[j]] =
[values[j], values[i]];
}
return values;
}
function weightedRating() {
const weights = TEST_CONFIG.ratingWeights;
const total = weights.reduce(
(sum, weight) => sum + weight, 0
);
let random = Math.random() * total;
for (let i = 0; i < weights.length; i++) {
random -= weights[i];
if (random < 0) {
return i + 1;
}
}
return 4;
}
4,273 chars · codepastes.com