Skip to content
Snippets Groups Projects
Commit 974c6376 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Add filters

parent 30eaaaa4
No related branches found
No related tags found
1 merge request!128Transport Indicator
Pipeline #
...@@ -81,27 +81,162 @@ transportApp.get('/rural_location', (req, res, next) => { ...@@ -81,27 +81,162 @@ transportApp.get('/rural_location', (req, res, next) => {
next(); next();
}, response('rural_location')); }, response('rural_location'));
transportApp.get('/education_level_mod', (req, res, next) => { transportApp.get('/education_level_basic', (req, res, next) => {
req.result = []; req.result = [
for(let i = 1; i <= 10; ++i) { {id: null, name: 'Não classificada'},
req.result.push({ {id: 1, name: 'Creche'},
id: i, {id: 2, name: 'Pré-Escola'},
name: id2str.educationLevelMod(i) {id: 4, name: 'Ensino Fundamental - anos iniciais'},
}); {id: 5, name: 'Ensino Fundamental - anos finais'},
{id: 6, name: 'Ensino Médio'}
];
next();
}, response('education_level_basic'));
transportApp.get('/transportation_manager', (req, res, next) => {
req.result = [
{id: null, name: 'Não classificada'},
{id: 1, name: 'Estadual'},
{id: 2, name: 'Municipal'},
];
next();
}, response('transportation_manager'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'rural_location',
table: 'matricula',
tableField: 'localidade_area_rural',
resultField: 'rural_location_id',
where: {
relation: '=',
type: 'integer',
field: 'localidade_area_rural'
} }
req.result.push({ }).addValue({
id: 99, name: 'location',
name: id2str.educationLevelMod(99) table: 'matricula',
tableField: 'localizacao_id',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_id'
}
}).addValue({
name:'adm_dependency',
table: 'matricula',
tableField: 'dependencia_adm_id',
resultField: 'adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_id'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'matricula',
tableField: 'dependencia_adm_priv',
resultField: 'adm_dependency_detailed_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_priv'
}
}).addValue({
name: 'transportation_manager',
table: 'matricula',
tableField: 'responsavel_transp',
resultField: 'transportation_manager',
where: {
relation: '=',
type: 'integer',
field: 'responsavel_transp'
}
}).addValue({
name: 'education_level_basic',
table: 'matricula',
tableField: 'etapas_mod_ensino_segmento_id',
resultField: 'education_level_basic_id',
where: {
relation: '=',
type: 'integer',
field: 'etapas_mod_ensino_segmento_id'
}
}).addValue({
name: 'min_year',
table: 'matricula',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'matricula',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
});
function matchQueries(queryTotal, queryPartial) {
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.percentage = (objMatch.total / result.total) * 100;
newObj.partial = objMatch.total;
newObj.total = result.total
match.push(newObj);
}
}); });
next();
}, response('education_level_mod')); return match;
}
transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.querySet = []; req.querySet = [];
req.queryIndex = {}; req.queryIndex = {};
let allTransports = req.sql.clone() let allTransports = req.sql.clone()
.field('COUNT(matricula.id)', 'total') allTransports.field('COUNT(*)', 'total')
.field("'Brasil'", 'name') .field("'Brasil'", 'name')
.field('matricula.ano_censo', 'year') .field('matricula.ano_censo', 'year')
.from('matricula') .from('matricula')
...@@ -111,67 +246,109 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -111,67 +246,109 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.where('turma.tipo_turma_id <= 3'); .where('turma.tipo_turma_id <= 3');
req.queryIndex.allTransports = req.querySet.push(allTransports) - 1; req.queryIndex.allTransports = req.querySet.push(allTransports) - 1;
// Vans e Kombi // Vans e Kombi
let allVansAndKombi = allTransports.clone(); let allVansAndKombi = allTransports.clone();
allVansAndKombi.where('matricula.transporte_vans_kombi = 1'); allVansAndKombi.where('matricula.transporte_vans_kombi = 1');
req.queryIndex.allVansAndKombi = req.querySet.push(allTransports) - 1; req.queryIndex.allVansAndKombi = req.querySet.push(allVansAndKombi) - 1;
// // Micro-ônibus // Vans e Kombi
// let allMicroBus = allTransports.clone(); let goVansAndKombi = allTransports.clone();
// allMicroBus.where('matricula.transporte_micro_onibus = 1'); goVansAndKombi.where('matricula.transporte_vans_kombi = 1 OR matricula.transporte_vans_kombi = 0');
// req.queryIndex.allMicroBus = req.querySet.push(allTransports) - 1; req.queryIndex.goVansAndKombi = req.querySet.push(goVansAndKombi) - 1;
//
// // Ônibus // Micro-ônibus
// let allBus = allTransports.clone(); let allMicroBus = allTransports.clone();
// allBus.where('matricula.transporte_onibus = 1'); allMicroBus.where('matricula.transporte_micro_onibus = 1 OR matricula.transporte_micro_onibus = 0');
// req.queryIndex.allBus = req.querySet.push(allTransports) - 1; req.queryIndex.allMicroBus = req.querySet.push(allMicroBus) - 1;
//
// // Bicicleta // Micro
// let allBikes = allTransports.clone(); let goMicroBus = allTransports.clone();
// allBikes.where('matricula.transporte_bicicleta = 1'); goMicroBus.where('matricula.transporte_micro_onibus = 1');
// req.queryIndex.allBikes = req.querySet.push(allTransports) - 1; req.queryIndex.goMicroBus = req.querySet.push(goMicroBus) - 1;
//
// // Tração Animal // Ônibus
// let allAnimalTraction = allTransports.clone(); let allBus = allTransports.clone();
// allAnimalTraction.where('matricula.transporte_animal = 1'); allBus.where('matricula.transporte_onibus = 1 OR matricula.transporte_onibus = 0');
// req.queryIndex.allAnimalTraction = req.querySet.push(allTransports) - 1; req.queryIndex.allBus = req.querySet.push(allBus) - 1;
//
// // Outro Veículo let goBus = allTransports.clone();
// let allOtherVehicle = allTransports.clone(); goBus.where('matricula.transporte_onibus = 1');
// allOtherVehicle.where('matricula.transporte_outro = 1'); req.queryIndex.goBus = req.querySet.push(goBus) - 1;
// req.queryIndex.allOtherVehicle = req.querySet.push(allTransports) - 1;
//
// // Aquaviário/ Embarcação (capacidade até 5 alunos)
// let allWaterway_5_Students = allTransports.clone();
// allWaterway_5_Students.where('matricula.transporte_embar_0_5 = 1');
// req.queryIndex.allWaterway_5_Students = req.querySet.push(allTransports) - 1;
//
// // Aquaviário/ Embarcação (capacidade de 5 até 15 alunos)
// let allWaterway_15_Students = allTransports.clone();
// allWaterway_15_Students.where('matricula.transporte_embar_5_15 = 1');
// req.queryIndex.allWaterway_15_Students = req.querySet.push(allTransports) - 1;
//
// // Aquaviário/ Embarcação (capacidade de 15 até 35 alunos)
// let allWaterway_35_Students = allTransports.clone();
// allWaterway_35_Students.where('matricula.transporte_embar_15_35 = 1');
// req.queryIndex.allWaterway_35_Students = req.querySet.push(allTransports) - 1;
//
// // Aquaviário/ Embarcação (capacidade mais 35 alunos)
// let allWaterwayMoreThan_35 = allTransports.clone();
// allWaterwayMoreThan_35.where('matricula.transporte_embar_35 = 1');
// req.queryIndex.allWaterwayMoreThan_35 = req.querySet.push(allTransports) - 1;
// //
// // Trêm / Metrô // Bicicleta
// let allSubwayAndTrain = allTransports.clone(); let goBikes = allTransports.clone();
// allSubwayAndTrain.where('matricula.transporte_trem_metro = 1'); goBikes.where('matricula.transporte_bicicleta = 1');
// req.queryIndex.allSubwayAndTrain = req.querySet.push(allTransports) - 1; req.queryIndex.goBikes = req.querySet.push(goBikes) - 1;
// Tração Animal
let goAnimalTraction = allTransports.clone();
goAnimalTraction.where('matricula.transporte_animal = 1');
req.queryIndex.goAnimalTraction = req.querySet.push(goAnimalTraction) - 1;
// Outro Veículo
let goOtherVehicle = allTransports.clone();
goOtherVehicle.where('matricula.transporte_outro = 1');
req.queryIndex.goOtherVehicle = req.querySet.push(goOtherVehicle) - 1;
// Aquaviário/ Embarcação (capacidade até 5 alunos)
let goWaterway_5_Students = allTransports.clone();
goWaterway_5_Students.where('matricula.transporte_embar_0_5 = 1');
req.queryIndex.goWaterway_5_Students = req.querySet.push(goWaterway_5_Students) - 1;
// Aquaviário/ Embarcação (capacidade de 5 até 15 alunos)
let goWaterway_15_Students = allTransports.clone();
goWaterway_15_Students.where('matricula.transporte_embar_5_15 = 1');
req.queryIndex.goWaterway_15_Students = req.querySet.push(goWaterway_15_Students) - 1;
// Aquaviário/ Embarcação (capacidade de 15 até 35 alunos)r
let goWaterway_35_Students = allTransports.clone();
goWaterway_35_Students.where('matricula.transporte_embar_15_35 = 1');
req.queryIndex.goWaterway_35_Students = req.querySet.push(goWaterway_35_Students) - 1;
// Aquaviário/ Embarcação (capacidade mais 35 alunos)
let goWaterwayMoreThan_35 = allTransports.clone();
goWaterwayMoreThan_35.where('matricula.transporte_embar_35 = 1');
req.queryIndex.goWaterwayMoreThan_35 = req.querySet.push(goWaterwayMoreThan_35) - 1;
// Trêm / Metrô
let goSubwayAndTrain = allTransports.clone();
goSubwayAndTrain.where('matricula.transporte_trem_metro = 1');
req.queryIndex.goSubwayAndTrain = req.querySet.push(goSubwayAndTrain) - 1;
next(); next();
}, multiQuery, (req, res, next) => { }, multiQuery, (req, res, next) => {
// let van_and_kombi = matchQueries(req.result[req.queryIndex.goVansAndKombi], req.result[req.queryIndex.allVansAndKombi]);
// let microBus = matchQueries(req.result[req.queryIndex.goMicroBus], req.result[req.queryIndex.allMicroBus]);
// let Bus = matchQueries(req.result[req.queryIndex.goBus], req.result[req.queryIndex.allBus]);
let van_and_kombi = req.result[req.queryIndex.goVansAndKombi]
let micro_bus = req.result[req.queryIndex.goMicroBus]
let Bus = req.result[req.queryIndex.goBus]
let bike = req.result[req.queryIndex.goBikes]
let animal_traction = req.result[req.queryIndex.goAnimalTraction]
let other_vehicle = req.result[req.queryIndex.goOtherVehicle]
let waterway_5_Students = req.result[req.queryIndex.goWaterway_5_Students]
let waterway_10_Students = req.result[req.queryIndex.goWaterway_10_Students]
let waterway_15_Students = req.result[req.queryIndex.goWaterway_15_Students]
let waterway_35_Students = req.result[req.queryIndex.goWaterway_35_Students]
let waterway_More_Than_35 = req.result[req.queryIndex.goWaterwayMoreThan_35]
let subway_and_train = req.result[req.queryIndex.goSubwayAndTrain]
req.result = [{
van_and_kombi,
micro_bus,
Bus,
bike,
animal_traction,
other_vehicle,
waterway_5_Students,
waterway_10_Students,
waterway_15_Students,
waterway_35_Students,
waterway_More_Than_35,
subway_and_train
// console.log(req.result[req.queryIndex.allVansAndKombi]); }]
req.result = []; next();
next();
}, response('transports')); }, response('transports'));
module.exports = transportApp; module.exports = transportApp;
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