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

Merge branch 'indicador_pop_fora_escola' into release_v1.1.0

parents 064a5651 385740b0
No related branches found
No related tags found
1 merge request!124Release v1.1.0
Pipeline #
......@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Added
* Out of school population indicator
## 1.0.3 - 2018-04-27
### Changed
- Fixed bug undefined field in some indicators
......
module.exports = function ageRange(id) {
switch (id) {
case 1:
return '0-3';
case 2:
return '4-5';
case 3:
return '6-10';
case 4:
return '11-14';
case 5:
return '15-17';
case 6:
return '18-24';
case 7:
return '25-29';
case 8:
return '30-40';
case 9:
return '41-50';
case 10:
return '51-64';
case 11:
return '64+';
default:
return 'Não declarada';
}
};
......@@ -20,6 +20,7 @@ const stateName = require(`${libs}/convert/stateName`);
const contractType = require(`${libs}/convert/contractType`);
const ethnicGroupPnad = require(`${libs}/convert/ethnicGroupPnad`);
const ageRange = require(`${libs}/convert/ageRange`);
const fullAgeRange = require(`${libs}/convert/fullAgeRange`);
const genderPnad = require(`${libs}/convert/genderPnad`);
const fifthHouseholdIncome = require(`${libs}/convert/fifthHouseholdIncome`);
const extremesHouseholdIncome = require(`${libs}/convert/extremesHouseholdIncome`);
......@@ -57,6 +58,7 @@ const ids = {
contract_type_id: contractType,
ethnic_group_pnad_id: ethnicGroupPnad,
age_range_id: ageRange,
full_age_range_id: fullAgeRange,
gender_pnad_id: genderPnad,
fifth_household_income_id: fifthHouseholdIncome,
extremes_household_income_id: extremesHouseholdIncome
......@@ -122,6 +124,7 @@ module.exports = {
contractType,
ethnicGroupPnad,
ageRange,
fullAgeRange,
genderPnad,
fifthHouseholdIncome,
extremesHouseholdIncome
......
......@@ -60,6 +60,8 @@ const distributionFactor = require(`${libs}/routes/distributionFactor`);
const siope = require(`${libs}/routes/siope`);
const outOfSchool = require(`${libs}/routes/outOfSchool`);
api.get('/', (req, res) => {
res.json({ msg: 'SimCAQ API is running' });
});
......@@ -92,5 +94,6 @@ api.use('/downloads', downloads);
api.use('/infrastructure', infrastructure);
api.use('/distribution_factor', distributionFactor);
api.use('/siope', siope);
api.use('/out_of_school', outOfSchool);
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('/full_age_range', (req, res, next) => {
req.result = [
{id: 1, name: '0-3'},
{id: 2, name: '4-5'},
{id: 3, name: '6-10'},
{id: 4, name: '11-14'},
{id: 5, name: '15-17'},
{id: 6, name: '18-24'},
{id: 7, name: '25-29'},
{id: 8, name: '30-40'},
{id: 9, name: '41-50'},
{id: 10, name: '51-64'},
{id: 11, name: '64+'}
];
next();
}, response('full_age_range'));
outOfSchoolApp.get('/ethnic_group', (req, res, next) => {
req.result = [
{id: 0, name: 'Sem declaração'},
{id: 1, name: 'Branca'},
{id: 2, name: 'Preta'},
{id: 3, name: 'Parda'},
{id: 4, name: 'Amarela'},
{id: 5, name: 'Indígena'}
];
next();
}, response('ethnic_group'));
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',
table: 'pnad',
tableField: 'cor_raca_id',
resultField: 'ethnic_group_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca_id'
}
}).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: 'full_age_range',
table: 'pnad',
tableField: 'faixa_etaria_31_03',
resultField: 'full_age_range_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria_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