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 all commits
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
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,36 +2,91 @@ 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 createTagsFromAssessmentName = (assessmentName: string) => { | ||
| // return assessmentName.split(",").map((tag) => tag.trim()); | ||
| // }; | ||
|
|
||
| const assessmentNameToTagsMap = { | ||
| 'MongoDB Aggregation Fundamentals': ['aggregation'], | ||
| 'MongoDB Query Optimization Techniques': ['query'], | ||
| "From Relational Model (SQL) to MongoDB's Document Model": ['data_modeling'], | ||
| 'MongoDB Schema Design Patterns and Antipatterns': ['data_modeling'], | ||
| 'MongoDB Advanced Schema Design Patterns and Antipatterns': ['data_modeling'], | ||
| 'MongoDB Schema Design Optimization': ['data_modeling'], | ||
| 'Building AI Agents with MongoDB': ['gen_ai'], | ||
| 'Building AI-Powered Search with MongoDB Vector Search': ['gen_ai'], | ||
| 'Building RAG Apps Using MongoDB': ['gen_ai'], | ||
| 'MongoDB Indexing Design Fundamentals': ['indexing'], | ||
| 'Monitoring MongoDB with Built-in Tools': ['monitoring_tuning_and_automation'], | ||
| 'Optimizing MongoDB Performance with Tuning Tools': ['monitoring_tuning_and_automation'], | ||
| 'CRUD Operations in MongoDB': ['query'], | ||
| 'Search with MongoDB': ['search'], | ||
| 'Securing MongoDB Atlas: Authentication & Authorization': ['security'], | ||
| 'Securing MongoDB Self-Managed: Authentication & Authorization': ['security'], | ||
| 'MongoDB Sharding Strategies': ['sharding'], | ||
| 'Optimizing and Maintaining MongoDB Cluster Reliability': ['performance_at_scale'], | ||
| }; | ||
|
|
||
| // excluded: | ||
| // 'MongoDB Overview: Core Concepts and Architecture' | ||
|
|
||
| const parseCSV = async (filePath: string): Promise<QuizQuestionData[]> => { | ||
| return new Promise((resolve, reject) => { | ||
| const results: QuizQuestionData[] = []; | ||
| const assessments = new Set<string>(); | ||
| fs.createReadStream(filePath) | ||
| .pipe(csv()) | ||
| .on("data", (row) => { | ||
| // console.log("HIT TRY"); | ||
| try { | ||
| const answers = ["A", "B", "C", "D"].map((label, index) => ({ | ||
| answer: row[label], | ||
| isCorrect: row.Answer === (index + 1).toString(), | ||
| label, | ||
| })); | ||
|
|
||
| const assessmentName = row["Assessment"]?.trim(); | ||
| if (!assessmentName) { | ||
| console.warn("Skipping row with missing assessment name"); | ||
| return; | ||
| } | ||
|
|
||
| // Type guard to ensure assessmentName is a valid key | ||
| if (assessmentName in assessmentNameToTagsMap) { | ||
| console.log('>> tags', assessmentNameToTagsMap[assessmentName as keyof typeof assessmentNameToTagsMap]); | ||
| } else { | ||
| console.warn(`Assessment name not found in map: "${assessmentName}"`); | ||
| } | ||
|
|
||
| const answers = handleAnswers(row); | ||
| const questionData: QuizQuestionData = QuizQuestionDataSchema.parse({ | ||
| questionText: row["Question Text"], | ||
| title: row["Assessment"], | ||
| title: assessmentName, | ||
| 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(",") : [], | ||
| // tags: row["tags"] ? row["tags"].split(",") : [], | ||
| tags: assessmentName in assessmentNameToTagsMap | ||
| ? assessmentNameToTagsMap[assessmentName as keyof typeof assessmentNameToTagsMap] | ||
| : [], | ||
| }); | ||
| questionData.tags = makeTags(questionData); | ||
| results.push(questionData); | ||
| // console.log(">>>> assessments >>>>", assessments); | ||
| } catch (error) { | ||
| console.error("Validation error:", error); | ||
| } | ||
|
|
||
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
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
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
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.