Commit a7803072 authored by Tero Ojanen's avatar Tero Ojanen
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

.env.example

0 → 100644
+30 −0
Changes for .env.example: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
# General Configuration
TZ=Europe/Helsinki

# Data Fetcher Configuration
# Interval in seconds between data fetch cycles (default: 3600)
FETCHER_INTERVAL=3600
# Max worker threads for fetching (default: number of fetchers)
FETCHER_MAX_WORKERS=5
# Logging level (DEBUG, INFO, WARNING, ERROR)
LOG_LEVEL=INFO

# UI & LLM Configuration
USER_TIMEZONE=Europe/Helsinki
LLM_PROVIDER=openai  # "openai" or "custom"

# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-4o

# Custom LLM / vLLM Configuration
# LLM_API_URL=http://your-vllm-server:8000/v1
# LLM_API_KEY=your-custom-api-key

# Optional: Additional LLM Endpoints (up to 3)
# LLM_ENDPOINT_1_URL=http://localhost:8000/v1
# LLM_ENDPOINT_1_MODEL=llama3-8b
# LLM_ENDPOINT_1_KEY=dummy

# API Keys for Fetchers (if applicable in future)
# CURRENTLY NOT USED BY DUMMY FETCHERS

.gitignore

0 → 100644
+41 −0
Changes for .gitignore: 41 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Environment files
.env
.env.local
.env.*.local

# Python virtual environments
venv/
env/
ENV/
.venv/

# Python cache
__pycache__/
*.py[cod]
*$py.class
*.so

# Logs
logs/
*.log

# Data files
data-fetcher-project/data/*.csv
data-fetcher-project/archive/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Docker
.dockerignore

# Backup files
*.backup

LICENSE

0 → 100644
+21 −0
Changes for LICENSE: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
MIT License

Copyright (c) 2025 South-Eastern Finland University of Applied Sciences (Xamk)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

README.md

0 → 100644
+85 −0
Changes for README.md: 85 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Farm Energy Management System

This monorepo combines two Python services that share a single data directory:

1. **`data-fetcher-project/`** polls public and private APIs (energy prices, weather, SuomiConnect metering, Volter predictions) and writes the results into CSVs under `data/`, while rotating historical snapshots into `archive/`.
2. **`ui-project-v2/`** is the Gradio 5 powered dashboard serving operators in production.

Both services run under Python 3.12 and are orchestrated with Docker Compose for parity between local development and production use.

## Repository layout

```
.
├── data-fetcher-project/
│   ├── data/            # latest CSVs (volume-shared)
│   ├── archive/         # historical CSV backups
│   └── src/             # domain fetchers + common helpers
├── ui-project-v2/       # Main UI Application
│   ├── app/             # Gradio layout, config, and helpers
│   └── content/         # Operator-editable site context notes (EN/FI)
├── docker-compose.yml
└── .env.example
```

## Quick start

1. Create a `.env` in the repository root using `.env.example` as a template.
2. Install Docker + Docker Compose.
3. Bring everything up:

   ```bash
   docker-compose up --build
   ```

   The fetcher will populate `data-fetcher-project/data/` while the UI serves Gradio on <http://localhost:7860>.

### Local UI without Docker

```bash
cd ui-project-v2
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
DEBUG_PLOTS=1 python app.py  # listens on 7860
```

### One-off data ingestion

```bash
cd data-fetcher-project
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python main.py
```

### Test & lint shortcuts

- `cd ui-project-v2 && python -m pytest` – regression pass for the upgraded Gradio 5 stack.
- `docker-compose logs -f` – tail both services when validating changes inside containers.

## Configuration

The root `.env` file is loaded by both services. Key variables:

- `LLM_PROVIDER`, `OPENAI_API_KEY`, `OPENAI_MODEL`
- `LLM_API_URL`, `LLM_API_KEY`, `LLM_ENDPOINT_{N}_URL|NAME|MODEL|KEY`
- `USER_TIMEZONE` – used by the UI when rendering timestamps
- `FETCHER_INTERVAL`, `FETCHER_MAX_WORKERS`, `LOG_LEVEL`

All timestamps must remain in UTC inside stored CSVs; the UI converts to local time on display through `app/time_utils.py` and documents the exact observation times in the “Current Data” panel.

### Editable site context & operator notes

Static operational constraints shown to the LLM live in `ui-project/content/site_context_en.md` and `ui-project/content/site_context_fi.md`. Update those files whenever on-site limits change (e.g., CHP capacity, grid policies). The UI automatically picks the language that matches the current selection.

## Development workflows

- **Fetchers:** add a new `src/<domain>/fetch.py`, register it in `FETCHERS` within `data-fetcher-project/main.py`, and ensure the output schema remains backward compatible (update archives if not).
- **UI:** extend the modular helpers under `ui-project-v2/app/`. Keep `app.py` as a thin orchestration layer.
- **LLM prompts:** the context builder now computes a price severity scale, daylight conditions, and grid guidance. Reuse helpers in `app/context_builder.py` when expanding prompt content.
- **Testing / smoke checks:**
  - `docker-compose up` – end-to-end validation
  - `DEBUG_PLOTS=1 python app.py` – desktop UI run with additional diagnostics
  - Inspect `logs/` for service output when running via Docker
+19 −0
Changes for data-fetcher-project/Dockerfile: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
FROM python:3.12-slim

WORKDIR /app

# Copy only the requirements file to leverage Docker cache
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code
COPY . .

# Create directories for data and logs that will be mounted as volumes
RUN mkdir -p /app/data /app/archive

# This container will run the main.py script to fetch data.
# The command to run it periodically will be in the docker-compose.yml file.
CMD ["python", "main.py"]
Loading