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
a209ef26
Commit
a209ef26
authored
3 months ago
by
tgcl21
Browse files
Options
Downloads
Patches
Plain Diff
initial
parent
e671157c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/routes_v1/enrollmentRate.js
+282
-0
282 additions, 0 deletions
src/libs/routes_v1/enrollmentRate.js
with
282 additions
and
0 deletions
src/libs/routes_v1/enrollmentRate.js
0 → 100644
+
282
−
0
View file @
a209ef26
/*
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
EnrollmentRateApp
=
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
multiQuery
=
require
(
`
${
libs
}
/middlewares/multiQuery`
);
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
();
EnrollmentRateApp
.
use
(
cache
(
'
15 day
'
));
EnrollmentRateApp
.
get
(
'
/years
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
pnad_novo
'
)
.
field
(
'
DISTINCT pnad_novo.ano_ref
'
,
'
year
'
)
next
();
},
query
,
response
(
'
years
'
));
EnrollmentRateApp
.
get
(
'
/ageRanges
'
,
(
req
,
res
,
next
)
=>
{
req
.
sql
.
from
(
'
pnad_novo
'
)
.
field
(
'
DISTINCT pnad_novo.faixa_etaria
'
,
'
age_range
'
)
next
();
},
query
,
response
(
'
ageRanges
'
));
rqf
.
addField
({
name
:
'
filter
'
,
field
:
false
,
where
:
true
}).
addField
({
name
:
'
dims
'
,
field
:
true
,
where
:
false
}).
addValue
({
name
:
'
location
'
,
table
:
'
pnad_novo
'
,
tableField
:
'
situacao_domicilio
'
,
resultField
:
'
location_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
situacao_domicilio
'
}
}).
addValue
({
name
:
'
location_escola
'
,
table
:
'
escola
'
,
tableField
:
'
localizacao_id
'
,
resultField
:
'
location_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
localizacao_id
'
}
}).
addValue
({
name
:
'
cap_code
'
,
table
:
'
pnad_novo
'
,
tableField
:
'
cod_cap
'
,
resultField
:
'
cap_code_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
cod_cap
'
}
}).
addValue
({
name
:
'
cod_mun
'
,
table
:
'
escola
'
,
tableField
:
'
municipio_id
'
,
resultField
:
'
municipio_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
municipio_id
'
}
}).
addValue
({
name
:
'
region
'
,
table
:
'
pnad_novo
'
,
tableField
:
'
cod_regiao
'
,
resultField
:
'
region_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
cod_regiao
'
}
}).
addValue
({
name
:
'
region_escola
'
,
table
:
'
escola
'
,
tableField
:
'
regiao_id
'
,
resultField
:
'
regiao_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
regiao_id
'
}
}).
addValue
({
name
:
'
state
'
,
table
:
'
pnad_novo
'
,
tableField
:
'
cod_uf
'
,
resultField
:
'
cod_uf
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
cod_uf
'
,
}
}).
addValue
({
name
:
'
state_escola
'
,
table
:
'
escola
'
,
tableField
:
'
estado_id
'
,
resultField
:
'
estado_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
estado_id
'
}
}).
addValue
({
name
:
'
faixa_etaria
'
,
table
:
'
pnad_novo
'
,
tableField
:
'
faixa_etaria
'
,
resultField
:
'
age_range_id
'
,
where
:
{
relation
:
'
=
'
,
type
:
'
integer
'
,
field
:
'
faixa_etaria
'
}
})
function
matchQueries
(
queryPartial
,
queryTotal
)
{
let
match
=
[];
console
.
log
(
queryPartial
,
queryTotal
)
queryTotal
.
forEach
((
result
)
=>
{
let
found
=
false
;
queryPartial
.
forEach
((
partial
)
=>
{
console
.
log
(
result
.
year
,
partial
.
year
)
if
(
result
.
year
===
partial
.
year
)
{
switch
(
result
.
age_range
)
{
case
1
:
console
.
log
(
"
é 1
"
)
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_partial
:
partial
.
total_inf_cre
,
total_taxa
:
((
partial
.
total_inf_cre
/
result
.
total
)
*
100
).
toFixed
(
2
),
});
found
=
true
;
break
;
case
2
:
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_partial
:
partial
.
total_inf_pre
,
total_taxa
:
((
partial
.
total_inf_pre
/
result
.
total
)
*
100
).
toFixed
(
2
),
});
found
=
true
;
break
;
case
3
:
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_partial
:
partial
.
total_fund_ai
,
total_taxa
:
((
partial
.
total_fund_ai
/
result
.
total
)
*
100
).
toFixed
(
2
),
});
found
=
true
;
break
;
case
4
:
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_partial
:
partial
.
total_fund_af
,
total_taxa
:
((
partial
.
total_fund_af
/
result
.
total
)
*
100
).
toFixed
(
2
),
});
found
=
true
;
break
;
case
5
:
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_partial
:
partial
.
total_med
,
total_taxa
:
((
partial
.
total_med
/
result
.
total
)
*
100
).
toFixed
(
2
),
});
found
=
true
;
break
;
default
:
break
;
}
}
});
if
(
!
found
)
{
match
.
push
({
year
:
result
.
year
,
age_range
:
result
.
age_range
,
total
:
result
.
total
,
total_taxa
:
0
,
});
}
});
return
match
;
}
EnrollmentRateApp
.
get
(
'
/
'
,
rqf
.
parse
(),
rqf
.
build
(),
(
req
,
res
,
next
)
=>
{
req
.
querySet
=
[];
let
padrao
=
req
.
sql
.
clone
()
.
from
(
'
escola
'
)
.
field
(
'
escola.ano_censo
'
,
'
year
'
)
.
field
(
'
sum(escola.qt_mat_inf_cre)
'
,
'
total_inf_cre
'
)
.
field
(
'
sum(escola.qt_mat_inf_pre)
'
,
'
total_inf_pre
'
)
.
field
(
'
sum(escola.qt_mat_fund_ai)
'
,
'
total_fund_ai
'
)
.
field
(
'
sum(escola.qt_mat_fund_af)
'
,
'
total_fund_af
'
)
.
field
(
'
sum(escola.qt_mat_med)
'
,
'
total_med
'
)
.
where
(
'
escola.situacao_funcionamento_pareada = 1
'
)
.
where
(
'
(escola.ensino_regular = 1 or escola.ensino_eja = 1 or escola.educacao_profissional = 1)
'
)
.
where
(
'
escola.ano_censo IN (2019, 2022, 2023)
'
)
.
group
(
'
escola.ano_censo
'
);
let
subquery
=
req
.
sql
.
clone
()
.
from
(
'
pnad_novo
'
)
.
field
(
'
round(sum(pnad_novo.peso_domicilio_pessoas_com_cal), 0)
'
,
'
total
'
)
.
field
(
'
pnad_novo.faixa_etaria
'
,
'
age_range
'
)
.
field
(
'
pnad_novo.ano_ref
'
,
'
year
'
)
.
where
(
'
pnad_novo.ano_ref IN (2019, 2022, 2023) AND pnad_novo.faixa_etaria IN (1, 2, 3, 4, 5)
'
)
.
group
(
'
pnad_novo.ano_ref
'
)
.
group
(
'
pnad_novo.faixa_etaria
'
)
.
order
(
'
pnad_novo.ano_ref
'
)
.
order
(
'
pnad_novo.faixa_etaria
'
);
req
.
querySet
.
push
(
padrao
);
req
.
querySet
.
push
(
subquery
);
next
();
},
multiQuery
,
(
req
,
res
,
next
)
=>
{
// The multiple requests are made. Then we need to calculate the percetange. So the function
// below is used
let
newObj
=
matchQueries
(
req
.
result
[
0
],
req
.
result
[
1
]);
req
.
result
=
newObj
;
next
();
},
id2str
.
transform
(
false
),
response
(
'
enrollmentRate
'
));
module
.
exports
=
EnrollmentRateApp
;
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