Skip to content
Snippets Groups Projects
Commit 974d1c9e authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'release_v1.9.0'

Merges !164
parents 858a0048 84d2106d
Branches
Tags v1.9.0
2 merge requests!219Documentation,!218Mapas
Pipeline #19377 failed
...@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. ...@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## 1.9.0 - 2018-11-24
## Changed
- Fix school infrastructure results when partial or needed schools query return empty
- Block 2 or more dimensions in daily_charge_amount/average
## 1.8.3 - 2018-11-24 ## 1.8.3 - 2018-11-24
### Changed ### Changed
- Fixed reulst return in classroom count - Fixed reulst return in classroom count
......
...@@ -6,6 +6,7 @@ const db = require(`${libs}/db/query_exec`); ...@@ -6,6 +6,7 @@ const db = require(`${libs}/db/query_exec`);
function query(req, res, next) { function query(req, res, next) {
let sql = req.sql.toParam(); let sql = req.sql.toParam();
log.info(`Executando query ${req.sql.toString()}`); log.info(`Executando query ${req.sql.toString()}`);
sql.text = sql.text.replace(/`/g, "");
execute(sql.text, sql.values, (err, result) => { execute(sql.text, sql.values, (err, result) => {
if(err) { if(err) {
log.error(err.stack); log.error(err.stack);
......
...@@ -284,6 +284,7 @@ rqf.addField({ ...@@ -284,6 +284,7 @@ rqf.addField({
table: 'turma', table: 'turma',
tableField: 'etapas_mod_ensino_segmento_id', tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_mod_id', resultField: 'education_level_mod_id',
dontGroup: true,
where: { where: {
relation: '=', relation: '=',
type: 'integer', type: 'integer',
...@@ -380,7 +381,7 @@ dailyChargeAmountApp.get('/', rqf.parse(), (req, res, next) => { ...@@ -380,7 +381,7 @@ dailyChargeAmountApp.get('/', rqf.parse(), (req, res, next) => {
next(); next();
}, id2str.transform(), response('turma')); }, id2str.transform(), response('turma'));
dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => { dailyChargeAmountApp.get('/average', rqf.parse(), rqf.build(), (req, res, next) => {
var status = 0; var status = 0;
if (('education_level_mod' in req.filter || 'education_level_mod' in req.dims) if (('education_level_mod' in req.filter || 'education_level_mod' in req.dims)
&& ('integral_time' in req.filter)) { && ('integral_time' in req.filter)) {
...@@ -401,11 +402,34 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => { ...@@ -401,11 +402,34 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => {
} }
if (status) { if (status) {
req.sql.from('turma') let baseQ = req.sql.clone();
let tableR = baseQ.clone();
tableR.from('turma')
.field('duracao_turma')
.field('ROW_NUMBER() OVER(PARTITION BY etapas_mod_ensino_segmento_id ORDER BY duracao_turma)', 'rowno')
.where('tipo_turma_id <= 3')
let tableG = baseQ.clone();
tableG.from('turma')
.field('1+COUNT(*)', 'counter')
.where('tipo_turma_id <= 3')
.group('etapas_mod_ensino_segmento_id')
let joinRG = squel.select();
joinRG.from(tableR, 'R')
.field('R.education_level_mod_id')
.field('AVG(1.0*R.duracao_turma)/60', 'median_value')
.join(tableG, 'G', 'R.education_level_mod_id = G.education_level_mod_id AND R.rowNo BETWEEN G.counter/2 AND G.counter/2+G.counter%2')
.group('R.education_level_mod_id')
req.sql
.from('turma')
.from(joinRG, 'm')
.field('turma.ano_censo', 'year') .field('turma.ano_censo', 'year')
.field('turma.etapas_mod_ensino_segmento_id', 'education_level_mod_id') .field('turma.etapas_mod_ensino_segmento_id', 'education_level_mod_id')
.field('AVG(turma.duracao_turma)/60.0', 'average_class_duration') .field('AVG(turma.duracao_turma)/60.0', 'average_class_duration')
.field('MEDIAN(turma.duracao_turma)/60.0', 'median_class_duration') .field('AVG(m.median_value)', 'median_class_duration')
.field('STDDEV_SAMP(turma.duracao_turma)/60.0', 'std_class_duration') .field('STDDEV_SAMP(turma.duracao_turma)/60.0', 'std_class_duration')
.field('QUANTILE(turma.duracao_turma, 0.25)/60.0', 'fstqt_class_duration') .field('QUANTILE(turma.duracao_turma, 0.25)/60.0', 'fstqt_class_duration')
.field('QUANTILE(turma.duracao_turma, 0.75)/60.0', 'thdqt_class_duration') .field('QUANTILE(turma.duracao_turma, 0.75)/60.0', 'thdqt_class_duration')
...@@ -413,7 +437,7 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => { ...@@ -413,7 +437,7 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => {
.group('turma.etapas_mod_ensino_segmento_id') .group('turma.etapas_mod_ensino_segmento_id')
.order('turma.ano_censo') .order('turma.ano_censo')
.order('turma.etapas_mod_ensino_segmento_id') .order('turma.etapas_mod_ensino_segmento_id')
.where('turma.tipo_turma_id <= 3') .where('turma.tipo_turma_id <= 3 and m.education_level_mod_id = turma.etapas_mod_ensino_segmento_id')
} else { } else {
res.status(400); res.status(400);
next({ next({
...@@ -423,6 +447,6 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => { ...@@ -423,6 +447,6 @@ dailyChargeAmountApp.get('/average', rqf.parse(), (req, res, next) => {
} }
next(); next();
}, rqf.build(), query, addMissing(rqf), id2str.transform(), response('turma')); }, query, addMissing(rqf), id2str.transform(), response('turma'));
module.exports = dailyChargeAmountApp; module.exports = dailyChargeAmountApp;
...@@ -259,6 +259,11 @@ function matchQueries(queryTotal, queryPartial, queryNeeded, zeroPercentage=fals ...@@ -259,6 +259,11 @@ function matchQueries(queryTotal, queryPartial, queryNeeded, zeroPercentage=fals
} }
} }
if(queryPartial.length == 0) {
partialMatch = JSON.parse(JSON.stringify(result));
partialMatch.total = 0;
}
for(let i = 0; i < queryNeeded.length; ++i) { for(let i = 0; i < queryNeeded.length; ++i) {
let needed = queryNeeded[i]; let needed = queryNeeded[i];
let foundMatch = true; let foundMatch = true;
...@@ -275,6 +280,11 @@ function matchQueries(queryTotal, queryPartial, queryNeeded, zeroPercentage=fals ...@@ -275,6 +280,11 @@ function matchQueries(queryTotal, queryPartial, queryNeeded, zeroPercentage=fals
} }
} }
if(queryNeeded.length == 0) {
needMatch = JSON.parse(JSON.stringify(result));
needMatch.total = 0;
}
if(partialMatch && needMatch) { if(partialMatch && needMatch) {
newObj.percentage = (partialMatch.total / result.total) * 100; newObj.percentage = (partialMatch.total / result.total) * 100;
if(zeroPercentage) newObj.percentage = 0; if(zeroPercentage) newObj.percentage = 0;
...@@ -340,11 +350,11 @@ infrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -340,11 +350,11 @@ infrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.queryIndex.allLibrariesReadingRoom = req.queryIndex.allCountrySchools; req.queryIndex.allLibrariesReadingRoom = req.queryIndex.allCountrySchools;
let haveLibrariesReadingRoom = allCountrySchools.clone(); let haveLibrariesReadingRoom = allCountrySchools.clone();
haveLibrariesReadingRoom.where('escola.biblioteca_sala_leitura = 1'); haveLibrariesReadingRoom.where('escola.biblioteca_sala_leitura = true');
req.queryIndex.haveLibrariesReadingRoom = req.querySet.push(haveLibrariesReadingRoom) - 1; req.queryIndex.haveLibrariesReadingRoom = req.querySet.push(haveLibrariesReadingRoom) - 1;
let needLibrariesReadingRoom = allCountrySchools.clone(); let needLibrariesReadingRoom = allCountrySchools.clone();
needLibrariesReadingRoom.where('escola.biblioteca_sala_leitura = 0'); needLibrariesReadingRoom.where('escola.biblioteca_sala_leitura = false');
req.queryIndex.needLibrariesReadingRoom = req.querySet.push(needLibrariesReadingRoom) - 1; req.queryIndex.needLibrariesReadingRoom = req.querySet.push(needLibrariesReadingRoom) - 1;
// Laboratório de informática // Laboratório de informática
...@@ -366,11 +376,11 @@ infrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -366,11 +376,11 @@ infrastructureApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.queryIndex.allScienceLab = req.querySet.push(allScienceLab) - 1; req.queryIndex.allScienceLab = req.querySet.push(allScienceLab) - 1;
let haveScienceLab = allScienceLab.clone(); let haveScienceLab = allScienceLab.clone();
haveScienceLab.where('escola.lab_ciencias = 1'); haveScienceLab.where('escola.lab_ciencias = true');
req.queryIndex.haveScienceLab = req.querySet.push(haveScienceLab) - 1; req.queryIndex.haveScienceLab = req.querySet.push(haveScienceLab) - 1;
let needScienceLab = allScienceLab.clone(); let needScienceLab = allScienceLab.clone();
needScienceLab.where('escola.lab_ciencias = 0'); needScienceLab.where('escola.lab_ciencias = false');
req.queryIndex.needScienceLab = req.querySet.push(needScienceLab) - 1; req.queryIndex.needScienceLab = req.querySet.push(needScienceLab) - 1;
// Parque infantil // Parque infantil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment