mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-26 01:24:59 +02:00
* feat(resilience): Phase 1 §3.2+§3.3 — full-country sanctions counts + grey-out ranking §3.2 — Switch sanctions from top-12 to full country counts - RESILIENCE_SANCTIONS_KEY: 'sanctions:pressure:v1' → 'sanctions:country-counts:v1' - New key is a plain ISO2→entryCount map covering ALL countries (no top-12 truncation) - Replaces compound pressure formula with normalizeSanctionCount() piecewise scale: 0=100, 1-10=90-75, 11-50=75-50, 51-200=50-25, 201+=25→0 - IMPUTE.ofacSanctions removed (country-counts covers all countries; no absent-country imputation needed for sanctions) §3.3 — Grey-out criteria for ranking - Proto: ResilienceRankingItem.overall_coverage (field 5) + GetResilienceRankingResponse.greyed_out - GREY_OUT_COVERAGE_THRESHOLD = 0.40: countries below this are excluded from ranking but still appear on choropleth in "insufficient data" style - buildRankingItem() now computes overallCoverage from domain/dimension data - getResilienceRanking() splits items into ranked (≥0.40) + greyedOut (<0.40) Tests updated for new sanctions format; overall score anchor updated (67.56). * fix(resilience): fix ranking cache guard for all-greyed-out + stale shape cases Two cache bugs: 1. Empty-items guard: `cached?.items?.length` fails when every country falls below GREY_OUT_COVERAGE_THRESHOLD (items=[], greyedOut=[…]). The cache was written correctly but never served, causing unnecessary rewarming on every request for sparse-data deployments. Fix: `cached != null && (items.length > 0 || greyedOut.length > 0)` 2. Stale-shape test: agent-written cache test stored a payload without `greyedOut` or `overallCoverage`, locking in pre-PR shape. Updated to the correct post-deploy shape so the test reflects actual cached content. Cache key was already bumped to resilience:ranking:v2 (forces fresh compute on first post-deploy request, avoiding old-shape responses in production). * fix(resilience): consume greyedOut on choropleth; version ranking cache key - Add 'insufficient_data' level to ResilienceChoroplethLevel and RESILIENCE_CHOROPLETH_COLORS - Extend buildResilienceChoroplethMap to accept optional greyedOut array - Thread greyedOut through DeckGLMap.setResilienceRanking, MapContainer.setResilienceRanking (with replay), and data-loader.ts - Add 'Insufficient data' tooltip guard for greyed-out countries in DeckGLMap - Bump RESILIENCE_RANKING_CACHE_KEY to resilience:ranking:v2 to invalidate stale schema-mismatched cache entries - Update api/health.js probe key to match * fix(resilience): include greyedOut in seed-meta count to avoid false health alert seed-meta:resilience:ranking was written with count=response.items.length, which excludes greyedOut countries. In an all-greyed-out deployment, count=0 causes api/health.js to report the ranking as EMPTY_DATA/critical even though the cached payload is valid (items:[], greyedOut:[…]). Fix: count = items.length + greyedOut.length — total scoured countries regardless of ranking eligibility. * test(resilience): pin all-greyed-out cache-hit regression Adds the missing test case: cached payload with items=[] and greyedOut=[…] must be served from cache without triggering score rewarming. Previously, `cached?.items?.length` was falsy for this shape, making the guard ineffective. The fix (items.length > 0 || greyedOut.length > 0) was correct but unpinned — this test locks it in.
178 lines
6.3 KiB
YAML
178 lines
6.3 KiB
YAML
openapi: 3.1.0
|
|
info:
|
|
title: ResilienceService API
|
|
version: 1.0.0
|
|
paths:
|
|
/api/resilience/v1/get-resilience-score:
|
|
get:
|
|
tags:
|
|
- ResilienceService
|
|
summary: GetResilienceScore
|
|
operationId: GetResilienceScore
|
|
parameters:
|
|
- name: countryCode
|
|
in: query
|
|
required: true
|
|
schema:
|
|
type: string
|
|
responses:
|
|
"200":
|
|
description: Successful response
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/GetResilienceScoreResponse'
|
|
"400":
|
|
description: Validation error
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/ValidationError'
|
|
default:
|
|
description: Error response
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
/api/resilience/v1/get-resilience-ranking:
|
|
get:
|
|
tags:
|
|
- ResilienceService
|
|
summary: GetResilienceRanking
|
|
operationId: GetResilienceRanking
|
|
responses:
|
|
"200":
|
|
description: Successful response
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/GetResilienceRankingResponse'
|
|
"400":
|
|
description: Validation error
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/ValidationError'
|
|
default:
|
|
description: Error response
|
|
content:
|
|
application/json:
|
|
schema:
|
|
$ref: '#/components/schemas/Error'
|
|
components:
|
|
schemas:
|
|
Error:
|
|
type: object
|
|
properties:
|
|
message:
|
|
type: string
|
|
description: Error message (e.g., 'user not found', 'database connection failed')
|
|
description: Error is returned when a handler encounters an error. It contains a simple error message that the developer can customize.
|
|
FieldViolation:
|
|
type: object
|
|
properties:
|
|
field:
|
|
type: string
|
|
description: The field path that failed validation (e.g., 'user.email' for nested fields). For header validation, this will be the header name (e.g., 'X-API-Key')
|
|
description:
|
|
type: string
|
|
description: Human-readable description of the validation violation (e.g., 'must be a valid email address', 'required field missing')
|
|
required:
|
|
- field
|
|
- description
|
|
description: FieldViolation describes a single validation error for a specific field.
|
|
ValidationError:
|
|
type: object
|
|
properties:
|
|
violations:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/FieldViolation'
|
|
description: List of validation violations
|
|
required:
|
|
- violations
|
|
description: ValidationError is returned when request validation fails. It contains a list of field violations describing what went wrong.
|
|
GetResilienceScoreRequest:
|
|
type: object
|
|
properties:
|
|
countryCode:
|
|
type: string
|
|
GetResilienceScoreResponse:
|
|
type: object
|
|
properties:
|
|
countryCode:
|
|
type: string
|
|
overallScore:
|
|
type: number
|
|
format: double
|
|
level:
|
|
type: string
|
|
domains:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ResilienceDomain'
|
|
cronbachAlpha:
|
|
type: number
|
|
format: double
|
|
trend:
|
|
type: string
|
|
change30d:
|
|
type: number
|
|
format: double
|
|
lowConfidence:
|
|
type: boolean
|
|
ResilienceDomain:
|
|
type: object
|
|
properties:
|
|
id:
|
|
type: string
|
|
score:
|
|
type: number
|
|
format: double
|
|
weight:
|
|
type: number
|
|
format: double
|
|
dimensions:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ResilienceDimension'
|
|
ResilienceDimension:
|
|
type: object
|
|
properties:
|
|
id:
|
|
type: string
|
|
score:
|
|
type: number
|
|
format: double
|
|
coverage:
|
|
type: number
|
|
format: double
|
|
GetResilienceRankingRequest:
|
|
type: object
|
|
GetResilienceRankingResponse:
|
|
type: object
|
|
properties:
|
|
items:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ResilienceRankingItem'
|
|
greyedOut:
|
|
type: array
|
|
items:
|
|
$ref: '#/components/schemas/ResilienceRankingItem'
|
|
ResilienceRankingItem:
|
|
type: object
|
|
properties:
|
|
countryCode:
|
|
type: string
|
|
overallScore:
|
|
type: number
|
|
format: double
|
|
level:
|
|
type: string
|
|
lowConfidence:
|
|
type: boolean
|
|
overallCoverage:
|
|
type: number
|
|
format: double
|