Add utility scripts and documentation

- Add TIPOS_ATUACAO_ELASTICSEARCH.md: mapping of ES activity types
- Add TOP_10_RANKING_CAPES.md: sample ranking output documentation
- Add backend/scripts/: utility scripts for analysis and debugging
  - analise_detalhada.py: detailed consultant analysis
  - auditar_ranking.py: ranking audit tool
  - bootstrap_ranking.sh: bootstrap script
  - buscar_consultores_especificos.py: search specific consultants
  - popular_componente_b.py: populate component B
  - top10_ranking.py: generate top 10 ranking
- Add scripts/reload_atuacapes.sh: reload ES index script
This commit is contained in:
Frederico Castro
2025-12-14 21:36:57 -03:00
parent 10d8efc96a
commit 4a98e8b38c
6 changed files with 1508 additions and 0 deletions

79
scripts/reload_atuacapes.sh Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"
echo "[1/5] Garantindo rede Docker compartilhada..."
docker network create shared_network >/dev/null 2>&1 || true
echo "[2/5] Subindo oracle18c e backend..."
docker compose up -d oracle18c backend
echo "[3/5] Aguardando backend responder /health..."
for i in {1..30}; do
if docker compose exec backend python - <<'PY' >/dev/null 2>&1; then
import httpx, sys
try:
r = httpx.get("http://localhost:8000/api/v1/health", verify=False, timeout=15)
if r.status_code == 200:
sys.exit(0)
except Exception:
pass
sys.exit(1)
PY
echo " Backend OK."
break
fi
echo " Tentativa ${i}/30... aguardando 5s"
sleep 5
if [ "$i" -eq 30 ]; then
echo "ERRO: backend não respondeu /health."
exit 1
fi
done
echo "[4/5] Disparando job do ranking (limpar_antes=true)..."
docker compose exec backend python - <<'PY'
import httpx
client = httpx.Client(verify=False, timeout=120)
resp = client.post("http://localhost:8000/api/v1/ranking/processar", json={"limpar_antes": True})
print("POST /api/v1/ranking/processar ->", resp.status_code, resp.text)
PY
echo "[5/5] Acompanhando status até finalizar..."
docker compose exec backend python - <<'PY'
import httpx, time
client = httpx.Client(verify=False, timeout=120)
while True:
r = client.get("http://localhost:8000/api/v1/ranking/status")
data = r.json()
print(f"{time.strftime('%H:%M:%S')} | running={data.get('running')} | {data.get('processados')}/{data.get('total')} ({data.get('progress')}%) | msg={data.get('mensagem')}")
if not data.get("running"):
break
time.sleep(15)
print("Coletando contagens finais...")
dsn = None
try:
import os, cx_Oracle
dsn = os.getenv("ORACLE_LOCAL_DSN", "oracle18c:1521/XEPDB1")
user = os.getenv("ORACLE_LOCAL_USER", "local123")
pwd = os.getenv("ORACLE_LOCAL_PASSWORD", "local123")
conn = cx_Oracle.connect(user, pwd, dsn)
cur = conn.cursor()
for sql in [
"select count(*) from tb_ranking_consultor",
"select count(*) from tb_ranking_consultor where componente_a>0",
"select count(*) from tb_ranking_consultor where componente_c>0",
"select count(*) from tb_ranking_consultor where componente_d>0",
"select max(pontuacao_total) from tb_ranking_consultor"
]:
cur.execute(sql)
print(sql, cur.fetchone()[0])
cur.close(); conn.close()
except Exception as e:
print(f"AVISO: não foi possível coletar contagens finais (dsn={dsn}): {e}")
PY
echo "Pronto."