AlertaDengue / AlertaDengueCaptura

Rotinas para captura de dados
GNU General Public License v3.0
6 stars 11 forks source link

Bugfix fill counties #77

Closed esloch closed 3 years ago

esloch commented 3 years ago
esloch commented 3 years ago

@fccoelho I'm validating with syncgeofiles before confirming, it looks like we have more problems ...

esloch commented 3 years ago

@fccoelho segue o report: O sync_geofiles não finaliza o processo de execução por alguns campos geojson na tabela "Dengue_global"."Municipio" estarem vazios:

dengueadmin@200:dengue> SELECT * FROM "Dengue_global"."Municipio" WHERE geocodigo=4220000;
+-------------+------------------+-----------+-------------+----------------+
| geocodigo   | nome             | geojson   | populacao   | uf             |
|-------------+------------------+-----------+-------------+----------------|
| 4220000     | Balneário Rincão | ""        | 12212       | Santa Catarina |
+-------------+------------------+-----------+-------------+----------------+

A App br-atlas não atualiza os files JSON para alguns municípios desde a fonte do IBGE:

1504752 is not in this geojson: pa.
4220000 is not in this geojson: sc.
4212650 is not in this geojson: sc.
4314548 is not in this geojson: rs.
5006275 is not in this geojson: ms.

CORREÇÃO Como alternativa foi criada a captura desde a API do IBGE: photo_2021-02-12_06-28-42

Os dados atuais no campo geojson na base da produção estão corrompidos:

dengueadmin@172:dengue> SELECT * FROM "Dengue_global"."Municipio" LIMIT 5;
+-------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
| geocodigo   | nome                  | geojson                                                                                                                                                                                     >
|-------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
| 1100015     | Alta Floresta D'Oeste | {"id": null, "geometry": {"coordinates": [[[-62.24619999285109, -11.901491491342], [-62.24398217664209, -11.901792085777299], [-62.241510805931995, -11.903270360906799], [-62.2439007184224>
| 1100023     | Ariquemes             | {"id": null, "geometry": {"coordinates": [[[-63.13712041193419, -9.784128828237979], [-63.0901289222885, -9.782367251610527], [-63.08988612872389, -9.78132654813934], [-63.09258992028059, >
| 1100031     | Cabixi                | {"id": null, "geometry": {"coordinates": [[[-60.5240797650751, -13.321372529996598], [-60.37161796037179, -13.318590345392899], [-60.37161114871169, -13.318590221091], [-60.37347303923849,>
| 1100049     | Cacoal                | {"id": null, "geometry": {"coordinates": [[[-61.426787563925004, -11.113760312915097], [-61.42900212332289, -10.987534213684398], [-61.4273103050208, -10.987552794455198], [-61.00059491397>
| 1100056     | Cerejeiras            | {"id": null, "geometry": {"coordinates": [[[-61.41347403956169, -13.2341685497038], [-61.41505011749268, -13.234970943198398], [-61.416727268301486, -13.236394807266098], [-61.417758034392>
+-------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
SELECT 5

CORREÇÃO:

esloch@dengue> SELECT * FROM "Dengue_global"."Municipio" LIMIT 5;
+-------------+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
| geocodigo   | nome    | geojson                                                                                                                                                                >
|-------------+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
| 1200138     | Bujari  | {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-68.31643, -9.295409], [-68.314842, -9.294053], [-68.312936, -9.292458], [-68.311666, -9.291183],>
| 2507200     | Itatuba | {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-35.71324, -7.364901], [-35.702682, -7.338105], [-35.700546, -7.339696], [-35.698217, -7.340425],>
| 2501807     | Bayeux  | {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-34.91654, -7.116528], [-34.91566, -7.117222], [-34.915299, -7.116782], [-34.91439, -7.115676], [>
| 3151909     | Pocrane | {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-41.366631, -19.636012], [-41.367422, -19.636632], [-41.36778, -19.637005], [-41.367942, -19.6374>
| 3501905     | Amparo  | {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[-46.806545, -22.546287], [-46.80636, -22.546386], [-46.806041, -22.546807], [-46.805724, -22.5470>
+-------------+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
SELECT 5

Com os trigers do bucardo agora não é permitido tabelas sem index {pk} da mesma forma está restrita de fazer INSERT no campo da chave:

  File "/work_lab/fiocruz/repositories/AlertaDengueCaptura/utilities/fill_counties.py", line 60, in <module>
    save(rows, schema="Dengue_global", table="Municipio")
  File "/work_lab/fiocruz/repositories/AlertaDengueCaptura/utilities/models.py", line 92, in save
    curr.executemany(sql, rows)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "Municipio_pk"
DETAIL:  Key (geocodigo)=(1100015) already exists

CORREÇÃO: https://github.com/AlertaDengue/AlertaDengueCaptura/blob/4820dafc0de8ae55e4e0763758caa4c157ac9777/utilities/models.py#L97

esloch commented 3 years ago

O sync_geofiles agora está finalizando com exito, mas ainda não temos solucionado por completo, por não ser possível a visualização de alguns municípios no mapa. Continuarei a issue aqui: https://github.com/AlertaDengue/AlertaDengue/issues/394