This repository was archived by the owner on Sep 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
(EAI-1257) handle multiple correct and more answer options #887
Open
yakubova92
wants to merge
5
commits into
main
Choose a base branch
from
EAI-1257
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1ffc82
process answer options through F, handle multiple correct
yakubova92 27f65ee
wip
yakubova92 ba05cee
Merge branch 'main' into EAI-1257
yakubova92 3712018
run reports
yakubova92 cacf923
create csv with breakdown by question
yakubova92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,35 +2,43 @@ import fs from "fs"; | |||||
| import path from "path"; | ||||||
| import csv from "csv-parser"; | ||||||
| import { QuizQuestionData, QuizQuestionDataSchema } from "../QuizQuestionData"; | ||||||
| import { makeTags } from "./makeTags"; | ||||||
|
|
||||||
| const testDataPath = path.resolve(__dirname, "..", "..", "..", "testData"); | ||||||
| const csvFileInPath = path.resolve(testDataPath, "badge-questions.csv"); | ||||||
| const jsonFileOutPath = path.resolve(testDataPath, "badge-questions.json"); | ||||||
|
|
||||||
| const handleAnswers = (row: any) => { | ||||||
| const correctAnswers = row.Answer.trim()?.split("") || []; | ||||||
| const answers = ["A", "B", "C", "D", "E", "F"] | ||||||
| .map((label) => { | ||||||
| const isCorrect = correctAnswers.includes(label); | ||||||
| return { | ||||||
| answer: row[label], | ||||||
| isCorrect, | ||||||
| label, | ||||||
| }; | ||||||
| }) | ||||||
| .filter((answer) => answer.answer && answer.answer.trim() !== ""); // Remove empty answers | ||||||
|
Comment on lines
+12
to
+21
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this code could be a little cleaner. rather than filtering at the end, can you slice the array of ["A", "B", "C", ...] to the correct length before running the map over it? |
||||||
| return answers; | ||||||
| }; | ||||||
|
|
||||||
| const parseCSV = async (filePath: string): Promise<QuizQuestionData[]> => { | ||||||
| return new Promise((resolve, reject) => { | ||||||
| const results: QuizQuestionData[] = []; | ||||||
| fs.createReadStream(filePath) | ||||||
| .pipe(csv()) | ||||||
| .on("data", (row) => { | ||||||
| try { | ||||||
| const answers = ["A", "B", "C", "D"].map((label, index) => ({ | ||||||
| answer: row[label], | ||||||
| isCorrect: row.Answer === (index + 1).toString(), | ||||||
| label, | ||||||
| })); | ||||||
|
|
||||||
| const answers = handleAnswers(row); | ||||||
| const questionData: QuizQuestionData = QuizQuestionDataSchema.parse({ | ||||||
| questionText: row["Question Text"], | ||||||
| title: row["Assessment"], | ||||||
| topicType: "badge", // Defaulting topic type | ||||||
| questionType: "singleCorrect", // Assuming single correct answer | ||||||
| questionType: | ||||||
| row["Answer"].length > 1 ? "multipleCorrect" : "singleCorrect", | ||||||
|
Comment on lines
+80
to
+81
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider doing more typesafe parsing rather than checking string length (which isn't very resilient). for example, there could be an err in the spreadsheet |
||||||
| answers, | ||||||
| explanation: row["Reference"], | ||||||
| tags: row["tags"] ? row["tags"].split(",") : [], | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
again, a bit more resilient |
||||||
| }); | ||||||
| questionData.tags = makeTags(questionData); | ||||||
| results.push(questionData); | ||||||
| } catch (error) { | ||||||
| console.error("Validation error:", error); | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of passing
row: any, please make sure that the input is strongly typed. you can use zod to do any validation that you need.