Datos y Calculos

IGSM scoring and validation helpers.

data.calculation.clasificar_nivel(score)

Classify an IGSM score into its official maturity level.

Parámetros:

score (float) – IGSM score in the 0-1 range.

Devuelve:

Official maturity level label.

Tipo del valor devuelto:

str

data.calculation.calcular_score_servicio(respuestas, servicio_nombre, eje_nombre)

Calculate the score for one municipal service.

The stage score is the average of scored indicators in the stage. The final service score is the weighted sum of stage scores using the official CGR stage weights.

Parámetros:
  • respuestas (dict) – Mapping from indicator code to submitted value.

  • servicio_nombre (str) – Service name as defined in the IGSM structure.

  • eje_nombre (str) – Axis name that contains the service.

Devuelve:

Service score summary with stage detail and final score.

Tipo del valor devuelto:

dict

data.calculation.calcular_igsm_municipalidad(respuestas, diversificados)

Calculate the total IGSM score for a municipality.

Only services with at least one response are included. Indicator weights are derived from the official stage weights divided by the number of scored indicators in each stage.

Parámetros:
  • respuestas (dict) – Mapping from indicator code to submitted value.

  • diversificados (list) – Diversified service keys applicable to the municipality.

Devuelve:

Municipality score summary with total score, maturity level, percentage, service detail, and indicator counts.

Tipo del valor devuelto:

dict

data.calculation.calcular_consistencia(respuestas, diversificados)

Calculate internal consistency alerts for submitted responses.

Parámetros:
  • respuestas (dict) – Mapping from indicator code to submitted value.

  • diversificados (list) – Diversified service keys applicable to the municipality.

Devuelve:

Consistency summary with detected inconsistencies, count, score, and status label.

Tipo del valor devuelto:

dict

data.calculation.detectar_anomalia_historica(score_actual, historial)

Detect whether the current score is anomalous against history.

Parámetros:
  • score_actual (float) – Current IGSM score in the 0-1 range.

  • historial (list) – Previous IGSM scores ordered chronologically.

Devuelve:

Anomaly summary with variation metrics and a display message.

Tipo del valor devuelto:

dict

Application-facing data access layer for SIGAM views.

data.db_layer._calcular_igsm_bd(codigo, end_date=None)

Calculate IGSM from database metadata for one municipality.

The calculation uses the stage metadata stored in the ORM tables and applies the PT-228 stage-weight formula.

Parámetros:
  • codigo (str) – Municipality code.

  • end_date – Optional cutoff date accepted by repository helpers.

Devuelve:

Score summary with total score, maturity level, stage scores, and service scores. A zero-score fallback is returned when calculation fails.

Tipo del valor devuelto:

dict

data.db_layer._build_muni_record(muni, end_date=None, posicion=0)

Build the view-ready record for a municipality.

Parámetros:
  • muni (dict) – Municipality dictionary from the repository layer.

  • end_date – Optional cutoff date for responses.

  • posicion (int) – Ranking position assigned by the caller.

Devuelve:

Municipality record with score, level, location, history, and status.

Tipo del valor devuelto:

dict

data.db_layer.get_ranking(end_date=None)

Return the national municipality ranking.

Parámetros:

end_date – Optional cutoff date for responses.

Devuelve:

Ranking records ordered by descending total score.

Tipo del valor devuelto:

list[dict]

data.db_layer.get_municipalidad_data(nombre, end_date=None)

Return complete municipality data by name.

Parámetros:
  • nombre (str) – Municipality display name.

  • end_date – Optional cutoff date for responses.

Devuelve:

Municipality record, or None when the name is unknown.

Tipo del valor devuelto:

dict | None

data.db_layer.get_municipalidad_data_by_codigo(codigo, end_date=None)

Return complete municipality data by code.

Parámetros:
  • codigo (str) – Municipality code.

  • end_date – Optional cutoff date for responses.

Devuelve:

Municipality record, or None when the code is unknown.

Tipo del valor devuelto:

dict | None

data.db_layer.get_estadisticas_nacionales(end_date=None)

Return national KPI statistics calculated from the database.

Parámetros:

end_date – Optional cutoff date for responses.

Devuelve:

National totals, participation metrics, score extrema, and maturity distribution.

Tipo del valor devuelto:

dict

data.db_layer.get_scores_por_servicio_nacional(end_date=None)

Return national average scores by service.

Parámetros:

end_date – Optional cutoff date for responses.

Devuelve:

Mapping from service name to average score.

Tipo del valor devuelto:

dict[str, float]

data.db_layer.save_responses(municipalidad_codigo, respuestas, end_date=None)

Persist form responses for a municipality.

Parámetros:
  • municipalidad_codigo (str) – Municipality code.

  • respuestas (dict) – Mapping from indicator code to submitted value.

  • end_date – Optional response date. Defaults to today.

Devuelve:

Repository submission summary.

Tipo del valor devuelto:

dict

data.db_layer.load_responses(municipalidad_codigo, end_date=None)

Load the latest responses for a municipality.

Parámetros:
  • municipalidad_codigo (str) – Municipality code.

  • end_date – Optional response cutoff date.

Devuelve:

Mapping from indicator code to latest value.

Tipo del valor devuelto:

dict

data.db_layer.get_historial_nacional()

Return national historical summary data for 2022-2025.

Devuelve:

Mapping from year to national average and maturity-level counts.

Tipo del valor devuelto:

dict

data.db_layer.get_weights(end_date=None)

Return the effective stage weights.

Parámetros:

end_date – Optional cutoff date for effective weights.

Devuelve:

Mapping from stage name to weight.

Tipo del valor devuelto:

dict[str, float]

data.db_layer.save_weights(planificacion, ejecucion, evaluacion, effective_from=None)

Persist a new set of stage weights.

Parámetros:
  • planificacion (float) – Planning stage weight.

  • ejecucion (float) – Execution stage weight.

  • evaluacion (float) – Evaluation stage weight.

  • effective_from (date | None) – Optional effective date. Defaults to today.

Devuelve:

Saved stage-weight summary.

Tipo del valor devuelto:

dict

Static IGSM indicator structure and maturity helpers.

data.indicators.clasificar_nivel(score)

Classify an IGSM score into a maturity level.

Parámetros:

score (float) – IGSM score in the 0-1 range.

Devuelve:

Maturity level label.

Tipo del valor devuelto:

str

data.indicators.get_servicios_para_municipalidad(diversificados)

Return the services that apply to a municipality.

Basic services are always included. Diversified services are included only when their service key is present in the municipality’s diversified-service list.

Parámetros:

diversificados (list) – Diversified service keys assigned to the municipality.

Devuelve:

Mapping from service name to service metadata, including the axis name.

Tipo del valor devuelto:

dict

data.indicators.contar_indicadores_totales()

Count scored indicators by stage and in total.

Devuelve:

Dictionary with total, planning, execution, and evaluation counts.

Tipo del valor devuelto:

dict

Mock IGSM data used by legacy and fallback view flows.

data.mock_data._score_en_rango(nivel_objetivo)

Generate a random score inside a maturity-level range.

Parámetros:

nivel_objetivo (str) – Target maturity level.

Devuelve:

Random score in the 0-1 range.

Tipo del valor devuelto:

float

data.mock_data._generar_score_servicio(base, variacion=0.15)

Generate a bounded service score around a base value.

Parámetros:
  • base (float) – Base score in the 0-1 range.

  • variacion (float) – Maximum random variation applied in either direction.

Devuelve:

Service score clipped to the 0-1 range.

Tipo del valor devuelto:

float

data.mock_data._generar_historial(score_actual)

Generate a plausible 2022-2024 score history.

Parámetros:

score_actual (float) – Current score used as the trend anchor.

Devuelve:

Three historical scores ordered from 2022 to 2024.

Tipo del valor devuelto:

list

data.mock_data.get_ranking()

Return the mock national ranking.

Devuelve:

List of mock municipality records ordered by score.

Tipo del valor devuelto:

list

data.mock_data.get_municipalidad_data(nombre)

Return a mock municipality record by name.

Parámetros:

nombre (str) – Municipality display name.

Devuelve:

Matching municipality record, or None when not found.

Tipo del valor devuelto:

dict

data.mock_data.get_municipalidad_by_codigo(codigo)

Return a mock municipality record by code.

Parámetros:

codigo (str) – Municipality code.

Devuelve:

Matching municipality record, or None when not found.

Tipo del valor devuelto:

dict

data.mock_data.get_estadisticas_nacionales()

Return national statistics calculated from mock data.

Devuelve:

Mock national totals, participation metrics, score extrema, and level distribution.

Tipo del valor devuelto:

dict

data.mock_data.get_historial_nacional()

Return mock national historical data for 2022-2025.

Devuelve:

Mapping from year to average score and maturity-level counts.

Tipo del valor devuelto:

dict

data.mock_data.get_scores_por_servicio_nacional()

Return mock national average scores by service.

Devuelve:

Mapping from service name to average score.

Tipo del valor devuelto:

dict

Static municipality catalog for Costa Rica.

data.municipalities.get_municipalidad(codigo)

Return a municipality by code.

Parámetros:

codigo (str) – Municipality code.

Devuelve:

Municipality dictionary, or None when not found.

Tipo del valor devuelto:

dict

data.municipalities.get_municipalidades_by_region(region)

Return municipalities in a region.

Parámetros:

region (str) – Region name.

Devuelve:

List of municipality dictionaries for the region.

Tipo del valor devuelto:

list

data.municipalities.get_nombres()

Return all municipality names.

Devuelve:

List of municipality names in catalog order.

Tipo del valor devuelto:

list

data.municipalities.get_by_nombre(nombre)

Return a municipality by exact name.

Parámetros:

nombre (str) – Municipality name.

Devuelve:

Municipality dictionary, or None when not found.

Tipo del valor devuelto:

dict