Skip to content

joaompfp/prumo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

83 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Prumo

Economic indicators dashboard built with FastAPI + DuckDB + ECharts, serving 11 interactive sections with data from 9 official statistical sources.

Open-source docs

PortuguΓͺs (pt-PT)

DocumentaΓ§Γ£o complementar em portuguΓͺs estΓ‘ disponΓ­vel em docs/ e em notas de projeto como SETUP_NOTES.md. O README principal mantΓ©m-se em inglΓͺs para o pΓΊblico open-source internacional.

image

Architecture

prumo/
β”œβ”€β”€ app/                          # FastAPI application
β”‚   β”œβ”€β”€ main.py                   # App entrypoint, CORS, static mount, healthcheck
β”‚   β”œβ”€β”€ config.py                 # Environment variables and paths
β”‚   β”œβ”€β”€ database.py               # Thread-safe DuckDB connection pool
β”‚   β”œβ”€β”€ constants/                # Static data (catalog, events, country lists)
β”‚   β”‚   β”œβ”€β”€ catalog.py            # CATALOG β€” 9 sources, ~380 indicators
β”‚   β”‚   β”œβ”€β”€ events.py             # CHART_EVENTS, BRIEFING/SUMMARY indicator lists
β”‚   β”‚   β”œβ”€β”€ countries.py          # COMPARE_COUNTRIES, COMPARE_DATASETS
β”‚   β”‚   └── mappings.py           # USED_IN, FRED_SERIES, WB_CODES, SOURCE_META
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ api.py                # /api/* endpoints (thin handlers β†’ services)
β”‚   β”‚   └── pages.py              # GET / β€” serves dashboard via Jinja2
β”‚   └── services/                 # Business logic, one module per section
β”‚       β”œβ”€β”€ helpers.py            # Shared: YoY, trend, sparkline, period utils
β”‚       β”œβ”€β”€ resumo.py             # Resumo KPIs
β”‚       β”œβ”€β”€ industria.py          # Industrial production (IPI)
β”‚       β”œβ”€β”€ energia.py            # Energy (REN, E-REDES, DGEG)
β”‚       β”œβ”€β”€ emprego.py            # Employment (IEFP, INE)
β”‚       β”œβ”€β”€ macro.py              # Macro indicators (GDP, inflation, trade)
β”‚       β”œβ”€β”€ ficha.py              # Data sheet / DB stats
β”‚       β”œβ”€β”€ fosso.py              # EU convergence gap
β”‚       β”œβ”€β”€ produtividade.py      # Productivity metrics
β”‚       β”œβ”€β”€ analysis.py           # Automated trend analysis
β”‚       β”œβ”€β”€ explorador.py         # Data explorer catalog
β”‚       β”œβ”€β”€ series.py             # Generic time series queries + country compare
β”‚       └── briefing.py           # Auto-generated briefing + summary
β”œβ”€β”€ templates/
β”‚   └── dashboard.html            # SPA shell (Jinja2, hash router, ECharts)
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   β”œβ”€β”€ swd-theme.css         # Storytelling with Data theme
β”‚   β”‚   └── sections.css          # Section-specific styles
β”‚   └── js/
β”‚       β”œβ”€β”€ app.js                # Hash router + lazy section loading
β”‚       β”œβ”€β”€ api.js                # Fetch wrappers with 5-min cache
β”‚       β”œβ”€β”€ swd-charts.js         # SWD chart factory (ECharts)
β”‚       └── sections/             # 11 section initializers (one per tab)
β”œβ”€β”€ collectors/                   # Data source clients (CLI tools)
β”‚   β”œβ”€β”€ ine.py                    # INE β€” Instituto Nacional de EstatΓ­stica
β”‚   β”œβ”€β”€ eurostat.py               # Eurostat
β”‚   β”œβ”€β”€ fred.py                   # FRED β€” Federal Reserve Economic Data
β”‚   β”œβ”€β”€ oecd.py                   # OECD
β”‚   β”œβ”€β”€ bportugal.py              # Banco de Portugal
β”‚   β”œβ”€β”€ ren.py                    # REN β€” Rede EnergΓ©tica Nacional
β”‚   β”œβ”€β”€ eredes.py                 # E-REDES β€” electricity distribution
β”‚   β”œβ”€β”€ dgeg_fuel_api.py          # DGEG β€” fuel prices
β”‚   └── worldbank.py              # World Bank
β”œβ”€β”€ stats_lib/                    # Shared data layer for collectors
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ cae-collect               # Main collection orchestrator
β”‚   └── cae-v4-backfill.py        # Historical data backfill
β”œβ”€β”€ analise-content.html          # Pre-rendered analysis content
β”œβ”€β”€ analise-metadata.json         # Analysis metadata
β”œβ”€β”€ requirements.txt              # Python dependencies
└── Dockerfile                    # Python 3.12 + uvicorn

Data Sources

Source Provider Data
INE Instituto Nacional de EstatΓ­stica Industrial production, employment, GDP, trade
Eurostat European Commission Cross-country comparisons (manufacturing, GDP, unemployment)
FRED Federal Reserve Bank of St. Louis US interest rates, global benchmarks
OECD Organisation for Economic Co-operation Composite leading indicators, productivity
BdP Banco de Portugal Monetary/financial indicators
REN Rede EnergΓ©tica Nacional Electricity consumption/production
E-REDES Electricity distribution Grid distribution data
DGEG DirecΓ§Γ£o-Geral de Energia e Geologia Fuel prices
World Bank World Bank Group Long-term development indicators

For provider URLs, cadence and terms/caveats notes, see SOURCES.md.

Dashboard Sections

Section Route API Description
Resumo #resumo /api/resumo Overview KPIs with sparklines and trends
IndΓΊstria #industria /api/industria Industrial Production Index (IPI) by sector
Europa #europa /api/europa PT vs EU country comparisons
Energia #energia /api/energia Energy consumption and production
Emprego #emprego /api/emprego Employment, unemployment, job offers
Macro #macro /api/macro GDP, inflation, trade balance
AnΓ‘lise #analise /api/analysis Automated trend analysis
Fosso #fosso /api/fosso EU convergence gap
Produtividade #produtividade /api/produtividade Labour productivity metrics
Explorador #explorador /api/explorador Data explorer (all indicators)
Ficha TΓ©cnica #ficha /api/ficha Data sheet, DB stats, sources

API Endpoints

All endpoints are under /api/ and return JSON.

Endpoint Method Parameters Description
/api/resumo GET β€” Summary KPIs
/api/industria GET period (int, default 5) IPI sectors data
/api/europa GET dataset, countries, months, indicator, source, since Country comparison
/api/energia GET β€” Energy data
/api/emprego GET β€” Employment data
/api/macro GET β€” Macro indicators
/api/ficha GET β€” DB stats and source metadata
/api/fosso GET β€” EU convergence gap
/api/produtividade GET β€” Productivity metrics
/api/analysis GET β€” Automated trend analysis
/api/explorador GET β€” Full indicator catalog
/api/briefing GET β€” Auto-generated briefing
/api/summary GET β€” Executive summary
/api/series GET source, indicator, from, to Raw time series query
/api/compare GET dataset, countries, months, indicator, source, since Country comparison (alias for europa)
/api/data GET β€” Full dataset dump
/api/kpis GET β€” Latest value per indicator
/api/catalog GET β€” CATALOG enriched with DB stats
/api/events GET β€” Historical event markers
/healthz GET β€” Health check
/docs GET β€” Swagger UI (auto-generated)

Environment Variables

Variable Default Description
CAE_DB_PATH /data/cae-data.duckdb Path to main DuckDB database
CAE_PORT 8080 Server port
CAE_BASE_PATH "" URL base path (for subpath serving)
SKILLS_DIR /home/node/.openclaw/workspace/skills/cae-reports Path to OpenClaw skills directory
TZ β€” Timezone (from compose)

Local server-env workflow (non-commit)

For machine-specific setup, use a local folder at stacks/web/images/prumo/server-env/.

  • server-env/ is intentionally ignored by git and must never be committed.
  • Keep all local-only links/files inside server-env/ (for example symlinks to root-level resources such as .bash_aliases, .env, and selected folders under md/).
  • Preferred pattern is symlink-based references from server-env/ so local server context is available without changing tracked deployment/configuration files.

Example local setup:

mkdir -p stacks/web/images/prumo/server-env
ln -s ../../../../../.bash_aliases stacks/web/images/prumo/server-env/bash_aliases
ln -s ../../../../../.env stacks/web/images/prumo/server-env/env
ln -s ../../../../../md stacks/web/images/prumo/server-env/md

This workflow is local-only and does not change compose behavior or deployment semantics.

Data Volume & First-Run Initialization

On its first run, the container will automatically initialize the /data volume with default configuration (site.json) and ideology defaults if they don't already exist. The DuckDB database is not included in the image; if one is not mounted, the system will place a README-DB.txt indicating that data needs to be populated via the collection scripts or mounted externally. This ensures safe, idempotent bootstrapping without overwriting existing data.

Deployment

The dashboard runs as a Docker container behind Traefik reverse proxy.

Compose layering (Phase 2)

Prumo is now split into two compose layers under stacks/web/compose/:

  • prumo.base.yml: portable/OSS app defaults (build, runtime env, healthcheck).
  • prumo.yml: server override (Traefik routes, proxy cert chain, server networks, bind mounts used on this host).

The stack loader in stacks/web/compose.yml includes base first and override second so current server behavior remains unchanged while keeping a reusable base.

Build and deploy

dc-jarbas-up cae-dashboard

Routes

  • Primary: https://cae.joao.date β€” direct access
  • Subpath: https://joao.date/dados β€” served under subpath with Traefik StripPrefix

The subpath route uses Traefik's StripPrefix middleware which sets X-Forwarded-Prefix: /dados. The app reads this header to inject the correct BASE_PATH into the template, so all static asset and API URLs resolve correctly.

Collect data

docker exec cae-dashboard ./scripts/cae-collect

Technical Notes

  • Single worker: Uvicorn runs with --workers 1 because DuckDB connections are not thread-safe. FastAPI's thread pool handles concurrent requests via per-thread connection reuse.
  • No auth: Dashboard is public (chain-no-auth@file middleware in Traefik).
  • SPA routing: The frontend uses hash-based routing (#section). All navigation is client-side; the server only serves the single HTML shell.
  • Chart library: ECharts 5.5.0 (CDN) with a custom SWD (Storytelling with Data) theme.
  • Caching: api.js caches API responses in memory for 5 minutes to reduce DB load during tab switching.
  • Database: DuckDB in read-only mode. Data is collected externally by the cae-collect script and written to the database separately.

About

Socio-economic data platform -with AI assistance layer: indicators, comparisons, data explorer, embeddable charts (FastAPI + DuckDB + ECharts) and LLM integration for content generation according to different biases.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors