Skip to content
Snippets Groups Projects
Commit 780ea8c4 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Add struct for gloss enrollment ratio indicator

parent dcdc5773
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!106Gloss enrollment ratio route
Pipeline #
......@@ -34,6 +34,8 @@ const population = require('./population')
const rateSchool = require('./rateSchool')
const glossEnrollmentRatio = require('./glossEnrollmentRatio')
const idhm = require('./idhm');
const idhmr = require('./idhmr');
......@@ -77,6 +79,7 @@ api.use('/idhme', idhme);
api.use('/pibpercapita', pibpercapita);
api.use('/population', population);
api.use('/rate_school', rateSchool);
api.use('/gloss_enrollment_ratio', glossEnrollmentRatio);
api.use('/idhml', idhml);
api.use('/auth/token', oauth2.token);
api.use('/verify', verifyToken);
......
const express = require('express');
const glossEnrollmentRatioApp = 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 multiQuery = require(`${libs}/middlewares/multiQuery`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const id2str = require(`${libs}/middlewares/id2str`);
const config = require(`${libs}/config`);
const download = require(`${libs}/middlewares/downloadDatabase`);
const passport = require('passport');
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
glossEnrollmentRatioApp.use(cache('15 day'));
let rqf = new ReqQueryFields();
// Complete range of the enrollments dataset.
// Returns a tuple of start and ending years of the complete enrollments dataset.
glossEnrollmentRatioApp.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'));
glossEnrollmentRatioApp.get('/years', (req, res, next) => {
req.sql.from('pnad')
.field('DISTINCT pnad.ano_censo', 'year');
next();
}, query, response('years'));
glossEnrollmentRatioApp.get('/source', (req, res, next) => {
req.sql.from('fonte')
.field('fonte', 'source')
.where('tabela = \'pnad\'');
next();
}, query, response('source'));
glossEnrollmentRatioApp.get('/location', (req, res, next) => {
req.result = [
{id: 1, name: 'Urbana'},
{id: 2, name: 'Rural'}
];
next();
}, response('location'));
glossEnrollmentRatioApp.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'));
glossEnrollmentRatioApp.get('/gender', (req, res, next) => {
req.result = [
{id: 2, name: 'Masculino'},
{id: 4, name: 'Feminino'}
];
next();
}, response('gender'));
glossEnrollmentRatioApp.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'));
glossEnrollmentRatioApp.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_id',
resultField: 'ethnic_group_pnad_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: 'age_range',
table: 'pnad',
tableField: 'faixa_etaria_31_03',
resultField: 'age_range_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria_31_03'
}
}).addValue({
name: 'gender',
table: 'pnad',
tableField: 'sexo',
resultField: 'gender_pnad_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'
}
});
glossEnrollmentRatioApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
next();
}, id2str.transform(false), response('rateSchool'));
glossEnrollmentRatioApp.get('/download', passport.authenticate('bearer', { session: false }), rqf.parse(), rqf.build(), download('pnad', 'mapping_pnad'));
module.exports = glossEnrollmentRatioApp;
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