Skip to content

Commit

Permalink
feat: Add url column for open response questions [PT-181870149]
Browse files Browse the repository at this point in the history
This adds an url column to each open response question that points to the portal dashboard so that researchers can listen to audio responses.
  • Loading branch information
dougmartin committed Mar 13, 2024
1 parent 2e9934e commit e3b294d
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 135 deletions.
45 changes: 23 additions & 22 deletions query-creator/create-query/steps/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ const getColumnsForQuestion = (questionId, question, denormalizedResource, authD

const columnPrefix = `res_${activityIndex}_${questionId}`;

const modelUrl = [`CONCAT(`,
`'${process.env.PORTAL_REPORT_URL}`,
`?auth-domain=${encodeURIComponent(authDomain)}`,
`&firebase-app=${process.env.FIREBASE_APP}`,
`&sourceKey=${sourceKey}`,
`&iframeQuestionId=${questionId}`,
`&class=${encodeURIComponent(`${authDomain}/api/v1/classes/`)}',`,
` CAST(${learnersAndAnswersTable}.class_id AS VARCHAR), `,
`'&offering=${encodeURIComponent(`${authDomain}/api/v1/offerings/`)}',`,
` CAST(${learnersAndAnswersTable}.offering_id AS VARCHAR), `,
`'&studentId=',`,
` CAST(${learnersAndAnswersTable}.user_id AS VARCHAR), `,
`'&answersSourceKey=', `,
` ${learnersAndAnswersTable}.source_key['${questionId}']`,
`)`
].join("")
const conditionalModelUrl = `CASE WHEN ${learnersAndAnswersTable}.kv1['${questionId}'] IS NULL THEN '' ELSE ${modelUrl} END`;

switch (type) {
case "image_question":
columns.push({name: `${columnPrefix}_image_url`,
Expand All @@ -155,10 +173,13 @@ const getColumnsForQuestion = (questionId, question, denormalizedResource, authD
case "open_response":
// When there is no answer to an open_response question the report state JSON is saved as the answer in Firebase.
// This detects if the answer looks like the report state JSON and if so returns an empty string to show there was no answer to the question.
const filterNoAnswerJSON = `if(starts_with(${learnersAndAnswersTable}.kv1['${questionId}'], '"{\\"mode\\":\\"report\\"'), '', ${learnersAndAnswersTable}.kv1['${questionId}'])`;
const filterNoAnswerJSON = (value) => `CASE WHEN starts_with(${learnersAndAnswersTable}.kv1['${questionId}'], '"{\\"mode\\":\\"report\\"') THEN '' ELSE (${value}) END`;

columns.push({name: `${columnPrefix}_text`,
value: filterNoAnswerJSON,
value: filterNoAnswerJSON(`${learnersAndAnswersTable}.kv1['${questionId}']`),
header: promptHeader});
columns.push({name: `${columnPrefix}_url`,
value: filterNoAnswerJSON(conditionalModelUrl),
header: promptHeader});
break;
case "multiple_choice":
Expand All @@ -181,26 +202,6 @@ const getColumnsForQuestion = (questionId, question, denormalizedResource, authD
columns.push({name: `${columnPrefix}_json`,
value: `${learnersAndAnswersTable}.kv1['${questionId}']`,
header: promptHeader});

const modelUrl = [`CONCAT(`,
`'${process.env.PORTAL_REPORT_URL}`,
`?auth-domain=${encodeURIComponent(authDomain)}`,
`&firebase-app=${process.env.FIREBASE_APP}`,
`&sourceKey=${sourceKey}`,
`&iframeQuestionId=${questionId}`,
`&class=${encodeURIComponent(`${authDomain}/api/v1/classes/`)}',`,
` CAST(${learnersAndAnswersTable}.class_id AS VARCHAR), `,
`'&offering=${encodeURIComponent(`${authDomain}/api/v1/offerings/`)}',`,
` CAST(${learnersAndAnswersTable}.offering_id AS VARCHAR), `,
`'&studentId=',`,
` CAST(${learnersAndAnswersTable}.user_id AS VARCHAR), `,
`'&answersSourceKey=', `,
` ${learnersAndAnswersTable}.source_key['${questionId}']`,
`)`
].join("")

const conditionalModelUrl = `CASE WHEN ${learnersAndAnswersTable}.kv1['${questionId}'] IS NULL THEN '' ELSE ${modelUrl} END`;

columns.push({name: `${columnPrefix}_url`,
value: conditionalModelUrl,
header: promptHeader});
Expand Down
Loading

0 comments on commit e3b294d

Please sign in to comment.