Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
aad36ec1
Commit
aad36ec1
authored
3 months ago
by
lgtg20
Browse files
Options
Downloads
Patches
Plain Diff
feat: dimensions for all necessary data
parent
b672b91b
No related branches found
Branches containing commit
No related tags found
4 merge requests
!449
Homologa
,
!444
dev -> hom
,
!440
New indicators
,
!439
Issue 935
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/routes_v1/adjustedLiquidFrequency.js
+44
-65
44 additions, 65 deletions
src/libs/routes_v1/adjustedLiquidFrequency.js
with
44 additions
and
65 deletions
src/libs/routes_v1/adjustedLiquidFrequency.js
+
44
−
65
View file @
aad36ec1
...
@@ -142,16 +142,6 @@ rqf.addField({
...
@@ -142,16 +142,6 @@ rqf.addField({
foreign
:
'
cod_uf
'
,
foreign
:
'
cod_uf
'
,
foreignTable
:
'
pnad_novo
'
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
({
}).
addValue
({
name
:
'
bolsa_familia
'
,
name
:
'
bolsa_familia
'
,
table
:
'
pnad_novo
'
,
table
:
'
pnad_novo
'
,
...
@@ -265,57 +255,32 @@ rqf.addField({
...
@@ -265,57 +255,32 @@ rqf.addField({
}
}
});
});
function
matchQueries
(
queryPartial
,
queryTotal
)
{
let
match
=
[];
queryTotal
.
forEach
((
result
)
=>
{
let
newObj
=
{};
let
keys
=
Object
.
keys
(
result
);
keys
.
forEach
((
key
)
=>
{
newObj
[
key
]
=
result
[
key
];
});
let
index
=
keys
.
indexOf
(
'
total
'
);
if
(
index
>
-
1
)
keys
.
splice
(
index
,
1
);
let
objMatch
=
null
;
for
(
let
i
=
0
;
i
<
queryPartial
.
length
;
++
i
)
{
let
partial
=
queryPartial
[
i
];
let
foundMatch
=
true
;
for
(
let
j
=
0
;
j
<
keys
.
length
;
++
j
)
{
let
key
=
keys
[
j
];
if
(
partial
[
key
]
!==
result
[
key
])
{
foundMatch
=
false
;
break
;
}
}
if
(
foundMatch
)
{
objMatch
=
partial
;
break
;
}
}
if
(
objMatch
)
{
newObj
.
denominator
=
result
.
total
;
newObj
.
partial
=
objMatch
.
total
;
newObj
.
total
=
(
objMatch
.
total
/
result
.
total
)
*
100
;
match
.
push
(
newObj
);
}
});
return
match
;
}
adjustedLiquidFrequency
.
get
(
'
/
'
,
rqf
.
parse
(),
(
req
,
res
,
next
)
=>
{
adjustedLiquidFrequency
.
get
(
'
/
'
,
rqf
.
parse
(),
(
req
,
res
,
next
)
=>
{
const
dimensions
=
req
.
dims
||
{};
// Obter dimensões solicitadas pela requisição
// Subquery: total_pop
// Subquery: total_pop
let
totalPop
=
squel
.
select
()
let
totalPop
=
squel
.
select
()
.
field
(
"
ano_ref
"
)
.
field
(
"
ano_ref
"
)
.
field
(
"
faixa_etaria
"
)
.
field
(
"
faixa_etaria
"
)
.
field
(
"
SUM(peso_domicilio_pessoas_com_cal)
"
,
"
total
"
)
.
field
(
"
SUM(peso_domicilio_pessoas_com_cal)
"
,
"
total
"
)
.
from
(
"
pnad_novo
"
)
.
from
(
"
pnad_novo
"
)
.
group
(
"
ano_ref
"
)
.
where
(
"
faixa_etaria <= 6
"
)
.
group
(
"
faixa_etaria
"
);
.
group
(
"
ano_ref
"
)
.
group
(
"
faixa_etaria
"
);
// Aplicando filtros dinâmicos à subquery total_pop
// Aplicar filtros dinâmicos à subquery total_pop
totalPop
=
rqf
.
buildQuery
(
req
,
totalPop
);
totalPop
=
rqf
.
buildQuery
(
req
,
totalPop
);
const
joinQuery
=
`
total_pop.ano_ref = pnad_novo.ano_ref AND
total_pop.faixa_etaria = pnad_novo.apoio_frequencia_ajustada
${
dimensions
.
gender
?
"
AND total_pop.gender_id = pnad_novo.sexo
"
:
""
}
${
dimensions
.
bolsa_familia
?
"
AND total_pop.bolsa_familia_id = pnad_novo.recebeu_rendimentos_de_programa_bolsa_familia
"
:
""
}
${
dimensions
.
new_pnad_ethnic_group
?
"
AND total_pop.new_pnad_ethnic_group_id = pnad_novo.cor_raca
"
:
""
}
${
dimensions
.
income_range
?
"
AND total_pop.income_range_id = pnad_novo.faixa_rendimento_aux_tx
"
:
""
}
`
// Subquery: total_apoio_freq
// Subquery: total_apoio_freq
let
totalApoioFreq
=
squel
.
select
()
let
totalApoioFreq
=
squel
.
select
()
...
@@ -326,26 +291,40 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => {
...
@@ -326,26 +291,40 @@ adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => {
.
from
(
"
pnad_novo
"
)
.
from
(
"
pnad_novo
"
)
.
join
(
.
join
(
totalPop
,
totalPop
,
"
total_pop
"
,
"
total_pop
"
,
"
total_pop.ano_ref = pnad_novo.ano_ref AND total_pop.faixa_etaria = pnad_novo.apoio_frequencia_ajustada
"
joinQuery
)
)
.
group
(
"
pnad_novo.ano_ref
"
)
.
group
(
"
pnad_novo.ano_ref
"
)
.
group
(
"
pnad_novo.apoio_frequencia_ajustada
"
)
.
group
(
"
pnad_novo.apoio_frequencia_ajustada
"
)
.
group
(
"
total_pop.total
"
);
.
group
(
"
total_pop.total
"
);
// Aplica
ndo
filtros à subquery total_apoio_freq
// Aplica
r
filtros
dinâmicos
à subquery total_apoio_freq
totalApoioFreq
=
rqf
.
buildQuery
(
req
,
totalApoioFreq
);
totalApoioFreq
=
rqf
.
buildQuery
(
req
,
totalApoioFreq
);
// Query principal
// Query Principal
req
.
sql
=
squel
.
select
()
let
mainQuery
=
squel
.
select
()
.
from
(
totalApoioFreq
,
"
total_apoio_freq
"
)
.
field
(
"
total_apoio_freq.ano_ref
"
)
.
field
(
"
total_apoio_freq.ano_ref
"
)
.
field
(
"
total_apoio_freq.apoio_frequencia_ajustada
"
)
.
field
(
"
total_apoio_freq.apoio_frequencia_ajustada
"
,
"
age_range_all_id
"
)
.
field
(
"
ROUND((total_apoio_freq.total_freq / total_apoio_freq.total) * 100, 1)
"
,
"
total
"
)
.
field
(
"
ROUND((total_apoio_freq.total_freq / total_apoio_freq.total) * 100, 1)
"
,
"
total
"
)
.
from
(
totalApoioFreq
,
"
total_apoio_freq
"
)
.
where
(
"
total_apoio_freq.ano_ref >= 2019
"
)
.
where
(
"
total_apoio_freq.ano_ref >= 2019
"
)
// Corrigido para usar alias correto
.
order
(
"
total_apoio_freq.ano_ref
"
)
.
order
(
"
total_apoio_freq.ano_ref
"
)
.
order
(
"
total_apoio_freq.apoio_frequencia_ajustada
"
);
.
order
(
"
total_apoio_freq.apoio_frequencia_ajustada
"
);
if
(
dimensions
.
gender
)
mainQuery
.
field
(
"
total_apoio_freq.gender_id
"
)
if
(
dimensions
.
bolsa_familia
)
mainQuery
.
field
(
"
total_apoio_freq.bolsa_familia_id
"
)
if
(
dimensions
.
new_pnad_ethnic_group
)
mainQuery
.
field
(
"
total_apoio_freq.new_pnad_ethnic_group_id
"
)
if
(
dimensions
.
income_range
)
mainQuery
.
field
(
"
total_apoio_freq.income_range_id
"
)
req
.
sql
=
mainQuery
;
next
();
next
();
},
query
,
id2str
.
transform
(
false
),
response
(
'
adjusted_liquid_frequency
'
));
},
query
,
id2str
.
transform
(
false
),
response
(
'
adjusted_liquid_frequency
'
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment