Skip to content

badhope/national_stats

Repository files navigation

National Economic Data Analysis Platform (NEDAP)

Version Python License FastAPI Streamlit

A comprehensive economic data assessment and prediction system for researchers, economists, and policy makers.

FeaturesQuick StartArchitectureAPIContributingLicense


🌐 Language | 语言

English | 中文


📊 Features

Core Functionality

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

Data Sources

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

Inference Indicators

  • 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

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • Git

Installation

# 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

Running the Application

# Start backend (Terminal 1)
uvicorn backend.main:app --reload --port 8001

# Start frontend (Terminal 2)
streamlit run app/streamlit_app.py

Access Points

Service URL
Frontend http://localhost:8501
API Docs http://localhost:8001/docs
ReDoc http://localhost:8001/redoc
Health Check http://localhost:8001/health

🏗️ Architecture

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

📡 API Documentation

Main Endpoints

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

Example Request

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"
  }'

Example Response

{
  "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"
}

🧪 Testing

# 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 -v

🔧 Configuration

Environment variables (optional):

Variable Default Description
DATABASE_URL sqlite:///./national_stats.db Database connection
API_PORT 8001 Backend port
CORS_ORIGINS * CORS allowed origins

👥 Contributing

Contributions are welcome! Please read our Contributing Guide before submitting PRs.

Development Setup

# 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/ -v

📄 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.


🙏 Acknowledgments

  • 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

📬 Contact


National Economic Data Analysis Platform
Built for economists, researchers, and policy makers

About

A comprehensive economic data assessment and prediction system for researchers, economists, and policy makers.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors