Conversation with Merlin [email protected] · Mon Nov 20 2023

Assignment Brief

Design and implement a Question Paper Generator application

The application must store a number of questions in a Question Store. A question can have the following attributes {question, subject, topic, difficulty, marks}

The Question paper Generator should look for questions in the Question Store and then generate the question paper based on the total marks and the distribution of marks based on Difficulty

Example

Assume the below requirement for a question paper:

(100 marks, Difficulty, {20% Easy, 50% Medium, 30% Hard })

The problem statement here is that you need to generate a question paper of 100 marks total of which 20% (ie, 20 marks) worth of questions should have the Difficulty=Easy, 50% having Difficulty=Medium and 30% having Difficulty=Hard

Expectations

  1. Try to keep the code as modular and as extensible as possible while following the best practices and community conventions
  2. We look for code that is open for extension so build the application that can easily scale with new future requirements. Example, what if we want to mention the percentages of questions from each Topic that the question paper should accommodate too.
  3. Handle the edge cases properly and fail gracefully
  4. You must provide the code setup and the steps for us to run the application and see what you have built
  5. We're a Javascript team! And as a Backend Engineer, we expect you to have fair knowledge in Nodejs and the assignment is also expected in Nodejs in nodejs and express and mongodb

To design and implement the Question Paper Generator application in Node.js, you can use the following structure and steps.

Step 1: Setting up the Environment

  • Install Node.js and npm (Node Package Manager) if not already installed.
  • Create a new project directory for the Question Paper Generator application.

Step 2: Initializing the Project

  • Inside the project directory, run npm init -y to initialize a new Node.js project.

Step 3: Installing Required Packages

  • Install Express, M (for MongoDB integration), and any other necessary dependencies using npm:
    npm install express mongoose

Step 4: Creating Question Schema and Model

  • Create a new directory for models (e.g., models) to store the schema and models for questions using MongoDB and Mongoose.
// models/question.js const mongoose = require('mongoose'); const Schema = mongoose.Schema; const questionSchema = new Schema({ question: { type: String, required: true }, subject: { type: String, required: true }, topic: { type: String, required: true }, difficulty: { type: String, required: true }, marks: { type: Number, required: true // You may add validation rules as needed } }); const Question = mongoose.model('Question', questionSchema); module.exports = Question;

Step 5: Setting up Express Server

  • Create a new file (e.g., app.js) to set up an Express server and handle routes for the Question Paper Generator.
// app.js const express = require('express'); const mongoose = require('mongoose'); const Question = require('./models/question'); // Import the Question model const app = express(); const PORT = process.env.PORT || 3000; // Set the port as needed // Connect to MongoDB using Mongoose mongoose.connect('mongodb://localhost:27017/questionStore', { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => { console.log('Connected to MongoDB'); }) .catch((err) => { console.error('Failed to connect to MongoDB:', err); }); // Define routes and implement the logic for generating the question paper // Start the server app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); });

Step 6: Generating Question Paper

  • Implement the logic to generate the question paper based on the given requirements (e.g., total marks and distribution of marks based on difficulty). This can be done within the route handlers by querying the question store and selecting questions based on the specified criteria.

Step 7: Additional Requirements

  • To accommodate future requirements such as mentioning the percentages of questions from each topic, you can modify the question schema and model accordingly and adjust the logic for generating the question paper as needed.

Step 8: Running the Application

  • Start the application by running the following command:
    node app.js

This setup provides a basic foundation for building the Question Paper Generator application in Node.js using Express, MongoDB, and Mongoose. It can be extended to accommodate future requirements and handle edge cases effectively.

Generating Question Paper as a above description in express and nodejs

Let's design a simple solution for a Question Paper Generator application in Express and Node.js. Note that due to the complexity and scale of the project, the solution is a basic version.

Let's approach it in different steps:

Step 1: Create and set up a new Node.js project If Node.js and npm are not installed, you need to install them first.

Create a new directory, initialize a new Node.js project and install necessary packages:

mkdir question-generator cd question-generator npm init -y npm install express mongoose

Step 2: Connect to the MongoDB database using Mongoose

Create a file database.js with the following code.

const mongoose = require('mongoose'); const connectDB = async () => { try { await mongoose.connect('mongodb://127.0.0.1:27017/question-generator', { useNewUrlParser: true, useUnifiedTopology: true }); console.log('MongoDB connected...'); } catch(err) { console.error(err.message); process.exit(1); } } module.exports = connectDB``` **Step 3: Define the Model** Create a new file `models/Question.js` and define the Question schema as per the application's requirements. ```javascript const mongoose = require('mongoose'); const QuestionSchema = new mongoose.Schema({ question: { : String, required: true }, subject: { type: String, required: true topic: { type: String, required: true }, difficulty: { type: String, required: true }, marks: { type: Number, required: true } }); module.exports = Question = mongoose.model('question', QuestionSchema); ` **Step 4: Define Routes and Logic** In the `app.js` file, define the logic and the endpoint to generate the question paper. ```javascript const express = require('express'); const connectDB = require('./database'); const Question = require('./models/Question'); const app = express(); connectDB(); app.get('/generate-paper', async (req, res) => { try { let paper = []; let totalMarks = 0; const difficultyLevels = ['Easy', 'Medium', 'Hard']; for(let i = 0; i < difficultyLevels.length; i++) { let questions = await Question.find({ difficulty: difficultyLevels[i] }); questions.forEach(question => { if(totalMarks + question.marks <= 100) { totalMarks += question.marks; paper.push(question); } }); if (totalMarks >= 100) break; } res.json(paper); catch(err) { console.error(err.message); res.status(500).send('Server Error'); } });

This code fetches the questions based on the difficulty level and constructs the question paper until the total marks reach 100.

Step 5: Start the server

The last step is to the server.

const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(`Server started on port ${PORT}`));

Run the application using the command node app.js.

This approach is a simple starter to a question paper generator. This solution does not include the distribution of marks based on the difficulty level but gives a foundation to expand upon. It can be modified to include more complex functionalities.

To handle the edge cases, you can program more conditions in the code to accommodate situations such as when the total marks exceed 100.

".js" redirects here. For the Microsoft dialect used in Internet Explorer, see JScript. JavaScriptScreenshot of JavaScript source codeParadigmMulti-paradigm: event-driven, functional, imperative, procedural, object-oriented programmingDesignedbyBrendan Eich of Netscape initially; others have also contributed to the ECMAScript standardFirstappearedDecember4, 1995; 27 years ago[1]Stable releaseECMAScript 2021[2] / June 2021; 2 years agoPreview releaseECMAScript 2022[3] / 22 July 2021; 2 years agoTyping disciplineDynamic, weak, duckFilename extensions .js .cjs .mjs[4] Websiteecma-international.org/publications-and-standards/standards/ecma-262/Major implementationsV8, JavaScriptCore, SpiderMonkey, ChakraInfluenced byJava,[5][6] Scheme,[6] Self,[7] AWK,[8] HyperTalk[9]InfluencedActionScript, AssemblyScript, CoffeeScript, Dart, Haxe, JS++, Opa, TypeScript JavaScript at Wikibooks JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2023, 98.7% of websites use JavaScript on the client side for webpage behavior,[10] often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on users' devices. JavaScript is a high-level, often just-in-time compiled language that conforms to the ECMAScript standard.[11] It has dynamic typing, prototype-based object-orientation, and first-class functions. It is multi-paradigm, supporting event-driven, functional, and imperative programming styles. It has application programming interfaces (APIs) for working with text, dates, regular expressions, standard data structures, and the Document Object Model (DOM). The ECMAScript standard does not include any input/output (I/O), such as networking, storage, or graphics facilities. In practice, the web browser or other runtime system provides JavaScript APIs for I/O. JavaScript engines were originally used only in web browsers, but are now core components of some servers and a variety of applications. The most popular runtime system for this usage is Node.js. Although Java and JavaScript are similar in name, syntax, and respective standard libraries, the two languages are distinct and differ greatly in design. History Creation at Netscape The first popular web browser with a graphical user interface, Mosaic, was released in 1993. Accessible to non-technical people, it played a prominent role in the rapid growth of the nascent World Wide Web.[12] The lead developers of Mosaic then founded the Netscape corporation, which released a more polished browser, Netscape Navigator, in 1994. This quickly became the most-used.[13] During these formative years of the Web, web pages could only be static, lacking the capability for dynamic behavior after the page was loaded in the browser. There was a desire in the flourishing web development scene to remove this limitation, so in 1995, Netscape decided to add a scripting language to Navigator. They pursued two routes to achieve this: collaborating with Sun Microsystems to embed the Java programming language, while also hiring Brendan Eich to embed the Scheme language.[6] Netscape management soon decided that the best option was for Eich to devise a new language, with syntax similar to Java and less like Scheme or other extant scripting languages.[5][6] Although the new language and its interpreter implementation were called LiveScript when first shipped as part of a Navigator beta in September 1995, the name was changed to JavaScript for the official release in December.[6][1][14] The choice of the JavaScript name has caused confusion, implying that it is directly related to Java. At the time, the dot-com boom had begun and Java was the hot new language, so Eich considered the JavaScript name a marketing ploy by Netscape.[15] Adoption by Microsoft Microsoft debuted Internet Explorer in 1995, leading to a browser war with Netscape. On the JavaScript front, Microsoft

en.wikipedia.org

Bachelor's Infosys Foundation USA| InStep 8 Infosys Foundation USAThe intern would be asked to contribute to the development and management of the Foundations marketing, grants management/partnerships and digital learning platform over a 6-month period. Some projects include: Digital Learning Platform: Support the ongoing development of the Pathfinders Online Institute - the Foundation's signature digital learning platform. This includes support implementing key partnerships with curriculum providers; liaising with the development team; supporting the tracking of content curation and submission process; and enhancing design and user experience. Events: Support the planning and implementation of the Pathfinders Summer Institute the Foundations signature teacher training eventas well as other ad hoc events that may arise. a virtual. Marketing & Communications: Support to the wider social media and marketing efforts broadly of the Foundation, including drafting copy for social media and other communications. Grants Management: Support grants management and the development of an impact report. This includes reviewing final report submissions from grantees, as well as extrapolating data from Foundation events to extract qualitative and quantitative insights that would be summarized in a PowerPoint impact report. Independent Research: Based on the interest, additional research tasks could be added that examines trends in K-12 education and specifically computer science. Bachelor's/ Masters /Ph.D Secondary Research, Automotive Domain Knowledge 8 SAP IS Auto and ACS StudySAP IS Auto and ACS Study - For Automotive Industry SAP offers two solutions - one is SAP IS Auto (also referred to as VMS - Vehicle Management System) while other is ACS (Automotive Consulting Solution). It needs to be determined how these 2 solutions are different and how they complement each other. Bachelor's/ Masters /Ph.D Secondary Research, Automotive Domain Knowledge 8 Machine Learning in Auto Industry Machine Learning in Auto Industry - While Machine Learning is a well known concept, identification of business situations where it can be applied is a continuous quest. We want to determine what are the various business processes in Automotive industry where ML can be applied to derive benefits. In this regard complete supply chain of Automotive industry need to be considered - right from Design, Procurement, Manufacturing, Sales, Dealer Management, After Sales to Scrapping. Bachelor's/ Masters /Ph.D ML,Deep Learning,Tensorflow,Python 8 AI Powered Question answering systemAI Powered Question answering system : AI powered question and answering system on unstructured documents Bachelor's/ Masters /Ph.D AI, ML 8 - 12 Data Analytics & Insights from multiple related data sources: Based on the last 3-5 years of data from mutiple DRM systems, to come up with some intelligent insights. Also, based on the historical data, accurately assess a projects riskiness/gaps using some AI algorithm Bachelor's/ Masters /Ph.D AI, ML 8 - 12 Building Intelligent Search Engine with search results similar to Google :Strong Search engine to search through various case studies/pdfs/text/documents and throw results similar to Google search Bachelor's/ Masters /Ph.D AI, ML 8 - 12 Obligation extraction from various Contract documents using ML :Research on ML based tools available in the market that can make Contract obligation extraction easier to be used by our teams for Contract reviews and awareness workshops Bachelor's/ Masters /Ph.D Design Thinking, Industrial Design, Adobe XD, Visualization 8 Design led intervention for human machine interaction: Researching and identifying various interventions to improve the overall human interactions with enterpise software applications through strategic design initiatives Bachelor's/ Masters /Ph.D Business research, Secondary research, 12 Idenitfying and assessing industry relevant startups from global ecosystem: Researching and identifying the m

infosys.com

Express/Node introduction Overview: Express Nodejs Next In this first Express article we answer the questions "What is Node?" and "What is Express?", and give you an overview of what makes the Express web framework special. We'll outline the main features, and show you some of the main building blocks of an Express application (although at this point you won't yet have a development environment in which to test it). Prerequisites: Basic computer literacy. A general understanding of server-side website programming, and in particular the mechanics of client-server interactions in websites. Objective: To gain familiarity with what Express is and how it fits in with Node, what functionality it provides, and the main building blocks of an Express application. Introducing Node Node (or more formally Node.js) is an open-source, cross-platform runtime environment that allows developers to create all kinds of server-side tools and applications in JavaScript. The runtime is intended for use outside of a browser context (i.e. running directly on a computer or server OS). As such, the environment omits browser-specific JavaScript APIs and adds support for more traditional OS APIs including HTTP and file system libraries. From a web server development perspective Node has a number of benefits: Great performance! Node was designed to optimize throughput and scalability in web applications and is a good solution for many common web-development problems (e.g. real-time web applications). Code is written in "plain old JavaScript", which means that less time is spent dealing with "context shift" between languages when you're writing both client-side and server-side code. JavaScript is a relatively new programming language and benefits from improvements in language design when compared to other traditional web-server languages (e.g. Python, PHP, etc.) Many other new and popular languages compile/convert into JavaScript so you can also use TypeScript, CoffeeScript, ClojureScript, Scala, LiveScript, etc. The node package manager (npm) provides access to hundreds of thousands of reusable packages. It also has best-in-class dependency resolution and can also be used to automate most of the build toolchain. Node.js is portable. It is available on Microsoft Windows, macOS, Linux, Solaris, FreeBSD, OpenBSD, WebOS, and NonStop OS. Furthermore, it is well-supported by many web hosting providers, that often provide specific infrastructure and documentation for hosting Node sites. It has a very active third party ecosystem and developer community, with lots of people who are willing to help. You can use Node.js to create a simple web server using the Node HTTP package.Hello Node.jsThe following example creates a web server that listens for any kind of HTTP request on the URL http://127.0.0.1:8000/ when a request is received, the script will respond with the string: "Hello World". If you have already installed node, you can follow these steps to try out the example: Open Terminal (on Windows, open the command line utility) Create the folder where you want to save the program, for example, test-node and then enter it by entering the following command into your terminal: Using your favorite text editor, create a file called hello.js and paste the following code into it: // Load HTTP module const http = require("http"); const hostname = "127.0.0.1"; const port = 8000; // Create HTTP server const server = http.createServer(function (req, res) { // Set the response HTTP header with HTTP status and Content type res.writeHead(200, { "Content-Type": "text/plain" }); // Send the response body "Hello World" res.end("Hello World\n"); }); // Prints a log once the server starts listening server.listen(port, hostname, function () { console.log(`Server running at http://${hostname}:${port}/`); }); Save the file in the folder you created above. Go back to the terminal and type the following command: Finally, navigate to http://localhost:8000 in your web browser; you shoul

developer.mozilla.org