Skip to content

feat: implement scoring/ — SCI scoring engine (Front 1) #8

Description

@guidevit-dealsmartai

Context

Part of the Application Layer design (Issue #7). Front 1 of 4 — merges first.

Scope

Implement the SCI (Score de Consistência) scoring engine under scoring/. This module reads from PostgreSQL and Neo4j (populated by the data pipeline), calculates a 0–1000 consistency score across 6 dimensions, and writes results back to the database.

Deliverables

Dimension Calculators (scoring/dimensions/)

Dimension File Weight Max Deduction
Wealth evolution vs salary patrimonio.py 25% −250 pts
Vote × donor sector correlation voto_doador.py 20% −200 pts
Family company contracts contrato_familiar.py 20% −200 pts
Amendment beneficiary linkage emenda_vinculo.py 15% −150 pts
Family office hiring gabinete_familiar.py 12% −120 pts
Vote change after donation voto_pos_doacao.py 8% −80 pts

Each dimension class inherits from BaseDimension and implements calculate(mandatario_id) → DimensionResult(score, deductions, inconsistencies).

Core Modules

  • engine.py — SCIEngine.calculate(mandatario_id) → SCIResult — orchestrates all 6 dimensions, applies weights, returns 0–1000 score
  • detector.py — InconsistencyDetector — creates :Inconsistencia records in PG + Neo4j with FATO/MÉTRICA/FONTE
  • history.py — ScoreHistory — records score snapshots for audit trail
  • queries/neo4j_queries.py — Cypher queries for graph traversals (family→company→contract)
  • queries/pg_queries.py — SQL aggregations (wealth, votes, donations)

CLI

python -m scoring.engine {mandatario_id | --all} — can be invoked by Airflow DAG or manually.

Key Constraints

  • Fixed weights (no ML — that's Phase 2)
  • Score = 1000 − sum(deductions), clamped to [0, 1000]
  • Every deduction MUST produce an :Inconsistencia with FATO + MÉTRICA + FONTE
  • All scores deterministic and reproducible
  • Imports vigiabr-schemas from pipeline/schemas/

Dependencies

  • Depends on: pipeline/schemas/ (merged), data in PostgreSQL + Neo4j
  • Blocks: Backend API (Front 2) reads pre-computed scores

Branch

feat/8-sci-scoring-engine (from develop)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions