A simple web application to analyze electricity prices and solar production data, with focus on negative price detection and cost analysis for solar producers in Sweden.
Quick Start โ | Live Demo (after running locally)
When you have solar panels, you often sell excess electricity back to the grid. But sometimes electricity prices go negative - meaning you actually pay to export your energy! This tool helps you:
- ๐ Analyze your production data - Upload your solar production CSV/Excel file
- ๐ธ Detect negative price periods - See when your export cost you money
- ๐ Visualize the impact - Interactive charts showing monthly patterns
- ๐ค Get AI insights (optional) - Swedish-language explanations of your analysis
- ๐พ Export results - Download detailed Excel reports
- ๐ No API keys required - Uses free Sourceful Price API
- ๐ Webapp interface - Simple drag-and-drop file upload
- ๐ธ๐ช Swedish electricity areas - Supports SE_1 through SE_4
- ๐ค Optional AI explanations - Add OpenAI key for AI-powered insights
- ๐ Visual analytics - Charts and metrics at a glance
- ๐พ Excel export - Detailed analysis export
- ๐ Easy deployment - Docker support included
- Python 3.12+
- uv package manager
# 1. Clone the repository
git clone https://github.com/srcfl/negative-price-calc.git
cd negative-price-calc
# 2. Install dependencies
uv sync
# 3. Start the webapp
uv run python app.pyOpen your browser and go to http://localhost:8080 ๐
That's it! No API keys needed for basic analysis.
Want AI-powered insights? Just add your OpenAI API key:
# Copy environment template
cp .env.example .env
# Edit .env and add: OPENAI_API_KEY=your_key_hereRestart the webapp and AI explanations will appear automatically!
# Build and run with docker-compose
docker-compose up --build
# Open http://localhost:8080Deploy to Railway with one click:
- Create new project on Railway
- Connect your GitHub repo
- Set root directory to
/(project root) - Add environment variables:
OPENAI_API_KEY(optional, for AI insights)CORS_ORIGINS(your frontend URL, e.g.,https://your-frontend.railway.app)
- Create another service in the same project
- Set root directory to
/frontend - Add environment variable:
NEXT_PUBLIC_API_URL(your backend URL, e.g.,https://your-backend.railway.app)
| Variable | Service | Description |
|---|---|---|
OPENAI_API_KEY |
Backend | Optional - enables AI explanations |
CORS_ORIGINS |
Backend | Frontend URL(s), comma-separated |
NEXT_PUBLIC_API_URL |
Frontend | Backend API URL |
- Upload your data: CSV or Excel file with solar production (hourly or daily)
- Select electricity area: SE_1, SE_2, SE_3, or SE_4
- Click "Analysera": Results appear in seconds
- Review insights: See negative price impact, timing losses, and more
- Export if needed: Download Excel report for deeper analysis
The tool intelligently handles various CSV/Excel formats. Your file should have:
- Timestamp/Date column: DateTime or date values
- Production column: Energy produced in kWh
Common column names are automatically detected (timestamp, date, production, kwh, etc.)
Try it out with sample files in data/samples/ directory!
negative-price-calc/
โโโ app.py # Flask webapp (start here!)
โโโ cli/ # Command-line interface
โ โโโ main.py # CLI entrypoint
โโโ core/ # Analysis engine
โ โโโ price_fetcher.py # Sourceful API integration
โ โโโ production_loader.py # CSV/Excel parser
โ โโโ price_analyzer.py # Core analysis logic
โโโ templates/ # HTML templates
โ โโโ index.html # Main webapp UI
โโโ data/ # Data storage
โโโ price_data.db # SQLite price cache
โโโ samples/ # Example files
- Backend: Flask + Python 3.12
- Price Data: Sourceful API (free, no key required)
- AI: OpenAI GPT (optional)
- Storage: SQLite for price caching
- Frontend: Modern HTML/CSS/JS with drag-and-drop
- SE_1: Northern Sweden (Luleรฅ) - Typically lowest prices
- SE_2: Central Sweden (Sundsvall)
- SE_3: Central Sweden (Stockholm)
- SE_4: Southern Sweden (Malmรถ) - Highest price volatility
- Total Production: Your solar output (kWh)
- Total Revenue: Income from electricity export
- Negative Price Hours: When export cost money
- Timing Loss: How much below market average you received
- Monthly Breakdown: Visual charts showing patterns
With OpenAI API key configured:
- Swedish-language explanation of your results
- Key recommendations
- Problem areas highlighted
Want command-line access instead of webapp?
# Analyze with CLI
uv run se-cli analyze your_file.csv --area SE_4 --json
# With AI explanations
uv run se-cli analyze your_file.csv --area SE_4 --json --ai-explainer
# Inspect file format
uv run se-cli inspect-production your_file.csvuv run pytestuv run black .
uv run isort .Contributions are welcome! This is an open source project for the solar community.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
Optional | Enables AI-powered explanations |
DATABASE_PATH |
Optional | Custom SQLite database path (default: data/price_data.db) |
CORS_ORIGINS |
Optional | Allowed frontend origins for CORS (default: http://localhost:3000) |
PORT |
Optional | Server port (default: 8080, Railway sets this automatically) |
NEXT_PUBLIC_API_URL |
Frontend | Backend API URL for Next.js frontend |
Note: Electricity price data comes from Sourceful API which requires no API key!
# Run on different port
uv run python -c "from app import app; app.run(host='0.0.0.0', port=5000)"- Check file size (max 16MB)
- Ensure valid CSV or Excel format
- Try with sample files in
data/samples/
- Verify your electricity area is correct
- Check that your file has proper date/production columns
- Use
se-cli inspect-productionto validate file format
- Sourceful Price API: https://docs.sourceful.energy/developer/price-api
- Nordic Energy Markets: https://www.nordpoolgroup.com/
- Swedish Energy Agency: https://www.energimyndigheten.se/
This project is licensed under the MIT License - see the LICENSE file for details.
- Price data powered by Sourceful Energy API
- Built for the solar producer community in Sweden
- Inspired by real challenges facing solar panel owners
- ๐ Bug reports: Open an issue
- ๐ก Feature requests: Start a discussion
- ๐ Questions: Check QUICKSTART.md or open an issue
Made with โค๏ธ for the solar energy community | GitHub