Commit 93c5ecd3 authored by Álex Cortiñas's avatar Álex Cortiñas
Browse files

Updating clicked feature data function to support provinces

parent 0ecbe879
......@@ -14,9 +14,9 @@ router.get("/dates", (req, res) => {
flowService.getDates().then((data) => res.json(data));
});
router.get("/cells/:cellCode", (req, res) => {
router.get("/features/:code", (req, res) => {
flowService
.getCellData(req.params.cellCode, req.query)
.getFeatureData(req.params.code, req.query)
.then((data) => res.json(data));
});
......
......@@ -15,15 +15,23 @@ class FlowService {
);
}
getCellData(cellCode, query) {
return this._runSQL(
"select celda as codigo, nombre, poblacion, dia, numero_destinos, " +
"personas_salen, round(((personas_salen/poblacion::float)*100)::numeric, 2) as personas_salen_p, " +
"personas_casa, round(((personas_casa/poblacion::float)*100)::numeric, 2) as personas_casa_p, " +
"numero_origenes, personas_llegan " +
"from poblacion_celda join celda on poblacion_celda.celda = celda.codigo " +
`where celda = '${cellCode}' and dia = '${query.DATE}';`
).then((rows) => rows[0]);
getFeatureData(code, query) {
if (query.TERRITORIAL_UNIT_TYPE == "CELDA")
return this._runSQL(
"select celda as codigo, nombre, poblacion, dia, numero_destinos, " +
"personas_salen, round(((personas_salen/poblacion::float)*100)::numeric, 2) as personas_salen_p, " +
"personas_casa, round(((personas_casa/poblacion::float)*100)::numeric, 2) as personas_casa_p, " +
"numero_origenes, personas_llegan " +
"from poblacion_celda join celda on poblacion_celda.celda = celda.codigo " +
`where celda = '${code}' and dia = '${query.DATE}';`
).then((rows) => rows[0]);
else if (query.TERRITORIAL_UNIT_TYPE == "PROVINCIA")
return this._runSQL(
"select provincia.codigo, provincia.nombre, sum(celda.poblacion) as poblacion " +
"from celda join provincia on celda.provincia = provincia.codigo " +
`where provincia.codigo = '${code}' ` +
"group by provincia.codigo, provincia.nombre;"
).then((rows) => rows[0]);
}
getData(query) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment