Skip to content
Snippets Groups Projects
Commit fad04d90 authored by lgtg20's avatar lgtg20
Browse files

feat: all dimensions working

parent 8182ab5f
Branches
No related tags found
3 merge requests!449Homologa,!444dev -> hom,!441Years of study mean
......@@ -472,7 +472,7 @@ rqf.addField({
}).addValue({
name: 'max_year',
table: 'pnad_novo',
tableField: '',
tableField: 'ano_ref',
resultField: 'year',
where: {
relation: '<=',
......@@ -513,14 +513,21 @@ rqf.addField({
});
PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
let teste = "pnad_novo.ano_ref = media.ano_ref"
console.log(req.dims)
if (req.dims) {
for (let i in req.dims) {
teste += ` and pnad_novo.${rqf[i].table} = media.${rqf[i].tableField}`
}
}
const dimensions = req.dims || {};
let joinQuery = `
pnad_novo.ano_ref = media.ano_ref
${dimensions.gender ? " AND media.gender_id = pnad_novo.sexo" : ""}
${dimensions.bolsa_familia ? "AND media.bolsa_familia_id = pnad_novo.recebeu_rendimentos_de_programa_bolsa_familia" : ""}
${dimensions.new_pnad_ethnic_group ? "AND media.new_pnad_ethnic_group_id = pnad_novo.cor_raca" : ""}
${dimensions.income_range ? "AND media.income_range_id = pnad_novo.faixa_rendimento_aux_tx" : ""}
${dimensions.age_range_all ? "AND media.age_range_all_id = pnad_novo.faixa_etaria" : ""}
${dimensions.location ? "AND media.location_id = pnad_novo.situacao_domicilio" : ""}
${dimensions.metro_code ? "AND media.metro_code_id = pnad_novo.cod_rm_ride" : ""}
${dimensions.cap_code ? "AND media.cap_code_id = pnad_novo.cod_cap" : ""}
${dimensions.region ? "AND media.region_id = pnad_novo.cod_regiao" : ""}
${dimensions.state ? "AND media.state_id = pnad_novo.cod_uf" : ""}
`
let mean = req.sql.clone()
.from('pnad_novo')
......@@ -533,11 +540,11 @@ PnadNovoApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.field('pnad_novo.ano_ref', 'year')
.field('media.media_anos_estudo', 'mean')
.field('SQRT(SUM(POWER(pnad_novo.anos_de_estudo - media.media_anos_estudo, 2) * pnad_novo.peso_domicilio_pessoas_com_cal) / SUM(pnad_novo.peso_domicilio_pessoas_com_cal))', 'std_dev')
.join(mean, 'media', teste)
.join(mean, 'media', joinQuery)
.where('pnad_novo.ano_ref >= 2019 AND pnad_novo.faixa_etaria >= 6 AND pnad_novo.anos_de_estudo <> 99')
.group('pnad_novo.ano_ref')
.group('media.media_anos_estudo')
console.log(req.sql.toString())
next();
}, query, id2str.transform(false), response('years_of_study'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment