How asterbons/cliodynamics works
1. Repository purpose
- This is a Python-based data pipeline for building a Political Stress Index (PSI) for Germany using cliodynamics / Structural-Demographic Theory.
- It is not an application server; the main architecture is an ETL + analysis + visualization workflow centered on CSV files and generated dashboard artifacts.
2. Primary data boundary
- The project is organized around three filesystem zones:
- data/raw/ for source extracts
- data/processed/ for cleaned and merged datasets
- output/ for final visual outputs
- This clean separation is the core architectural boundary: ingestion writes raw inputs, preprocessing creates the analytical master dataset, and analysis reads processed data to produce final artifacts.
3. Ingestion subsystem
- The src/loaders/ package is responsible for acquiring data from external sources and placing it into data/raw/.
- Sources called out in the README include Destatis / GENESIS, WSI strike data, Google Trends, and other German socioeconomic datasets.
- Loader scripts are domain-specific, not generic: separate scripts exist for trends, students, rent/wages, table search, and a larger loader_v4.py entrypoint.
4. External data dependencies
- The architecture depends on government statistics and public data services rather than an internal database.
- Destatis credentials are expected via environment variables, which means data acquisition is parameterized and credential-bound.
- Google Trends is treated as an additional mobilization signal, and WSI strike records act as a social unrest proxy.
5. Raw dataset shape
- The raw layer contains multiple topic-specific CSVs such as wages, CPI, GDP, tax revenue, civil servants, students, youth population, food prices, holders, and strike data.
- There is also google_trends_mobilization.csv, indicating that the pipeline blends both official statistics and alternative signal data.
- The presence of data_holders_raw.csv alongside data_holders.csv suggests a raw-to-cleaned step for some sources.
6. Preprocessing subsystem
- src/preprocessors/ is the transformation layer that normalizes, cleans, aligns time series, and merges indicators into a unified analytical dataset.
- preprocessor_v4.py appears to be the current canonical pipeline, while preprocessor.py and afterpreprocessor.py look like earlier or supplementary versions.
- This layer likely computes the PSI components and ensures that heterogeneous series become time-aligned and comparable.
7. Analytical model layer
- src/analysis/Wealth_Pump_Index.py and Seasonal_Decomposition.py indicate focused analytical routines for component-level indicators and time-series decomposition.
- process_and_merge_trends.py bridges Google Trends into the main dataset, showing that trend data is treated as an analytical augmentation rather than a raw source alone.
- The analysis layer is where domain concepts such as wealth pump, elite pressure, and mobilization are operationalized.
8. Visualization and reporting
- Visualization is handled separately from preprocessing, mainly through src/analysis/visualizer_v1.py, visualizer_v2.py, and src/preprocessors/visualize_v4.py.
- The README references a generated interactive Plotly dashboard (output/psi_v4_dashboard.html) and a static figure output.
- This separation suggests the pipeline is designed to produce reusable analytical datasets first, then multiple presentation formats.
9. Pipeline flow
- The end-to-end flow is:
- fetch raw indicators
- store in data/raw/
- preprocess into merged/master CSVs in data/processed/
- run analysis and visualization
- emit dashboard artifacts into output/
- The processed master files (master_cliodynamics.csv and master_cliodynamics_v2.csv) are the central handoff point between data engineering and analysis.
10. Versioning and evolution
- The presence of multiple v2 and v4 scripts indicates iterative development of the PSI methodology.
- The architecture seems to preserve older scripts for comparison or fallback while promoting a newer “v4” pipeline as the main path.
- This suggests the repo values reproducibility and methodological evolution rather than a single frozen implementation.
11. Operational constraints
- Runtime is Python 3.9+ with a dependency-managed environment from requirements.txt.
- There is a preprocessor_debug.log, which implies preprocessing is a nontrivial, failure-prone stage and likely contains diagnostic instrumentation.
- Execution is file-based and script-driven, so the deployment model is batch processing rather than a long-running service.
12. What to diagram
- A good architecture diagram should show:
- external data sources on the left
- loader scripts writing to data/raw/
- preprocessors producing data/processed/master_cliodynamics*.csv
- analysis scripts consuming processed data
- visualization outputs in output/
- The key conceptual modules to emphasize are data ingestion, indicator engineering, composite PSI calculation, and dashboard/report generation.
Main entry points: master_cliodynamics_v2.csv Master v2 · raw Raw data · loader_v4.py Loader v4 · preprocessor_v4.py Preprocessor v4
Components 21
External data
Public statistics and alternative signals used as inputs
- Destatis · German official statistics / GENESIS data source
- WSI strikes · Strike and unrest proxy data source
- Google Trends · Mobilization signal from search trends
Ingestion
Loaders that fetch and stage source data
- Loader v4 · Main batch entrypoint for acquiring raw indicators
src/loaders/loader_v4.py - Trends loader · Fetches and stages Google Trends data
src/loaders/fetch_trends.py - Students loader · Loads education-related source series
src/loaders/load_students.py - Wages loader · Loads rent and wage indicators
src/loaders/load_rent_and_wages.py - Table search · Source lookup / retrieval helper for tabular data
src/loaders/table_search.py - Raw data · Staging area for source CSV extracts
data/raw
Preprocessing
Cleaning, alignment, and master dataset assembly
- Preprocessor v4 · Canonical cleaning, alignment, and merge pipeline
src/preprocessors/preprocessor_v4.py - Legacy prep · Earlier or supplementary preprocessing variants
src/preprocessors/preprocessor.py - After prep · Follow-up transformation stage for prepared data
src/preprocessors/afterpreprocessor.py - Processed data · Merged analytical datasets and master CSVs
data/processed - Master v2 · Primary processed handoff for analysis
data/processed/master_cliodynamics_v2.csv
Analysis
Indicator engineering and time-series routines
- Merge trends · Integrates Google Trends into the main dataset
src/analysis/process_and_merge_trends.py - Wealth pump · Computes a core PSI component / derived indicator
src/analysis/Wealth_Pump_Index.py - Seasonal decomp · Decomposes seasonality in indicators
src/analysis/Seasonal_Decomposition.py - Visualizer v2 · Creates analytical plots and presentation views
src/analysis/visualizer_v2.py - Viz v4 · Preprocessor-side visualization for the current pipeline
src/preprocessors/visualize_v4.py
Delivery
Generated artifacts and reports
- PSI dashboard · Interactive Plotly dashboard output
output/psi_v4_dashboard.html - Output · Final generated artifacts and figures
output
Connections 22
- Destatis → Loader v4: feeds · Official statistics are fetched through the main loader
- WSI strikes → Loader v4: feeds · Strike data is acquired as a source input
- Google Trends → Trends loader: feeds · Search trend signal is fetched separately
- Loader v4 → Raw data: writes · Loader stages source CSVs into the raw data zone
- Trends loader → Raw data: writes · Trend extracts are stored with other raw inputs
- Students loader → Raw data: writes · Education series are staged as raw extracts
- Wages loader → Raw data: writes · Wage and rent series are staged as raw extracts
- Table search → Loader v4: supports · Helper supports source retrieval and table lookup
- Raw data → Preprocessor v4: reads · Preprocessing consumes raw source CSVs
- Legacy prep → Preprocessor v4: evolves · Older preprocessing variants inform the canonical pipeline
- After prep → Preprocessor v4: extends · Follow-up transformation stage complements preprocessing
- Preprocessor v4 → Processed data: writes · Canonical pipeline emits processed datasets
- Processed data → Master v2: contains · Processed zone contains the master cliodynamics dataset
- Master v2 → Merge trends: reads · Analysis bridge augments the master dataset with trends
- Master v2 → Wealth pump: reads · Indicator model operates on the processed master data
- Master v2 → Seasonal decomp: reads · Time-series decomposition runs on processed indicators
- Master v2 → Visualizer v2: reads · Visualizer consumes the processed analytical dataset
- Master v2 → Viz v4: reads · Current visualization path is driven from the processed master dataset
- Merge trends → PSI dashboard: contributes · Trend-augmented analysis feeds the final dashboard
- Visualizer v2 → PSI dashboard: renders · Visualization scripts generate presentation artifacts
- Viz v4 → PSI dashboard: renders · Current visualization pipeline renders the dashboard output
- PSI dashboard → Output: stored in · Interactive dashboard artifact is written to the output zone