generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Arquisoft/questiongenerator1
Question generator 1
- Loading branch information
Showing
16 changed files
with
6,149 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
docs/build | ||
docs/build | ||
game/qgservice/.env |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
OPENAI_API_KEY="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" |
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Use an official Node.js runtime as a parent image | ||
FROM node:20 | ||
|
||
# Set the working directory in the container | ||
WORKDIR /usr/src/questiongeneratorservice | ||
|
||
# Copy package.json and package-lock.json to the working directory | ||
COPY package*.json ./ | ||
|
||
# Install app dependencies | ||
RUN npm install | ||
|
||
# Copy the app source code to the working directory | ||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 8003 | ||
|
||
# Define the command to run your app | ||
CMD ["node", "qg-service.js"] |
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Question4Answers = require("./Question4Answers"); | ||
|
||
function generateRandomMathQuestion() { | ||
const operators = ['+', '-', '*', '/']; | ||
|
||
const operator = operators[Math.floor(Math.random() * operators.length)]; | ||
let num1 = Math.floor(Math.random() * 100) + 1; | ||
let num2 = Math.floor(Math.random() * 100) + 1; | ||
|
||
// Ensure division results in integers | ||
if (operator === '/' && num2 !== 0) { | ||
const divisionResult = num1 / num2; | ||
num1 = divisionResult * num2; // Adjust num1 to get an integer result | ||
} | ||
|
||
const question = `${num1} ${operator} ${num2}`; | ||
const correctAnswer = eval(question).toString(); | ||
|
||
// Generate incorrect answers | ||
const incorrectAnswers = []; | ||
while (incorrectAnswers.length < 3) { | ||
const randomAnswer = Math.floor(Math.random() * 200) - 100; // Random integer between -100 and 100 | ||
if (incorrectAnswers.indexOf(randomAnswer.toString()) === -1 && randomAnswer.toString() !== correctAnswer) { | ||
incorrectAnswers.push(randomAnswer.toString()); | ||
} | ||
} | ||
|
||
return { | ||
question, | ||
correctAnswer, | ||
incorrectAnswer1: incorrectAnswers[0], | ||
incorrectAnswer2: incorrectAnswers[1], | ||
incorrectAnswer3: incorrectAnswers[2], | ||
}; | ||
} | ||
|
||
async function saveMathQuestions(numberOfQuestions) { | ||
const questions = []; | ||
|
||
for (let i = 0; i < numberOfQuestions; i++) { | ||
const mathQuestion = generateRandomMathQuestion(); | ||
questions.push(mathQuestion); | ||
} | ||
|
||
try { | ||
const savedQuestions = await Question4Answers.insertMany(questions); | ||
console.log(`${numberOfQuestions} math questions saved to MongoDB:`, savedQuestions); | ||
return questions; | ||
} catch (error) { | ||
console.error('Error saving math questions to MongoDB:', error.message); | ||
} | ||
} | ||
|
||
module.exports = { saveMathQuestions }; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const question4AnswersSchema = new mongoose.Schema({ | ||
question: { | ||
type: String, | ||
required: true, | ||
}, | ||
correctAnswer: { | ||
type: String, | ||
required: true, | ||
}, | ||
incorrectAnswer1: { | ||
type: String, | ||
required: true, | ||
}, | ||
incorrectAnswer2: { | ||
type: String, | ||
required: true, | ||
}, | ||
incorrectAnswer3: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
const Question4Answers = mongoose.model('Question4Answers', question4AnswersSchema); | ||
|
||
module.exports = Question4Answers; |
Oops, something went wrong.