Commit 24e4570b9b8e2916af071af2b7e2601376a007e9

Authored by Edmar Moretti
1 parent 33a2c559

Novo método de classificação baseado na metade dos valores

classesphp/classe_alteraclasse.php
... ... @@ -319,6 +319,109 @@ class Alteraclasse
319 319 {return ("erro. Nenhum valor numerico no item");
320 320 }
321 321 }
  322 + /*
  323 + function: metade
  324 +
  325 + Classifica os dados em duas classes, a primeira concentra os registros que somados correspondem à primeira metade do total e a segunda classe corresponde à segunda metade
  326 +
  327 + Parametros:
  328 +
  329 + $item - item da tabela de atributos
  330 +
  331 + $itemid - item que identifica unicamente cada registro
  332 +
  333 + $ignorar - valor que será ignorado na listagem final
  334 + */
  335 + function metade($item,$itemid,$ignorar)
  336 + {
  337 + if(!$this->layer){
  338 + return "erro";
  339 + }
  340 + //cria um array contendo o id como chave e o valor
  341 + $valores = $this->pegaValores($this->mapa,$this->layer,$item,true,$ignorar);
  342 + $ids = $this->pegaValores($this->mapa,$this->layer,$itemid,false,$ignorar);
  343 + $lista = array();
  344 + for ($i = 0; $i < count($valores); ++$i){
  345 + $lista[$ids[$i]] = $valores[$i];
  346 + }
  347 +
  348 + if (count($lista) > 0){
  349 + asort($lista);
  350 + //$valores = array_unique($valores);
  351 + $numValues = count($lista);
  352 + //soma os valores
  353 + $total = array_sum($lista);
  354 + //metade
  355 + $metade = $total / 2;
  356 + //separa os dados em dois conjuntos
  357 + $metadeInf = array();
  358 + $metadeSup = array();
  359 + $IdNumerico = true;
  360 + $soma = 0;
  361 + $somaInf = 0;
  362 + $somaSup = 0;
  363 + $maxMetade1 = 0;
  364 + foreach ($lista as $k => $v) {
  365 + $soma = $soma + $v;
  366 + if($soma < $metade){
  367 + $metadeInf[] = $k;
  368 + $somaInf = $soma;
  369 + $maxMetade1 = $v;
  370 + }
  371 + else{
  372 + $metadeSup[] = $k;
  373 + $somaSup = $somaSup + $v;
  374 + }
  375 + }
  376 + $percInf = ($somaInf * 100) / $total;
  377 + $percSup = ($somaSup * 100) / $total;
  378 +
  379 + $numclassesatual = $this->layer->numclasses;
  380 + //apaga todas as classes existentes
  381 + $classetemp = $this->layer->getClass(0);
  382 + $estilotemp = $classetemp->getStyle(0);
  383 + for ($i=0; $i < $numclassesatual; ++$i){
  384 + $classe = $this->layer->getClass($i);
  385 + $classe->set("status",MS_DELETE);
  386 + }
  387 + //adiciona as classes novas
  388 + $expressao = "('[".$itemid."]'in'".implode(",",$metadeInf)."')";
  389 + $nomeclasse = "Tot ".$somaInf.' ('.round($percInf,2).'%) Max: '.$maxMetade1;
  390 + $classe = ms_newClassObj($this->layer);
  391 + $novoestilo = ms_newStyleObj($classe);
  392 + if ($this->layer->type == 0){
  393 + $novoestilo->set("symbolname","ponto");
  394 + $novoestilo->set("size","6");
  395 + }
  396 + $ncor = $novoestilo->color;
  397 + $ncor->setrgb(246,183,134);
  398 + $ncor = $novoestilo->outlinecolor;
  399 + $ncor->setrgb(255,255,255);
  400 + $classe->setexpression($expressao);
  401 + $classe->set("name",$nomeclasse);
  402 +
  403 + $expressao = "('[".$itemid."]'in'".implode(",",$metadeSup)."')";
  404 + $nomeclasse = "Tot ".$somaSup.' ('.round($percSup,2).'%) ';
  405 + $classe = ms_newClassObj($this->layer);
  406 + $novoestilo = ms_newStyleObj($classe);
  407 + if ($this->layer->type == 0){
  408 + $novoestilo->set("symbolname","ponto");
  409 + $novoestilo->set("size","6");
  410 + }
  411 + $ncor = $novoestilo->color;
  412 + $ncor->setrgb(210,111,111);
  413 + $ncor = $novoestilo->outlinecolor;
  414 + $ncor->setrgb(255,255,255);
  415 + $classe->setexpression($expressao);
  416 + $classe->set("name",$nomeclasse);
  417 +
  418 + $this->layer->setMetaData("cache","");
  419 + return ("ok");
  420 + }
  421 + else{
  422 + return ("erro. Nenhum valor numerico no item");
  423 + }
  424 + }
322 425 /*
323 426 function: quantil
324 427  
... ...
classesphp/mapa_controle.php
... ... @@ -1215,6 +1215,9 @@ switch (strtoupper($funcao))
1215 1215 if ($opcao == "quebrasnaturais"){
1216 1216 $retorno = $m->quebrasnaturais($item,$nclasses,$ignorar);
1217 1217 }
  1218 + if ($opcao == "metade"){
  1219 + $retorno = $m->metade($item,$itemid,$ignorar);
  1220 + }
1218 1221 if ($opcao == "quartis"){
1219 1222 if(!isset($tipoLegenda))
1220 1223 {
... ...
ferramentas/legenda/dicionario.js
... ... @@ -758,5 +758,26 @@ i3GEOF.legenda.dicionario =
758 758 en : "",
759 759 es : ""
760 760 }
761   - ]
  761 + ],
  762 + "metade" : [
  763 + {
  764 + pt : "Metade",
  765 + en : "",
  766 + es : ""
  767 + }
  768 + ],
  769 + "duasmetades" : [
  770 + {
  771 + pt : "Classifica os dados em duas classes, a primeira concentra os registros que somados correspondem &agrave; primeira metade do total e a segunda classe corresponde &agrave; segunda metade",
  772 + en : "",
  773 + es : ""
  774 + }
  775 + ],
  776 + "iunico" : [
  777 + {
  778 + pt : "Coluna que identifica cada registro de forma &uacute;nica",
  779 + en : "",
  780 + es : ""
  781 + }
  782 + ]
762 783 };
... ...
ferramentas/legenda/index.js
... ... @@ -208,6 +208,12 @@ i3GEOF.legenda =
208 208 }
209 209 });
210 210 b.addClass("rodar");
  211 + b = new YAHOO.widget.Button("i3GEOlegendabotaoMetade", {
  212 + onclick : {
  213 + fn : i3GEOF.legenda.metade
  214 + }
  215 + });
  216 + b.addClass("rodar");
211 217 b = new YAHOO.widget.Button("i3GEOlegendabotao7", {
212 218 onclick : {
213 219 fn : i3GEOF.legenda.representacao
... ... @@ -346,6 +352,12 @@ i3GEOF.legenda =
346 352 if ($i("i3GEOlegendaClassesValorUnico")) {
347 353 $i("i3GEOlegendaClassesValorUnico").innerHTML = retorno.dados;
348 354 }
  355 + if ($i("i3GEOlegendaitensMetade")) {
  356 + $i("i3GEOlegendaitensMetade").innerHTML = retorno.dados;
  357 + }
  358 + if ($i("i3GEOlegendaitensMetadeId")) {
  359 + $i("i3GEOlegendaitensMetadeId").innerHTML = retorno.dados;
  360 + }
349 361 if ($i("i3GEOlegendaitensValorClass")) {
350 362 $i("i3GEOlegendaitensValorClass").innerHTML = retorno.dados;
351 363 }
... ... @@ -1297,6 +1309,67 @@ i3GEOF.legenda =
1297 1309 i3GEO.janela.tempoMsg("Selecione um item!");
1298 1310 return;
1299 1311 }
  1312 + if ($i("i3GEOFlegendaaplicaextent").checked === true) {
  1313 + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten);
  1314 + } else {
  1315 + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.extentTotal);
  1316 + }
  1317 + i3GEOF.legenda.aguarde.visibility = "visible";
  1318 + cp.set_response_type("JSON");
  1319 + cp.call(p, "alteraclasse", fim);
  1320 + } catch (e) {
  1321 + i3GEO.janela.tempoMsg("Erro: " + e);
  1322 + i3GEOF.legenda.aguarde.visibility = "hidden";
  1323 + }
  1324 + },
  1325 + /*
  1326 + * Function: metade
  1327 + *
  1328 + * Duas classes concentrando a soma das metades
  1329 + *
  1330 + * Veja:
  1331 + *
  1332 + * <ALTERACLASSE>
  1333 + */
  1334 + metade : function() {
  1335 + try {
  1336 + if (i3GEOF.legenda.aguarde.visibility === "visible") {
  1337 + return;
  1338 + }
  1339 + var item = $i("i3GEOlegendaitensMetade").getElementsByTagName("select")[0].value,
  1340 + itemid = $i("i3GEOlegendaitensMetadeId").getElementsByTagName("select")[0].value,
  1341 + ext = i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten),
  1342 + p = i3GEO.configura.locaplic + "/classesphp/mapa_controle.php?g_sid="
  1343 + + i3GEO.configura.sid
  1344 + + "&funcao=alteraclasse"
  1345 + + "&tema="
  1346 + + i3GEOF.legenda.tema
  1347 + + "&item="
  1348 + + item
  1349 + + "&itemid="
  1350 + + itemid
  1351 + + "&opcao=metade&ignorar="
  1352 + + $i("i3GEOlegendaignorar").value
  1353 + + "&ext="
  1354 + + ext,
  1355 + cp = new cpaint(),
  1356 + fim = function() {
  1357 + i3GEOF.legenda.aposAlterarLegenda();
  1358 + i3GEOF.legenda.aguarde.visibility = "hidden";
  1359 + };
  1360 + if (item == "") {
  1361 + i3GEO.janela.tempoMsg("Selecione um item!");
  1362 + return;
  1363 + }
  1364 + if (itemid == "") {
  1365 + i3GEO.janela.tempoMsg("Selecione um item!");
  1366 + return;
  1367 + }
  1368 + if ($i("i3GEOFlegendaaplicaextent").checked === true) {
  1369 + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.mapexten);
  1370 + } else {
  1371 + p += "&ext=" + i3GEO.util.extOSM2Geo(i3GEO.parametros.extentTotal);
  1372 + }
1300 1373 i3GEOF.legenda.aguarde.visibility = "visible";
1301 1374 cp.set_response_type("JSON");
1302 1375 cp.call(p, "alteraclasse", fim);
... ...
ferramentas/legenda/template_mst.html
... ... @@ -187,6 +187,19 @@
187 187 </fieldset>
188 188 <br>
189 189 <fieldset style='padding: 5px; margin: 2px;'>
  190 + <legend>{{{metade}}}</legend>
  191 + <p class='paragrafo'>{{{duasmetades}}}</p>
  192 + <div id='i3GEOlegendaitensMetade' class='styled-select'></div>
  193 + <br>
  194 + <p class='paragrafo'>{{{iunico}}}</p>
  195 + <div id='i3GEOlegendaitensMetadeId' class='styled-select'></div>
  196 + <br>
  197 + <p class='paragrafo'>
  198 + <input id='i3GEOlegendabotaoMetade' size='25' type='button' value='{{{aplicar}}}' />
  199 + </p>
  200 + </fieldset>
  201 + <br>
  202 + <fieldset style='padding: 5px; margin: 2px;'>
190 203 <legend>{{{calcularQuartil}}}</legend>
191 204 <p class='paragrafo'>{{{criaQuartis}}}</p>
192 205 <div id='i3GEOlegendaitensValorQuartil' class='styled-select'></div>
... ...