A comprehensive economic data assessment and prediction system for researchers, economists, and policy makers.
Features • Quick Start • Architecture • API • Contributing • License
English | 中文
| Feature | Description |
|---|---|
| 📈 Indicator Inference | Input economic indicators to automatically infer related metrics (e.g., fiscal deficit rate, debt ratio) |
| 🔮 Teaching Models | Preset economic models (Phillips Curve, Okun's Law, Cobb-Douglas) for educational purposes |
| 🗺️ Regional Analysis | North-South, East-West economic comparison and convergence testing |
| 📥 Data Collection | Automated scraping from official sources (Ministry of Finance, NBS, Customs, PBC) |
| 📊 Visualization | Interactive charts and dashboards with Plotly |
| Source | Code | Description |
|---|---|---|
| Ministry of Finance | mof |
Fiscal revenue, expenditure, debt data |
| National Bureau of Statistics | nbs |
GDP, CPI, employment, population |
| Customs Administration | customs |
Import/export trade data |
| People's Bank of China | pbc |
Monetary supply, interest rates |
- Fiscal:
fiscal_deficit,deficit_rate,debt_ratio,tax_revenue - Regional:
gini_coefficient,theil_index,convergence_coefficient - Income:
urban_rural_ratio,gini_urban,labor_share - Industrial:
industrial_upgrading_index,hoffmann_coefficient - Innovation:
rd_intensity,patent_output,innovation_efficiency
- Python 3.10+
- Git
# Clone the repository
git clone https://github.com/your-repo/national_stats.git
cd national_stats
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt# Start backend (Terminal 1)
uvicorn backend.main:app --reload --port 8001
# Start frontend (Terminal 2)
streamlit run app/streamlit_app.py| Service | URL |
|---|---|
| Frontend | http://localhost:8501 |
| API Docs | http://localhost:8001/docs |
| ReDoc | http://localhost:8001/redoc |
| Health Check | http://localhost:8001/health |
national_stats/
├── app/ # Streamlit Frontend
│ ├── streamlit_app.py # Main application
│ └── i18n.py # Internationalization
│
├── backend/ # FastAPI Backend
│ ├── main.py # Application entry
│ ├── core/
│ │ └── config.py # Configuration
│ ├── models/
│ │ ├── database.py # SQLAlchemy models
│ │ └── schemas.py # Pydantic schemas
│ ├── api/routes/
│ │ ├── data.py # Data management
│ │ ├── inference.py # Indicator inference
│ │ └── scrape.py # Web scraping
│ └── services/
│ └── scraper/ # Scraper implementations
│
├── core/ # Core Analysis Models
│ └── models/
│ ├── fiscal.py # Fiscal analysis
│ ├── regional.py # Regional analysis
│ ├── income.py # Income distribution
│ ├── industrial.py # Industrial structure
│ └── innovation.py # Innovation metrics
│
├── tests/ # Test Suite
├── docs/ # Documentation
└── scripts/ # Utility Scripts
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/indicators/ |
List all indicators |
POST |
/api/v1/inference/calculate |
Calculate indicator inference |
GET |
/api/v1/inference/available_indicators |
Get available indicators |
POST |
/api/v1/scrape/ |
Scrape data from source |
GET |
/api/v1/scrape/status |
Get scraper status |
GET |
/health |
Health check |
curl -X POST http://localhost:8001/api/v1/inference/calculate \
-H "Content-Type: application/json" \
-d '{
"input_indicators": {
"expenditure": 250000,
"revenue": 200000,
"gdp": 1200000
},
"target_indicator": "deficit_rate",
"method": "linear"
}'{
"predicted_value": 4.1667,
"predicted_unit": "%",
"confidence_interval": [3.9583, 4.375],
"method_used": "linear",
"input_indicators": {
"expenditure": 250000.0,
"revenue": 200000.0,
"gdp": 1200000.0
},
"target_indicator": "deficit_rate"
}# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=backend --cov-report=html
# Run specific test file
pytest tests/test_fiscal.py -vEnvironment variables (optional):
| Variable | Default | Description |
|---|---|---|
DATABASE_URL |
sqlite:///./national_stats.db |
Database connection |
API_PORT |
8001 |
Backend port |
CORS_ORIGINS |
* |
CORS allowed origins |
Contributions are welcome! Please read our Contributing Guide before submitting PRs.
# Install dev dependencies
pip install -r requirements.txt
pip install pytest pytest-cov black flake8
# Run linting
black backend/ app/ tests/
# Run tests
pytest tests/ -vThis project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- Official data sources: Ministry of Finance, National Bureau of Statistics, Customs Administration, People's Bank of China
- Built with: FastAPI, Streamlit, Plotly, SQLAlchemy, Pandas, NumPy
- Issue Tracker: https://github.com/your-repo/national_stats/issues
- Email: contact@example.com
National Economic Data Analysis Platform
Built for economists, researchers, and policy makers