Skip to content

Commit

Permalink
feat(scraper): otimiza o scraper para pegar a quantidade de focos tot…
Browse files Browse the repository at this point in the history
…al no mes para cada estado
  • Loading branch information
Arturhk05 committed Jan 17, 2025
1 parent aed35ef commit 3c99aeb
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 260 deletions.
24 changes: 13 additions & 11 deletions backend/api/repositories/FocusRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class FocusRepository {

async getCountByYear(ano) {
return new Promise((resolve, reject) => {
const query = 'SELECT count(*) FROM focos WHERE ano = ?';
const query = 'SELECT sum(quantidade_focos) FROM focos WHERE ano = ?';
connection.query(query, [ano], (err, results) => {
if (err) {
return reject(new Error('Erro ao obter dados: ' + err.message));
Expand All @@ -16,10 +16,11 @@ export default class FocusRepository {

async getMonthlyFocusByEstate(month, year) {
const query = `
SELECT ano, MONTH(data_pas) AS mes, estado, COUNT(*) AS contagem
SELECT estado, sum(quantidade_focos) AS quantidade_focos, mes, ano
FROM focos
WHERE MONTH(data_pas) = ? AND ano = ?
GROUP BY mes, estado;
WHERE mes = ? AND ano = ?
GROUP BY mes, estado
order by estado
`;

return new Promise((resolve, reject) => {
Expand All @@ -34,10 +35,11 @@ export default class FocusRepository {

async getMonthlyFocusByRegion(month, year) {
const query = `
SELECT ano, MONTH(data_pas) AS mes, regiao, COUNT(*) AS contagem
SELECT regiao, sum(quantidade_focos) as quantidade_focos, mes, ano
FROM focos
WHERE MONTH(data_pas) = ? AND ano = ?
GROUP BY mes, regiao;
WHERE mes = ? AND ano = ?
GROUP BY mes, regiao
order by regiao;
`;

return new Promise((resolve, reject) => {
Expand All @@ -52,10 +54,10 @@ export default class FocusRepository {

async getYearFocusFromRegion(region, year) {
const query = `
SELECT ano, MONTH(data_pas) as mes, regiao, count(*) as quantidade_focos
SELECT mes, regiao, sum(quantidade_focos) as quantidade_focos, ano
FROM focos
WHERE ano = ? AND regiao = ?
GROUP BY MONTH(data_pas)
GROUP BY mes
ORDER BY mes;
`;

Expand All @@ -71,10 +73,10 @@ export default class FocusRepository {

async getYearFocusFromEstate(estate, year) {
const query = `
SELECT ano, MONTH(data_pas) as mes, estado, count(*) as quantidade_focos
SELECT mes, estado, sum(quantidade_focos) as quantidade_focos, ano
FROM focos
WHERE ano = ? AND estado = ?
GROUP BY MONTH(data_pas)
GROUP BY mes
ORDER BY mes;
`;

Expand Down
124 changes: 0 additions & 124 deletions backend/scraper/coletaAnual.js

This file was deleted.

Loading

0 comments on commit 3c99aeb

Please sign in to comment.