From 48a32e6305a3d7b131c708009da13a84e52c12dc Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Wed, 27 Jun 2018 10:46:39 -0300
Subject: [PATCH] Finish transport indicator

---
 src/libs/routes/transport.js | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes/transport.js b/src/libs/routes/transport.js
index 1febdad6..7af1b990 100644
--- a/src/libs/routes/transport.js
+++ b/src/libs/routes/transport.js
@@ -300,13 +300,23 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     allEnrollment.field('COUNT(*)', 'total')
     .field("'Brasil'", 'name')
     .field('matricula.ano_censo', 'year')
+    .from('matricula')
+    .group('matricula.ano_censo')
+    .order('matricula.ano_censo')
+    .where('matricula.tipo <= 3');
+    req.queryIndex.allEnrollment = req.querySet.push(allEnrollment) - 1;
+
+    let allEnrollmentTransport = req.sql.clone()
+    allEnrollmentTransport.field('COUNT(*)', 'total')
+    .field("'Brasil'", 'name')
+    .field('matricula.ano_censo', 'year')
     .field('matricula.transporte_escolar_publico', 'use_transport_id')
     .from('matricula')
     .group('matricula.ano_censo')
     .group('matricula.transporte_escolar_publico')
     .order('matricula.ano_censo')
     .where('matricula.tipo <= 3');
-    req.queryIndex.allEnrollment = req.querySet.push(allEnrollment) - 1;
+    req.queryIndex.allEnrollmentTransport = req.querySet.push(allEnrollmentTransport) - 1;
 
 
     let allTransports = req.sql.clone()
@@ -402,7 +412,10 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     let transport_match = [];
     let transport_match_0 = JSON.parse(JSON.stringify(req.result[req.queryIndex.allTransports]));
     let transport_match_1 = JSON.parse(JSON.stringify(req.result[req.queryIndex.allTransports]));
-    let public_transport = req.result[req.queryIndex.allTransports];
+
+    let all_enrollment_match = [];
+    let all_enrollment_match_0 = JSON.parse(JSON.stringify(req.result[req.queryIndex.allEnrollment]));
+    let all_enrollment_match_1 = JSON.parse(JSON.stringify(req.result[req.queryIndex.allEnrollment]));
 
     //modifica adicionando use_transport_id=false, com os mesmos valores
     //do transport_id=true, usado para dar o match e fazer a divisão.
@@ -413,6 +426,16 @@ transportApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
         transport_match.push(transport_match_1[i])
     }
 
+    //modifica adicionando use_transport_id=false, com os mesmos valores
+    //do transport_id=true, usado para dar o match e fazer a divisão.
+    for (let i = 0; i < all_enrollment_match_0.length; i++) {
+        all_enrollment_match_0[i].use_transport_id = true;
+        all_enrollment_match.push(all_enrollment_match_0[i])
+        all_enrollment_match_1[i].use_transport_id = false;
+        all_enrollment_match.push(all_enrollment_match_1[i])
+    }
+
+    let public_transport = matchQueries(all_enrollment_match, req.result[req.queryIndex.allEnrollmentTransport]);
     let van_and_kombi = matchQueries(transport_match, req.result[req.queryIndex.goVansAndKombi]);
     let micro_bus = matchQueries(transport_match, req.result[req.queryIndex.goMicroBus]);
     let bus = matchQueries(transport_match, req.result[req.queryIndex.goBus]);
-- 
GitLab