Commit 902f7abd28625a2b737c97104c07dbad67109783

Authored by Edmar Moretti
1 parent 5e50a90d

Alteração na função que retorna a lista de indicadores para o catálogo do mapa d…

…a saúde, para melhorar a performance
classesphp/classe_metaestatinfo.php
@@ -1889,16 +1889,25 @@ class MetaestatInfo{ @@ -1889,16 +1889,25 @@ class MetaestatInfo{
1889 else{ 1889 else{
1890 $vs = $this->listaVariavel(); 1890 $vs = $this->listaVariavel();
1891 } 1891 }
  1892 +
  1893 + $lista = $this->listaMedidaVariavel();
  1894 + $lista = array_group_by($lista, "codigo_variavel");
  1895 +
1892 foreach($vs as $v){ 1896 foreach($vs as $v){
1893 $nivel1["id"] = $v["codigo_variavel"]; 1897 $nivel1["id"] = $v["codigo_variavel"];
1894 $nivel1["titulo"] = $v["nome"]; 1898 $nivel1["titulo"] = $v["nome"];
1895 $nivel1["descricao"] = $v["descricao"]; 1899 $nivel1["descricao"] = $v["descricao"];
1896 - $ms = $this->listaMedidaVariavel($v["codigo_variavel"]); 1900 + //$ms = $this->listaMedidaVariavel($v["codigo_variavel"]);
  1901 +
  1902 + $ms = $lista[$v["codigo_variavel"]];
  1903 +
1897 $nivel1["filhos"] = array(); 1904 $nivel1["filhos"] = array();
1898 foreach($ms as $m){ 1905 foreach($ms as $m){
1899 $nivel2["id"] = $m["id_medida_variavel"]; 1906 $nivel2["id"] = $m["id_medida_variavel"];
1900 $nivel2["titulo"] = $m["nomemedida"]; 1907 $nivel2["titulo"] = $m["nomemedida"];
1901 - $unidade = $this->listaUnidadeMedida($m["codigo_unidade_medida"]); 1908 + //$unidade = $this->listaUnidadeMedida($m["codigo_unidade_medida"]);
  1909 +
  1910 + $unidade = $lista[$m["codigo_unidade_medida"]];
1902 $unidade = "Unidade de medida: ".$unidade["nome"]; 1911 $unidade = "Unidade de medida: ".$unidade["nome"];
1903 $periodo = $this->listaTipoPeriodo($m["codigo_tipo_periodo"]); 1912 $periodo = $this->listaTipoPeriodo($m["codigo_tipo_periodo"]);
1904 $periodo = "Período de tempo: ".$periodo["nome"]; 1913 $periodo = "Período de tempo: ".$periodo["nome"];
classesphp/classe_temas.php
@@ -959,18 +959,22 @@ $wkt - boolean indicando se $xy e um WKT @@ -959,18 +959,22 @@ $wkt - boolean indicando se $xy e um WKT
959 } 959 }
960 960
961 $pinlayer->addfeature($shp); 961 $pinlayer->addfeature($shp);
962 - if($nomeTema != ""){  
963 - $pinlayer->setmetadata("tema",$nomeTema);  
964 - } 962 +
965 //verifica a projecao 963 //verifica a projecao
966 $c = $shp->getCentroid(); 964 $c = $shp->getCentroid();
967 - $c = $c->x;  
968 - if($c > -181 && $c < 181){ 965 + if($c->x > -181 && $c->x < 181){
969 $pinlayer->setprojection(pegaProjecaoDefault("proj4")); 966 $pinlayer->setprojection(pegaProjecaoDefault("proj4"));
  967 + $extensao = ($c->x - 0.01)." ".($c->y - 0.01)." ".($c->x + 0.01)." ".($c->y + 0.01);
970 } 968 }
971 else{ 969 else{
972 $pinlayer->setprojection($this->mapa->getProjection()); 970 $pinlayer->setprojection($this->mapa->getProjection());
  971 + $extensao = ($c->x - 50000)." ".($c->y - 50000)." ".($c->x + 50000)." ".($c->y + 50000);
973 } 972 }
  973 + $pinlayer->setmetadata("extensao",$extensao);
  974 + if($nomeTema != ""){
  975 + $pinlayer->setmetadata("tema",$nomeTema);
  976 + }
  977 +
974 return("ok"); 978 return("ok");
975 } 979 }
976 /* 980 /*
classesphp/funcoes_gerais.php
@@ -3556,4 +3556,70 @@ function pegaDadosAdmin($sql,$dbh=&quot;&quot;){ @@ -3556,4 +3556,70 @@ function pegaDadosAdmin($sql,$dbh=&quot;&quot;){
3556 throw new Exception("pegaDadosAdmin"); 3556 throw new Exception("pegaDadosAdmin");
3557 } 3557 }
3558 } 3558 }
  3559 +/**
  3560 + * Groups an array by a given key.
  3561 + *
  3562 + * Groups an array into arrays by a given key, or set of keys, shared between all array members.
  3563 + *
  3564 + * Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function.
  3565 + * This variant allows $key to be closures.
  3566 + *
  3567 + * @param array $array The array to have grouping performed on.
  3568 + * @param mixed $key,... The key to group or split by. Can be a _string_,
  3569 + * an _integer_, a _float_, or a _callable_.
  3570 + *
  3571 + * If the key is a callback, it must return
  3572 + * a valid key from the array.
  3573 + *
  3574 + * If the key is _NULL_, the iterated element is skipped.
  3575 + *
  3576 + * ```
  3577 + * string|int callback ( mixed $item )
  3578 + * ```
  3579 + *
  3580 + * @return array|null Returns a multidimensional array or `null` if `$key` is invalid.
  3581 + */
  3582 +function array_group_by(array $array, $key)
  3583 +{
  3584 + if (!is_string($key) && !is_int($key) && !is_float($key) && !is_callable($key) ) {
  3585 + //trigger_error('array_group_by(): The key should be a string, an integer, or a callback', E_USER_ERROR);
  3586 + return null;
  3587 + }
  3588 +
  3589 + $func = (!is_string($key) && is_callable($key) ? $key : null);
  3590 + $_key = $key;
  3591 +
  3592 + // Load the new array, splitting by the target key
  3593 + $grouped = [];
  3594 + foreach ($array as $value) {
  3595 + $key = null;
  3596 +
  3597 + if (is_callable($func)) {
  3598 + $key = call_user_func($func, $value);
  3599 + } elseif (is_object($value) && isset($value->{$_key})) {
  3600 + $key = $value->{$_key};
  3601 + } elseif (isset($value[$_key])) {
  3602 + $key = $value[$_key];
  3603 + }
  3604 +
  3605 + if ($key === null) {
  3606 + continue;
  3607 + }
  3608 +
  3609 + $grouped[$key][] = $value;
  3610 + }
  3611 +
  3612 + // Recursively build a nested grouping if more parameters are supplied
  3613 + // Each grouped array value is grouped according to the next sequential key
  3614 + if (func_num_args() > 2) {
  3615 + $args = func_get_args();
  3616 +
  3617 + foreach ($grouped as $key => $value) {
  3618 + $params = array_merge([ $value ], array_slice($args, 2, func_num_args()));
  3619 + $grouped[$key] = call_user_func_array('array_group_by', $params);
  3620 + }
  3621 + }
  3622 +
  3623 + return $grouped;
  3624 +}
3559 ?> 3625 ?>
classesphp/metaestat_controle.php
@@ -38,6 +38,22 @@ switch (strtoupper($funcao)) { @@ -38,6 +38,22 @@ switch (strtoupper($funcao)) {
38 $layers = explode(",", $_pg["layers"]); 38 $layers = explode(",", $_pg["layers"]);
39 $map = ms_newMapObj($map_file); 39 $map = ms_newMapObj($map_file);
40 break; 40 break;
  41 + case "LISTACOMPLETA":
  42 + $arq = $dir_tmp."/listaDeVariaveis.json";
  43 + if (file_exists($arq)){
  44 + $dados = unserialize(file_get_contents($arq));
  45 + retornaJSON($dados);
  46 + exit;
  47 + }
  48 + $m = new MetaestatInfo();
  49 + $dados = $m->relatorioCompleto();
  50 + if(empty($_pg["cache"]) || $_pg["cache"] == "false" || $_pg["cache"] == false){
  51 + if (!file_exists($arq)){
  52 + gravaDados([serialize($dados)], $arq);
  53 + }
  54 + }
  55 + retornaJSON($dados);
  56 + break;
41 case "RELATORIOCOMPLETO": 57 case "RELATORIOCOMPLETO":
42 $m = new MetaestatInfo(); 58 $m = new MetaestatInfo();
43 if (empty($_pg["codigo_variavel"])) { 59 if (empty($_pg["codigo_variavel"])) {