diff --git a/CHANGELOG.md b/CHANGELOG.md index ad61ef515ed1da4792bde55953f54e7c63caefd2..52fe3ae4e5ab21dd3d5500a98a0aa4055ec1619b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ 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/). +## 1.1.0 +### Added +- Out of school population indicator +- Liquid enrollment ratio indicator +- Gloss enrollment ratio indicator + + ## 1.0.3 - 2018-04-27 ### Changed - Fixed bug undefined field in some indicators diff --git a/src/libs/convert/fullAgeRange.js b/src/libs/convert/fullAgeRange.js new file mode 100644 index 0000000000000000000000000000000000000000..d7b36fdc9aee2e459126feb457695c9ea13aa7d5 --- /dev/null +++ b/src/libs/convert/fullAgeRange.js @@ -0,0 +1,28 @@ +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'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index a6c4af2ed6a429baaeffc90d2a0ec220ba4eea58..776c338219297401aee5bb398810c0b50544198d 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -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 diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 2b56919393323db34a82b3f4373f39c1684a28dc..be86d04106e232beb341a1385a408754cb3f2a89 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -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; diff --git a/src/libs/routes/outOfSchool.js b/src/libs/routes/outOfSchool.js new file mode 100644 index 0000000000000000000000000000000000000000..b3b6e930dc265ecd198ba95a1862679448627a6b --- /dev/null +++ b/src/libs/routes/outOfSchool.js @@ -0,0 +1,241 @@ +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