Skip to content

nydiokar/bg_food_prices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿž Bulgarian Food Price Intelligence Suite

A comprehensive food price monitoring and analysis system for Bulgaria, providing market signals, trend analysis, and price intelligence across retail and wholesale markets.

Market Overview Market Overview with national food price trends and data quality indicators

๐Ÿš€ Quick Start (New Machine Setup)

Prerequisites

  • Python 3.8+
  • Git
  • Windows PowerShell (or Command Prompt)

1. Clone & Setup Environment

Option A: Automated Setup (Recommended)

# Clone the repository
git clone https://github.com/nydiokar/bg_food_prices.git
cd products-bg

# Run automated setup script
# For Windows Command Prompt:
setup.bat

# For PowerShell:
.\setup.ps1

Option B: Manual Setup

# Clone the repository
git clone <your-repo-url>
cd products-bg

# Create virtual environment
python -m venv .venv

# Activate virtual environment
.venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Data Setup Options

Option A: Use Pre-committed Database (Recommended for Development)

# The SQLite database is already included in the repo
# No additional setup needed - you can start the app immediately
streamlit run src/app.py

Option B: Fetch Fresh Data (First Time Setup)

# Harvest all historical data (one call per product, full history per payload)
python -m src.harvest_all

# For incremental updates later:
python -m src.update_incremental

3. Launch the Application

# Start the Streamlit web app
streamlit run src/app.py

# Or run analytics directly
python -m src.analytics.run_all

๐Ÿ“Š What This System Does

Data Collection

  • Source: Bulgarian Ministry of Agriculture food price monitoring system
  • Frequency: Weekly updates
  • Products: 46+ food items (bread, milk, meat, vegetables, etc.)
  • Markets: Retail and wholesale prices across Bulgarian cities
  • Filters Available: Location, bulk location, supply chain, market type

Analytics & Intelligence

  • Market Signals: Product and city watchlists for price stress
  • Basket Index: National and city-level food price trends (base=100)
  • Margin Analysis: Retail vs. wholesale profit margins
  • Anomaly Detection: Unusual weekly price movements
  • Correlation Analysis: City and product price relationships
  • Data Quality Assessment: Coverage, completeness, and reliability metrics

๐Ÿ“ˆ Understanding the Basket Index System

What is the Basket Index?

The Basket Index is a composite measure that tracks how food prices change over time across Bulgaria. Think of it as a "food price thermometer" that shows whether prices are going up or down nationally.

Key Terms Explained:

๐ŸŽฏ Baseline (100)

  • What it is: The starting point for all price comparisons
  • When it was set: At the beginning of our data collection period
  • What it means: When the index = 100, food prices are at their "normal" level
  • Why 100: It's easier to understand "108.4" means "8.4% higher than normal" than dealing with absolute price values

๐Ÿ“Š Current Index

  • What it is: The current value of the food price basket
  • Example: 108.4 means food prices are currently 8.4% higher than the baseline
  • How it's calculated: Weighted average of all product prices, normalized to the baseline period
  • What it tells us: Whether food is getting more expensive or cheaper right now

๐Ÿ“ˆ vs Baseline

  • What it is: The percentage change from baseline to current
  • Example: +8.4% means prices have increased by 8.4% since the baseline period
  • Positive values: Food is getting more expensive
  • Negative values: Food is getting cheaper
  • Zero: Prices are exactly at baseline levels

Real-World Example:

  • Baseline (100): In January 2024, a typical food basket cost 100 BGN
  • Current Index (108.4): Today, the same basket costs 108.4 BGN
  • vs Baseline (+8.4%): Food prices have increased by 8.4% since January 2024

Why This Matters:

  • Inflation tracking: See if food prices are rising faster than general inflation
  • Regional comparison: Compare how different cities perform against the national baseline
  • Trend analysis: Identify if price increases are accelerating or stabilizing
  • Policy insights: Help understand the impact of economic policies on food affordability

๐Ÿ–ผ๏ธ App Screenshots

Market Signals & Hot Products

Market Signals Product watchlist showing risk scores, trends, and human-readable risk explanations

City Alerts & Price Patterns

City Alerts City alerts with price premiums, unusual products percentage, and risk breakdowns

Price Anomalies Detection

Price Anomalies Weekly price anomaly detection with severity indicators and percentage changes

๐Ÿ—๏ธ Project Structure

products-bg/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app.py                 # Streamlit web application
โ”‚   โ”œโ”€โ”€ harvest_all.py         # Initial data harvesting
โ”‚   โ”œโ”€โ”€ update_incremental.py  # Incremental updates
โ”‚   โ”œโ”€โ”€ fetch.py               # HTTP request handling
โ”‚   โ”œโ”€โ”€ normalize.py           # Data transformation
โ”‚   โ”œโ”€โ”€ ingest.py              # Database insertion
โ”‚   โ””โ”€โ”€ analytics/
โ”‚       โ”œโ”€โ”€ metrics.py         # Statistical calculations
โ”‚       โ”œโ”€โ”€ signals.py         # Market signal generation
โ”‚       โ””โ”€โ”€ run_all.py         # Analytics orchestration
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ foodprice.sqlite       # Main database (committed to repo)
โ”‚   โ”œโ”€โ”€ raw/                   # Raw JSON responses
โ”‚   โ””โ”€โ”€ exports/               # Processed CSV/Parquet files
โ”œโ”€โ”€ assets/                    # App screenshots and visuals
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ””โ”€โ”€ README.md                  # This file

๐Ÿ”„ Development Workflow

Daily Development

# Activate environment
.venv\Scripts\activate

# Make code changes
# Test the app
streamlit run src/app.py

# Run analytics tests
python test_phase2_completion.py

Data Updates

# When you need fresh data (optional)
python -m src.update_incremental

# Or full refresh (rarely needed)
python -m src.harvest_all

Committing Changes

# The SQLite database is included in commits
# This means new team members get the data immediately
git add .
git commit -m "Update analytics and data"
git push

๐Ÿ“ˆ Key Features

Market Overview

  • National food price trend visualization
  • Data quality indicators
  • Coverage metrics (products, cities, market types)

Market Signals

  • Hot Products: Products with unusual price activity
  • City Alerts: Cities with price stress patterns
  • Risk scoring and human-readable explanations

Deep Dive Analysis

  • Product Analysis: Price trends, margins, percentiles
  • City Analysis: Basket indices, product mix
  • Anomalies: Weekly price change detection

๐Ÿ› ๏ธ Technical Details

Database Schema

  • facts: Price records with product, city, date, market type
  • dims: Product and city metadata
  • Indexes: Optimized for time-series queries

Data Processing Pipeline

  1. Fetch: HTTP requests to ministry API
  2. Normalize: Transform raw JSON to structured format
  3. Ingest: Insert into SQLite with validation
  4. Analyze: Generate metrics, signals, and insights

Performance Considerations

  • Caching: Streamlit data caching for app performance
  • Lazy Loading: Data loaded only when needed
  • Optimized Queries: Efficient SQL for large datasets

๐Ÿšจ Troubleshooting

Common Issues

App Won't Start

# Check if database exists
ls data/foodprice.sqlite

# If missing, fetch data first
python -m src.harvest_all

Import Errors

# Ensure virtual environment is activated
.venv\Scripts\activate

# Reinstall dependencies
pip install -r requirements.txt

Data Quality Issues

  • Check the Data Quality Assessment in the app
  • Run python test_phase2_completion.py to verify analytics
  • Review logs in data/exports/_failures.log

Getting Help

  • Check the app's Data Quality Assessment section
  • Review test logs for specific error messages
  • Ensure all dependencies are installed correctly

๐Ÿ”ฎ Future Enhancements

Phase 3 (Planned)

  • Configurable parameters and backtesting
  • Advanced correlation analysis
  • Export functionality for reports
  • API endpoints for external integration

Data Expansion

  • Additional types of filters
  • More granular geographic coverage
  • Increase coverage of metrics
  • Real-time price feeds

๐Ÿ“ License & Attribution

Data source: Bulgarian Ministry of Economy and Industry price monitoring system Analysis and visualization: Custom analytics suite


Note: The SQLite database (data/foodprice.sqlite) is committed to the repository to provide immediate access to historical data for new team members and development environments. This eliminates the need for constant data fetching during development while maintaining the ability to update data when needed.

About

Food price monitoring and analysis system for Bulgaria based on official data

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published