Skip to content
Snippets Groups Projects
Commit cb99a654 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'pib_per_capita' into development

!58
Conflicts:
	src/libs/routes/api.js
parents 18f0b741 77fe4915
No related branches found
No related tags found
1 merge request!116Release v1.0.0
Pipeline #
......@@ -32,6 +32,10 @@ const teacher = require('./teacher');
const idhme = require('./idhme');
const pibpercapita = require('./pibpercapita')
const population = require('./population')
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' });
});
......@@ -49,5 +53,7 @@ api.use('/spatial', cache('1 day'), spatial);
api.use('/classroom', cache('15 day'), classroom);
api.use('/teacher', cache('1 day'), teacher);
api.use('/idhme', cache('15 day'), idhme);
api.use('/pibpercapita', cache('1 day'), pibpercapita);
api.use('/population', cache('1 day'), population);
module.exports = api;
const express = require('express');
const pibpercapitaApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
pibpercapitaApp.get('/year_range', (req, res, next) => {
req.sql.from('ibge_pib')
.field('MIN(ibge_pib.ano_censo)', 'start_year')
.field('MAX(ibge_pib.ano_censo)', 'end_year');
next();
}, query, response('range'));
pibpercapitaApp.get('/income_level', (req, res, next) => {
req.result = [
{id: 1, name: "1º quintil – 20% menores"},
{id: 2, name: "2º quintil"},
{id: 3, name: "3º quintil"},
{id: 4, name: "4º quintil"},
{id: 5, name: "5º quintil – 20% maiores"},
];
next();
}, response('income_level'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'municipio_id',
table: 'ibge_pib'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'ibge_pib'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'ibge_pib'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'ibge_pib'
}
}).addValue({
name: 'min_year',
table: 'ibge_pib',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'ibge_pib',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'income_level',
table: 'ibge_pib',
tableField: 'nivel_renda_per_capita',
resultField: 'income_level_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_renda_per_capita'
}
});
pibpercapitaApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
log.debug(req.sql.toParam());
req.sql.from('ibge_pib')
.field('SUM(ibge_pib.pib)/SUM(ibge_pib.populacao)', 'pibpercapita')
.field('ibge_pib.ano_censo', 'year')
.group('ibge_pib.ano_censo')
.order('ibge_pib.ano_censo')
next();
}, query, id2str.transform(true), response('pibpercapita'));
module.exports = pibpercapitaApp;
const express = require('express');
const populationApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
let rqf = new ReqQueryFields();
populationApp.get('/year_range', (req, res, next) => {
req.sql.from('ibge_populacao')
.field('MIN(ibge_populacao.ano_censo)', 'start_year')
.field('MAX(ibge_populacao.ano_censo)', 'end_year');
next();
}, query, response('range'));
populationApp.get('/city_size', (req, res, next) => {
req.result = [
{id: 1, name: "até 5000"},
{id: 2, name: "5001 - 10000"},
{id: 3, name: "10001 - 20000"},
{id: 4, name: "20001 - 50000"},
{id: 5, name: "50001 - 100000"},
{id: 6, name: "100001 - 500000"},
{id: 7, name: "mais que 500000"}
];
next();
}, response('city_size'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'municipio_id',
table: 'ibge_populacao'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'ibge_populacao'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'ibge_populacao'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'ibge_populacao'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: 'nome',
resultField: 'region_name',
where: {
relation: '=',
type: 'integer',
field: 'regiao_id',
table: 'ibge_populacao'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'ibge_populacao'
}
}).addValue({
name: 'min_year',
table: 'ibge_populacao',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'ibge_populacao',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'city_size',
table: 'ibge_populacao',
tableField: 'porte',
resultField: 'city_size_id',
where: {
relation: '=',
type: 'integer',
field: 'porte'
}
});
populationApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
log.debug(req.sql.toParam());
log.debug(req.dims);
req.sql.from('ibge_populacao')
.field('SUM(ibge_populacao.populacao)', 'total')
.field('ibge_populacao.ano_censo', 'year')
.group('ibge_populacao.ano_censo')
.order('ibge_populacao.ano_censo')
next();
}, query, id2str.transform(true), response('population'));
module.exports = populationApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment