This Node.js application is designed to generate question papers based on a question bank provided in a JSON file. The application exposes three REST APIs for different functionalities related to question paper generation.
- Node.js installed on your machine.
-
Clone the repository:
git clone https://github.com/your-username/reelo.git
-
Navigate to the project directory:
cd reelo
-
Install dependencies:
npm install
Endpoint: /generate_paper
- Method:
POST
- Request Body:
{ "total_marks": 50, "difficulty": { "Easy": "28%", "Medium": "40%", "Hard": "32%" } }
- Example:
-
Open Postman on your machine.
-
Set the request type GET .
-
Enter the API endpoint URL:
https://127.0.0.1:3000/generate_paper
-
Set the request headers:
- Content-Type: application/json
-
Set the request body:
- For POST requests, select the "Body" tab, choose "raw," and paste the JSON body given above.
-
Click the "Send" button to make the API call.
-
View the response in the "Body" section of the Postman interface.
The dfs
function is a critical component of the first API in this application. Its primary role is to generate a question paper based on the specified parameters, including total marks, a pool of all available questions, the number of required questions, and the maximum limit for each difficulty level.
function dfs(marks, allquestions, required_questions, max) {
// Function implementation
}
marks
: Total marks for the question paper.allquestions
: A pool of all available questions.required_questions
: The number of questions required for the paper.max
: Maximum limit for each difficulty level.
-
Depth-First Search (DFS) Algorithm:
- The function employs a depth-first search algorithm to traverse the available questions and select the optimal combination that meets the specified requirements.
-
Difficulty Level Weightage:
- The function ensures that the selected questions maintain the desired weightage for each difficulty level, as defined by the
max
parameter. This ensures a balanced distribution of easy, medium, and hard questions.
- The function ensures that the selected questions maintain the desired weightage for each difficulty level, as defined by the
-
Total Marks Calculation:
- The function calculates the total marks of the generated question paper, providing users with a clear understanding of the paper's overall difficulty level.
const generatedPaper = dfs(50, allQuestionsPool, [], { "Easy": 14, "Medium": 20, "Hard": 16 });
Feel free to enhance the function based on specific use cases and requirements.
Endpoint: /get_questions_topicwise
- Method:
POST
- Request Body:
{ "total_marks": 50, "difficulty": { "Easy": "28%", "Medium": "40%", "Hard": "32%" }, "weightage": { "Democracy": "8%" } }
- Example:
-
Open Postman on your machine.
-
Set the request type GET .
-
Enter the API endpoint URL:
https://127.0.0.1:3000/get_questions_topicwise
-
Set the request headers:
- Content-Type: application/json
-
Set the request body:
- For POST requests, select the "Body" tab, choose "raw," and paste the JSON body given above.
-
Click the "Send" button to make the API call.
-
View the response in the "Body" section of the Postman interface.
The topicwise_dfs
function is a core component of the second API in this application. Its primary responsibility is to generate a question paper based on the specified parameters, including total marks, marks distribution across difficulty levels, topic-wise weightage, and a pool of all available questions.
function topicwise_dfs(marks, marks_obj, topics_weightage, allquestions) {
// Function implementation
}
marks
: Total marks for the question paper.marks_obj
: Marks distribution across difficulty levels.topics_weightage
: Weightage of each topic in terms of marks percentage.allquestions
: A pool of all available questions.
-
Topic-wise Question Selection:
- The function utilizes a depth-first search (DFS) approach to select questions for each topic based on their weightage in the total marks. It ensures that each topic contributes its designated percentage of marks to the total marks.
-
Difficulty Level Distribution:
- Within each topic, the function further distributes marks across difficulty levels according to the provided
marks_obj
. This ensures a balanced representation of easy, medium, and hard questions within each topic.
- Within each topic, the function further distributes marks across difficulty levels according to the provided
-
Marks Percentage Calculation:
- The function calculates the marks percentage of each topic from the total marks. This information can be useful for users to understand the distribution of marks across different topics.
const generatedPaper = topicwise_dfs(
50,
{ "Easy": 14, "Medium":20, "Hard": 16 },
{ "Democracy": "8%" },
allQuestionsPool
);
- Adjust the function as needed to accommodate any specific business rules, error handling, or additional features required by your application.
Feel free to enhance the function based on specific use cases and requirements.
Endpoint: /paper_generator_topicwise
- Method:
POST
- Request Body:
{ "total_marks": 50, "difficulty": { "Easy": "28%", "Medium": "40%", "Hard": "32%" }, "total_questions": 13, "weightage": { "Democracy": "7.69%" } }
- Example:
-
Open Postman on your machine.
-
Set the request type GET .
-
Enter the API endpoint URL:
https://127.0.0.1:3000/paper_generator_topicwise
-
Set the request headers:
- Content-Type: application/json
-
Set the request body:
- For POST requests, select the "Body" tab, choose "raw," and paste the JSON body given above.
-
Click the "Send" button to make the API call.
-
View the response in the "Body" section of the Postman interface.
The paper_generator_topicwise
function is a key component of the third API in this application. It is responsible for generating a question paper based on various parameters, including total marks, the number of total questions, marks distribution across difficulty levels, topic-wise weightage, a pool of all available questions, and an index to keep track of the current question set.
function paper_generator_topicwise(
marks,
total_questions,
marks_obj,
topics_weightage,
allquestions,
index
) {
// Function implementation
}
marks
: Total marks for the question paper.total_questions
: Total number of questions to be included in the paper.marks_obj
: Marks distribution across difficulty levels.topics_weightage
: Weightage of each topic in terms of marks percentage.allquestions
: A pool of all available questions.index
: Index to keep track of the current topic.
-
Topic-wise Question Selection:
- The function begins by selecting questions for each topic based on their weightage in the total number of questions. It ensures that each topic contributes its designated percentage of marks to the total marks.
-
Random Question Selection:
- After selecting questions for each topic, the function fills in the remaining questions randomly from the pool of all available questions.
-
Difficulty Level Distribution:
- The function takes into account the marks distribution across difficulty levels (
marks_obj
) and assigns marks to questions accordingly.
- The function takes into account the marks distribution across difficulty levels (
const generatedPaper = paper_generator_topicwise(
50,
13,
{ "Easy": 14, "Medium": 20, "Hard": 16 },
{ "Democracy": "7.69%" },
allQuestionsPool,
0
);
Feel free to adjust the function or provide additional error handling based on specific use cases and requirements.
Feel free to contribute by opening issues, suggesting improvements, or submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.