Automatiza componente B e ajuste frontend do ranking

This commit is contained in:
Frederico Castro
2025-12-10 13:49:43 -03:00
parent d1379b4f5c
commit 6f11b7c166
11 changed files with 431 additions and 186 deletions

View File

@@ -4,7 +4,13 @@ from contextlib import asynccontextmanager
from .routes import router
from .config import settings
from .dependencies import es_client, oracle_local_client, oracle_remote_client, get_processar_job
from .dependencies import (
es_client,
oracle_local_client,
oracle_remote_client,
get_processar_job,
get_popular_componente_b_job,
)
from ...application.jobs.scheduler import RankingScheduler
@@ -29,7 +35,8 @@ async def lifespan(app: FastAPI):
scheduler = None
try:
job = get_processar_job()
scheduler = RankingScheduler(job)
job_b = get_popular_componente_b_job()
scheduler = RankingScheduler(job, job_componente_b=job_b)
await scheduler.iniciar()
except Exception as e:
print(f"AVISO: Scheduler não iniciou: {e}")

View File

@@ -3,6 +3,7 @@ from ...infrastructure.oracle.client import OracleClient
from ...infrastructure.oracle.ranking_repository import RankingOracleRepository
from ...infrastructure.repositories.consultor_repository_impl import ConsultorRepositoryImpl
from ...application.jobs.processar_ranking import ProcessarRankingJob
from ...application.jobs.popular_componente_b_job import PopularComponenteBJob
from .config import settings
@@ -30,6 +31,7 @@ oracle_remote_client = OracleClient(
_repository: ConsultorRepositoryImpl = None
_ranking_repository: RankingOracleRepository = None
_processar_job: ProcessarRankingJob = None
_popular_b_job: PopularComponenteBJob = None
def get_repository() -> ConsultorRepositoryImpl:
@@ -56,3 +58,13 @@ def get_processar_job() -> ProcessarRankingJob:
ranking_repo=get_ranking_repository()
)
return _processar_job
def get_popular_componente_b_job() -> PopularComponenteBJob:
global _popular_b_job
if _popular_b_job is None:
_popular_b_job = PopularComponenteBJob(
oracle_local_client=oracle_local_client,
oracle_remote_client=oracle_remote_client
)
return _popular_b_job

View File

@@ -20,6 +20,7 @@ from ..schemas.ranking_schema import (
)
from .dependencies import get_repository, get_ranking_repository, get_processar_job
from ...application.jobs.job_status import job_status
import json
router = APIRouter(prefix="/api/v1", tags=["ranking"])
@@ -102,19 +103,7 @@ async def ranking_paginado(
total_pages = (total + size - 1) // size
consultores_schema = [
ConsultorRankingResumoSchema(
id_pessoa=c.id_pessoa,
nome=c.nome,
posicao=c.posicao,
pontuacao_total=c.pontuacao_total,
componente_a=c.componente_a,
componente_b=c.componente_b,
componente_c=c.componente_c,
componente_d=c.componente_d,
ativo=c.ativo,
anos_atuacao=c.anos_atuacao
)
for c in consultores
_consultor_resumo_from_ranking(c) for c in consultores
]
return RankingPaginadoResponseSchema(
@@ -126,6 +115,29 @@ async def ranking_paginado(
)
def _consultor_resumo_from_ranking(c):
consultoria = None
try:
jd = json.loads(c.json_detalhes) if c.json_detalhes else {}
consultoria = jd.get("consultoria") if isinstance(jd, dict) else None
except Exception:
consultoria = None
return ConsultorRankingResumoSchema(
id_pessoa=c.id_pessoa,
nome=c.nome,
posicao=c.posicao,
pontuacao_total=c.pontuacao_total,
componente_a=c.componente_a,
componente_b=c.componente_b,
componente_c=c.componente_c,
componente_d=c.componente_d,
ativo=c.ativo,
anos_atuacao=c.anos_atuacao,
consultoria=consultoria,
)
@router.get("/ranking/estatisticas", response_model=EstatisticasRankingSchema)
async def ranking_estatisticas(
ranking_repo = Depends(get_ranking_repository),