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

Add indicator population out of school

parent c84d0920
No related branches found
No related tags found
2 merge requests!124Release v1.1.0,!118Indicador população fora da escola
Pipeline #
...@@ -60,6 +60,8 @@ const distributionFactor = require(`${libs}/routes/distributionFactor`); ...@@ -60,6 +60,8 @@ const distributionFactor = require(`${libs}/routes/distributionFactor`);
const siope = require(`${libs}/routes/siope`); const siope = require(`${libs}/routes/siope`);
const outOfSchool = require(`${libs}/routes/outOfSchool`);
api.get('/', (req, res) => { api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' }); res.json({ msg: 'SimCAQ API is running' });
}); });
...@@ -92,5 +94,6 @@ api.use('/downloads', downloads); ...@@ -92,5 +94,6 @@ api.use('/downloads', downloads);
api.use('/infrastructure', infrastructure); api.use('/infrastructure', infrastructure);
api.use('/distribution_factor', distributionFactor); api.use('/distribution_factor', distributionFactor);
api.use('/siope', siope); api.use('/siope', siope);
api.use('/out_of_school', outOfSchool);
module.exports = api; module.exports = api;
const express = require('express');
const outOfSchoolApp = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`).query;
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
const addMissing = require(`${libs}/middlewares/addMissing`);
const config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
outOfSchoolApp.use(cache('15 day'));
outOfSchoolApp.get('/year_range', (req, res, next) => {
req.sql.from('pnad')
.field('MIN(pnad.ano_censo)', 'start_year')
.field('MAX(pnad.ano_censo)', 'end_year');
next();
}, query, response('range'));
outOfSchoolApp.get('/years', (req, res, next) => {
req.sql.from('pnad').
field('DISTINCT pnad.ano_censo', 'year');
next();
}, query, response('years'));
outOfSchoolApp.get('/age', (req, res, next) => {
req.result = [];
for(let i = 0; i <= 120; ++i) {
req.result.push({id: i, name: i+''});
}
next();
}, response('age'));
outOfSchoolApp.get('/ethnic_group_pnad', (req, res, next) => {
req.result = [
{id: 0, name: 'Indígena'},
{id: 1, name: 'Branca e amarela'},
{id: 2, name: 'Preta e parda'},
{id: 9, name: 'Sem declaração'}
];
next();
}, response('ethnic_group_pnad'));
outOfSchoolApp.get('/location', (req, res, next) => {
req.result = [
{id: 1, name: 'Urbana'},
{id: 2, name: 'Rural'}
];
next();
}, response('location'));
outOfSchoolApp.get('/gender', (req, res, next) => {
req.result = [
{id: 1, name: 'Masculino'},
{id: 2, name: 'Feminino'}
];
next();
}, response('gender'));
outOfSchoolApp.get('/fifth_household_income', (req, res, next) => {
req.result = [
{id: 1, name: '20% menores'},
{id: 2, name: '2o quinto'},
{id: 3, name: '3o quinto'},
{id: 4, name: '4o quinto'},
{id: 5, name: '20% maiores'},
{id: -1, name: 'Sem declaração'}
];
next();
},response('fifth_household_income'));
outOfSchoolApp.get('/extremes_household_income', (req, res, next) => {
req.result = [
{id: 1, name: '10% menores'},
{id: 2, name: '10% maiores'},
{id: -1, name: 'Sem declaração'}
];
next();
}, response('extremes_household_income'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'region',
table: 'regiao',
tableField: 'nome',
resultField: 'region_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'pnad'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'pnad'
}
}).addValue({
name: 'ethnic_group_pnad',
table: 'pnad',
tableField: 'cor_raca',
resultField: 'ethnic_group_pnad_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca'
}
}).addValue({
name: 'min_year',
table: 'pnad',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
table: 'pnad',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'pnad',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
table: 'pnad',
field: 'ano_censo'
}
}).addValue({
name: 'age',
table: 'pnad',
tableField: 'idade_31_03',
resultField: 'age_name',
where: {
relation: '=',
type: 'integer',
field: 'idade_31_03'
}
}).addValue({
name: 'gender',
table: 'pnad',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
type: 'integer',
field: 'sexo'
}
}).addValue({
name: 'location',
table: 'pnad',
tableField: 'localizacao_id',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_id'
}
}).addValue({
name: 'extremes_household_income',
table: 'pnad',
tableField: 'extremos_nivel_rendimento',
resultField: 'extremes_household_income_id',
where: {
relation: '=',
type: 'integer',
field: 'extremos_nivel_rendimento'
}
}).addValue({
name: 'fifth_household_income',
table: 'pnad',
tableField: 'quintil_nivel_rendimento',
resultField: 'fifth_household_income_id',
where: {
relation: '=',
type: 'integer',
field: 'quintil_nivel_rendimento'
}
});
outOfSchoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('pnad')
.field('SUM(pnad.peso)', 'total')
.field('pnad.ano_censo', 'year')
.where('pnad.escolaridade_familiar >= 1 AND pnad.escolaridade_familiar <= 4 AND pnad.frequenta_escola_creche = 4')
.group('pnad.ano_censo')
.order('pnad.ano_censo');
next();
}, query, addMissing(rqf), id2str.transform(), response('out_of_school'));
module.exports = outOfSchoolApp;
\ No newline at end of file
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