Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Game Service] Question fetcher component #53

Closed
carlosfernandezmartinez opened this issue Feb 23, 2025 · 4 comments · Fixed by #58
Closed

[Game Service] Question fetcher component #53

carlosfernandezmartinez opened this issue Feb 23, 2025 · 4 comments · Fixed by #58
Assignees
Labels
enhancement New feature or request

Comments

@carlosfernandezmartinez
Copy link

carlosfernandezmartinez commented Feb 23, 2025

Question fetcher component

The question fetcher is in charge of querying WikiData for questions. Remember that the main function of this component is processing the data returned from Wikidata and storing it into the database. The format of storing the data into the MongoDB database with the following schema (have a look at the user-model):

{
subject: {
type: String,
required: true,
},
image_name: {
type: String,
required: true,
},
answer: {
type: String,
required: true,
}
}

GET /generate with parameter the number of questions we want to generate, as well as the theme
Something like: /generate?n=100&sub=capital

Note that, in this initial implementation, only questions about capitals should be correctly generated and stored.

The image should be downloaded into a folder images inside the game service.

@carlosfernandezmartinez carlosfernandezmartinez changed the title [Game Service] Question generator component [Game Service] Question fetcher component Feb 23, 2025
@carlosfernandezmartinez
Copy link
Author

Update: it seems that mongoose assigns by default a '_id' field to each object of type ObjectId. This is the test I've done:

Image

We can take that hash to uniquely identify each Question object in the db, so that the image file linked to that question also has the same name. I suggest this schema:

const mongoose = require('mongoose');

const questionSchema = new mongoose.Schema({
    subject: String,
    answer: String,
});

const Question = mongoose.model('Question', questionSchema);

module.exports = Question

since both image names and question id can be extracted from _id @Arquisoft/course2425_en2b.

@carlosfernandezmartinez carlosfernandezmartinez added the enhancement New feature or request label Feb 23, 2025
carlosfernandezmartinez added a commit that referenced this issue Feb 23, 2025
carlosfernandezmartinez added a commit that referenced this issue Feb 24, 2025
…tion and the amount of questions. Query yet to be improved.
@carlosfernandezmartinez
Copy link
Author

carlosfernandezmartinez commented Feb 24, 2025

I've found that it is not so hard to request generation together with the subject and amount of generated questions. I think that the best approach would be to directly pass a WikiData code as a request parameter (ex. Q515, which stands for cities).

GET /generate/wikiDataCode/amount - Ex. /generate/Q515/10 would download 10 images and store in the 'game' DB the answer to them.

The implementation right now is far from being perfect, it has a single query, so the subjects should be very specific. These are some subjects that I've checked are good enough to generate a reasonably large (around 10) amount of images with their answer:

  • Q31629 - sports type
  • Q515 - cities
  • Q4989906 - monuments
  • Q11344 - chemical elements

Therefore, this is the way in which the data is stored in the DB, together with the storage of the image inside in the /public/images folder. Please note that the __v field is also something MongoDB creates automatically, so I've took advantage of that to keep track of the version of the generated questions:

Image

Image

Image
Exposing an endpoint to retrieve those images shouldn't be that hard, and the good part is that we can use the question id to retrieve the right image.

@carlosfernandezmartinez
Copy link
Author

Thanks to @adrianmfuentes and his previous experience in node, I've discovered that I had an OOOoooold version of Node installed in my Ubuntu. I have already updated it and I will fix the existing errors soon.

@carlosfernandezmartinez
Copy link
Author

😡 🐰 🏄‍♀️ DISCALIMER 💃 🥇 🧑‍🦯

Images can be obtained from url/image/[question_id].jpg
Here you got an example:

imagen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant