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

Merge from questions to develop #110

Merged
merged 61 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2e42f5b
Setup of question generation module
uo288543 Feb 22, 2024
5659a76
Setup node scripts to start and starting code for question generation…
uo288543 Feb 22, 2024
5c95498
Setup dockerfile
uo288543 Feb 22, 2024
e3f99bf
Integration of question generation service in gateway service
uo288543 Feb 22, 2024
44f7d28
First try looking for fast wikidata requests
uo288347 Feb 23, 2024
086d29a
Just some random things about SparQL. Not working yet
uo288347 Feb 23, 2024
d916a18
Index works with fullQuery
uo288347 Feb 24, 2024
62bd3bf
City and population on the same wikidata request
uo288347 Feb 24, 2024
cce6ae4
Including population and spanish filters (spanish does not always work)
uo288347 Feb 24, 2024
3616917
Tyring to request wikidata with various queries
uo288347 Feb 24, 2024
20b91b7
Decreasing number of requests for city questions
uo288347 Feb 24, 2024
95d7c67
Fixed bug in improved cities question
uo288347 Feb 24, 2024
3010fd3
Comparating different options
uo288347 Feb 24, 2024
bf425eb
Optimize request time
uo288347 Feb 24, 2024
37337ac
Fixing mistake
uo288347 Feb 24, 2024
8ab8df8
Optimized city population request
uo288347 Feb 24, 2024
37e6980
Added json with provisional question format
uo288347 Feb 24, 2024
fb27aba
Reading from json. Not working yet
uo288347 Feb 24, 2024
ced2aa7
Info about Node.js queries
uo288347 Feb 25, 2024
ef2707f
Generalise requests. Not working yet
uo288347 Feb 25, 2024
11c2c61
Single request
uo288347 Feb 25, 2024
f55a7d1
Initial setup of mongo question database
uo288543 Feb 25, 2024
a237f48
Modified question model
uo288543 Feb 25, 2024
cbe323c
Change question database schema
uo288543 Feb 25, 2024
caffdf3
Refactored express service for the question generation to follow stan…
PabloGOP Feb 25, 2024
e5b456b
Added random quesiton fetch and addQuestion to database
uo288543 Feb 26, 2024
260353d
Add method to get random questions with a specific category
uo288543 Feb 26, 2024
214bd37
Fixed errors and added sample questions to database
uo288543 Feb 26, 2024
2b810f1
Added a method to get questions directly from database
uo288543 Feb 26, 2024
6cb5a30
Fixed errors
uo288543 Feb 26, 2024
7a77a86
Added new url to get questions with category filter
uo288543 Feb 26, 2024
811e7a1
Fixes after meeting
uo288543 Feb 26, 2024
309618f
Restructure of folders
uo288347 Feb 27, 2024
b999aab
Changing structure
uo288347 Feb 27, 2024
202c738
Merge branch 'develop-questions' into develop-investigate-wikidata
uo288347 Feb 27, 2024
3ad815d
Merge pull request #83 from Arquisoft/develop-investigate-wikidata
PabloGOP Feb 27, 2024
25d80ab
Changed name of package according to last decision taken on the scope…
PabloGOP Feb 27, 2024
03386d7
Wikidata requests optimized
uo288347 Feb 28, 2024
423c1aa
Starting to generalize Wikidata requests
uo288347 Feb 28, 2024
caf4001
Requests in Spanish
uo288347 Feb 28, 2024
cf9c3f5
Rename cotyPopulation.js to generalQuestions.js
uo288347 Feb 28, 2024
ecc998a
Refactored Wikidata access to include it in its own service and actua…
PabloGOP Feb 28, 2024
0accaf5
Changed json structure to allow random question generation and update…
PabloGOP Feb 28, 2024
a692e13
Added code to get label of entity if property is entity not data
uo288543 Feb 29, 2024
c09554f
Fixed huge error that caused queries to fail
uo288543 Feb 29, 2024
b5c0920
Added one more template + minor fixes
uo288543 Feb 29, 2024
c2d72cd
Added one more question template
uo288543 Feb 29, 2024
ea10a40
Merge branch 'develop-webapp' into develop-questions
uo288347 Mar 2, 2024
d3d6db0
Added filter to city population query. Modified river query
uo288347 Mar 3, 2024
a897046
Implemented expected Queue functionality for questions DB
PabloGOP Mar 3, 2024
c6fc552
Merge branch 'develop-questions' of https://github.com/Arquisoft/wiq_…
PabloGOP Mar 3, 2024
291122d
Fixing bugs
uo288543 Mar 5, 2024
b476a4e
Fixed question generation
uo288543 Mar 5, 2024
f095b8b
Code to deploy questions (db not working)
uo288543 Mar 5, 2024
9b68856
questions ready to deploy (fixed docker deploy)
uo288543 Mar 5, 2024
3ef6a48
Question routes file renamed. Questions integrated with webapp: bug f…
uo288347 Mar 5, 2024
e4411f4
Added filter to city population queries
uo288347 Mar 5, 2024
60b705f
Changed url to fix a bug
uo288543 Mar 7, 2024
81f4b0e
Fix questions bug. Changed configurations .github
uo288347 Mar 7, 2024
1e9322e
Merge branch 'develop-questions' of https://github.com/Arquisoft/wiq_…
uo288347 Mar 7, 2024
57dbd2c
Merge questions branch with develop branch
uo288347 Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ DB_PORT=3306
MYSQL_USER=Admin
MYSQL_PASSWORD=Xp@7qZr#3wT2
DB_NAME=base_de_datos_de_usuarios
JWT_TOKEN='eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiQWRtaW4iLCJJc3N1ZXIiOiJJc3N1ZXIiLCJVc2VybmFtZSI6IkphdmFJblVzZSIsImV4cCI6MTcwOTQ2OTkzMywiaWF0IjoxNzA5NDY5OTMzfQ.pQ8H6FKeZyEHPnGs4Ah3-n-QXJ5E8YM_u1AfZHI7Ip0'
DATABASE_URI=mongodb://mongodb:27017/questionDB
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix users ci
- run: npm --prefix questions ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix users ci
- run: npm --prefix questions ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
node_modules
coverage
docs/build
.vscode

# Node.js dependencies
node_modules

# IDE/Editor files
.idea/
.vscode/
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,28 @@ services:
environment:
DATABASE_URL: mariadb:3306/userdb

questions:
container_name: questions-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es04a/questions:latest
profiles: ["dev", "prod"]
build: ./questions
depends_on:
- mongodb
ports:
- "8010:8010"
networks:
- mynetwork
environment:
DATABASE_URI: mongodb://mongodb:27017/questionDB

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_0/gatewayservice:latest
profiles: ["dev", "prod"]
build: ./gatewayservice
depends_on:
- mariadb
- users
- questions
ports:
- "8000:8000"
networks:
Expand Down
26 changes: 11 additions & 15 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const port = 8000;

const userServiceUrl = process.env.USER_SERVICE_URL || 'http://users:8001';

const questionGenerationServiceUrl = 'http://questions:8010';

app.use(cors());
app.use(express.json());

Expand Down Expand Up @@ -52,6 +54,15 @@ app.post('/user/add', async (req, res) => {
}
});

app.get('/questions', async (req, res) => {
try {
const questionsResponse = await axios.get(questionGenerationServiceUrl+'/questions/');
res.json(questionsResponse.data);
} catch (error) {
res.status(error.response).json({ error: error.response });
}
});

app.post('/user/edit', async (req, res) => {
try {
// Forward the add user request to the user service
Expand Down Expand Up @@ -83,21 +94,6 @@ app.get('/group/list', async (req, res) => {
}
});

app.post('/user/edit', async (req, res) => {
try {
// Forward the add user request to the user service
const userResponse = await axios.post(userServiceUrl + '/user/edit', req.body);
res.json(userResponse.data);
} catch (error) {
if (error.response && error.response.status) {
res.status(error.response.status).json({ error: error.response.data.error });
} else if (error.message) {
res.status(500).json({ error: error.message });
} else {
res.status(500).json({ error: 'Internal Server Error' });
}
}
});

app.post('/group/add', async (req, res) => {
try {
Expand Down
17 changes: 17 additions & 0 deletions questions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an official Node.js runtime as a parent image
FROM node:20

# Set the working directory in the container
WORKDIR /usr/src/questions

# 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 . .

# Define the command to run your app
CMD ["node", "index.js"]
23 changes: 23 additions & 0 deletions questions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Imports (express syntax)
const express = require('express');
const cors = require('cors');
// Routes:
const questionRoutes = require('./routes/question-routes.js');

// App definition and
const app = express();
const port = 8010;

// Middlewares added to the application
app.use(cors());
app.use(express.json());

// Routes middlewares to be used
app.use('/questions', questionRoutes);

// Start the service
const server = app.listen(port, () => {
console.log(`Question Service listening at http://localhost:${port}`);
});

module.exports = server
42 changes: 42 additions & 0 deletions questions/investigation_wikidata/bulkNodejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fetch = require('node-fetch');
const { wbk } = require('wikibase-sdk');

// Configura la URL base de la API de Wikidata
const wikidataEndpoint = 'https://www.wikidata.org/w/api.php';

// Función para hacer la consulta bulk
async function bulkQuery(entityIds, propertyIds) {
const formattedEntityIds = entityIds.join('|');
const formattedPropertyIds = propertyIds.join('|');
const sparqlQuery = `
SELECT ?item ?itemLabel ?property ?propertyLabel WHERE {
VALUES ?item {${formattedEntityIds}}
VALUES ?property {${formattedPropertyIds}}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
`;
const url = wbk.sparqlQuery(sparqlQuery);
const response = await fetch(url);
const data = await response.json();
return data.results.bindings;
}

function option5() {
// IDs de las entidades y propiedades que deseas consultar
const entityIds = ['Q515']; // Ejemplo de IDs de entidades
const propertyIds = ['P31', 'P1082']; // Ejemplo de IDs de propiedades

// Realizar la consulta bulk
bulkQuery(entityIds, propertyIds)
.then(results => {
console.log('Resultados de la consulta bulk:');
console.log(results);
})
.catch(error => {
console.error('Error al realizar la consulta bulk:', error);
});

}

module.exports = {option5};

Loading