Skip to content
Snippets Groups Projects
Commit d622ea60 authored by Fernando Gbur dos Santos's avatar Fernando Gbur dos Santos
Browse files

[ADD] First request to create the new attendance_rate route

parent 7e1b6edd
No related branches found
No related tags found
3 merge requests!417[ADD] Indicator "Taxa de Atendimento Educacional" updated on production!,!416[ADD] Route almost ready, some tests needed. Comments added and filters that...,!414[ADD] Route almost ready, some tests needed. Comments added and filters that...
...@@ -143,6 +143,8 @@ const activity = require(`${libs}/routes_v1/activity`); ...@@ -143,6 +143,8 @@ const activity = require(`${libs}/routes_v1/activity`);
const newPnad = require(`${libs}/routes_v1/newPnad`); const newPnad = require(`${libs}/routes_v1/newPnad`);
const rateSchoolNew = require(`${libs}/routes_v1/rateSchoolNew`)
const email = require(`${libs}/routes_v1/email`); const email = require(`${libs}/routes_v1/email`);
api.get('/', (req, res) => { api.get('/', (req, res) => {
...@@ -205,6 +207,7 @@ api.use('/universityLocalOffer', universityLocalOffer); ...@@ -205,6 +207,7 @@ api.use('/universityLocalOffer', universityLocalOffer);
api.use('/message', message); api.use('/message', message);
api.use('/course_students', courseStudents); api.use('/course_students', courseStudents);
api.use('/new_pnad', newPnad); api.use('/new_pnad', newPnad);
api.use('/rate_school_new', rateSchoolNew)
//Publication //Publication
api.use('/publication', publication); api.use('/publication', publication);
......
/*
Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
This file is part of simcaq-node.
simcaq-node is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
simcaq-node is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
*/
const express = require('express');
const rateSchoolNewApp = express.Router();
const libs = `${process.cwd()}/libs`;
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 config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
rateSchoolNewApp.use(cache('15 day'));
rateSchoolNewApp.get('/years', (req, res, next) => {
req.sql.from('pnad_novo')
.field('DISTINCT pnad_novo.ano_ref', 'year')
next();
}, query, response('years'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'id',
table: 'pnad_novo',
tableField: 'id',
where: {
relation: '=',
type: 'integer',
field: 'id'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: ['id', 'nome'],
resultField: ['state_id', 'state_nome'],
where: {
relation: '=',
type: 'integer',
field: 'id',
},
join: {
primary: 'id',
foreign: 'cod_uf',
foreignTable: 'pnad_novo'
}
}).addValue({
name: 'state_not',
table: 'estado',
tableField: ['nome', 'id'],
resultField: ['state_name', 'state_id'],
where: {
relation: '<>',
type: 'integer',
field: 'cod_uf',
table: 'pnad_novo'
},
join: {
primary: 'id',
foreign: 'cod_uf',
foreignTable: 'pnad_novo'
}
}).addValue({
name: 'years_of_study',
table: 'pnad_novo',
tableField: 'anos_de_estudo',
resultField: 'years_of_study_id',
where: {
relation: '=',
type: 'integer',
field: 'anos_de_estudo'
}
}).addValue({
name: 'instruction_level',
table: 'pnad_novo',
tableField: 'nivel_de_instrucao',
resultField: 'instruction_level_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_de_instrucao'
}
}).addValue({
name: 'new_pnad_adm_dependency',
table: 'pnad_novo',
tableField: 'dependencia_adm',
resultField: 'new_pnad_adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm'
}
}).addValue({
name: 'attends_school',
table: 'pnad_novo',
tableField: 'frequenta_escola',
resultField: 'attends_school_id',
where: {
relation: '=',
type: 'integer',
field: 'frequenta_escola'
}
}).addValue({
name: 'modality',
table: 'pnad_novo',
tableField: 'modalidade',
resultField: 'modality_id',
where: {
relation: '=',
type: 'integer',
field: 'modalidade'
}
}).addValue({
name: 'attended_modality',
table: 'pnad_novo',
tableField: 'nivel_etapa_modalidade_freq',
resultField: 'attended_modality_id',
where: {
relation: '=',
type: 'integer',
field: 'nivel_etapa_modalidade_freq'
}
}).addValue({
name: 'illiteracy',
table: 'pnad_novo',
tableField: 'analfabetismo',
resultField: 'illiteracy_id',
where: {
relation: '=',
type: 'integer',
field: 'analfabetismo'
}
}).addValue({
name: 'modality_shift',
table: 'pnad_novo',
tableField: 'turno_nivel_etapa',
resultField: 'modality_shift_id',
where: {
relation: '=',
type: 'integer',
field: 'turno_nivel_etapa'
}
}).addValue({
name: 'bolsa_familia',
table: 'pnad_novo',
tableField: 'recebeu_rendimentos_de_programa_bolsa_familia',
resultField: 'bolsa_familia_id',
where: {
relation: '=',
type: 'integer',
field: 'recebeu_rendimentos_de_programa_bolsa_familia'
}
}).addValue({
name: 'new_pnad_ethnic_group',
table: 'pnad_novo',
tableField: 'cor_raca',
resultField: 'new_pnad_ethnic_group_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca'
}
}).addValue({
name: 'age_range_all',
table: 'pnad_novo',
tableField: 'faixa_etaria',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria'
}
}).addValue({
name: 'income_range',
table: 'pnad_novo',
tableField: 'faixa_rendimento_aux',
resultField: 'income_range_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_rendimento_aux'
}
}).addValue({
name: 'gender',
table: 'pnad_novo',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
type: 'integer',
field: 'sexo'
}
}).addValue({
name: 'cap_code',
table: 'pnad_novo',
tableField: 'cod_cap',
resultField: 'cap_code_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_cap'
}
}).addValue({
name: 'region',
table: 'pnad_novo',
tableField: 'cod_regiao',
resultField: 'region_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_regiao'
}
}).addValue({
name: 'metro_code',
table: 'pnad_novo',
tableField: 'cod_rm_ride',
resultField: 'metro_code_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_rm_ride'
}
}).addValue({
name: 'min_year',
table: 'pnad_novo',
tableField: 'ano_ref',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_ref'
}
}).addValue({
name: 'max_year',
table: 'pnad_novo',
tableField: '',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_ref'
}
}).addField({
name: 'search',
field: false,
where: true
}).addValueToField({
name: 'name',
table: 'pnad_novo',
tableField: 'nome',
where: {
relation: 'LIKE',
type: 'string',
field: 'nome'
}
}, 'search').addValue({
name: 'mesoregion',
table: 'pnad_novo',
tableField: 'mesorregiao_id',
where: {
relation: '=',
type: 'integer',
field: 'mesorregiao_id'
}
}).addValue({
name: 'microregion',
table: 'pnad_novo',
tableField: 'microrregiao_id',
where: {
relation: '=',
type: 'integer',
field: 'microrregiao_id'
}
});
rateSchoolNewApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('pnad_novo')
.field('round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)', 'total')
.field('pnad_novo.faixa_etaria')
.field('pnad_novo.ano_ref', 'year')
.group('pnad_novo.ano_ref')
.group('pnad_novo.faixa_etaria')
.order('pnad_novo.ano_ref')
.order('pnad_novo.faixa_etaria')
console.log(req.sql.toString())
next();
}, query, id2str.transform(false), response('pnad_novo'));
module.exports = rateSchoolNewApp;
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