Skip to content

A machine learning-powered system for predicting the impact of electric vehicle (EV) charging on electricity costs. Users can input their consumption data, EV model, and tariff details to receive personalized cost estimates. Built with FastAPI, React, and PostgreSQL. πŸš—βš‘

Notifications You must be signed in to change notification settings

iMrLopez/WattsUp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WattsUp Logo A machine learning‑powered system for predicting the impact of electric vehicle (EV) charging on electricity costs. Users input their consumption data, EV model, and tariff details to receive personalized cost estimates. Built with FastAPI, Prolog, React (Next.js) and PostgreSQL. πŸš—βš‘

Table of Contents

Overview

A CLI and web‑based tool that leverages rule‑based Prolog inference combined with machine learning to estimate how much an EV charging session will add to your electricity bill. It provides:

  • A /estimate endpoint to calculate energy (kWh) and estimated cost (β‚‘) based on battery capacity, vehicle age, charging duration, company and period.
  • Metadata endpoints to fetch available companies, periods, and detailed tariff tables.
  • A modern Next.js frontend with React & TypeScript for interactive user input and result display.

Features

  • Energy Prediction: Uses Prolog rules (energy_required, charging_rate_value) for kWh estimation.
  • Cost Estimation: Combines energy estimate with dynamic tariffs from the database via the /estimate endpoint.
  • Metadata Lookup: Single /lookup endpoint returns lists of companies and tariff periods.
  • Detailed Tariffs: /companies-with-tariffs returns structured tariff info by company and period.
  • Prolog Integration: Dynamic seeding of Prolog facts (battery_capacity, vehicle_age, charging_duration, tariffs) from PostgreSQL.
  • Frontend: Next.js + TypeScript + Tailwind CSS interactive form and modal components.
  • Dockerized: Full-stack setup with Docker Compose for consistent deployment.

Project Structure

β”œβ”€β”€ backend
β”‚   β”œβ”€β”€ app
β”‚   β”‚   β”œβ”€β”€ routers
β”‚   β”‚   β”œβ”€β”€ rules
β”‚   β”‚   β”œβ”€β”€ engine
β”‚   β”‚   β”‚   └── prolog_engine.py
β”‚   β”‚   β”œβ”€β”€ models.py
β”‚   β”‚   β”œβ”€β”€ database.py
β”‚   β”‚   β”œβ”€β”€ config.py
β”‚   β”‚   └── main.py
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”œβ”€β”€ databaseDefinition
β”‚   β”œβ”€β”€ a_init_cars.sql
β”‚   β”œβ”€β”€ b_init_energy_facts.sql
|   β”œβ”€β”€ c_init_energy_tarifss.sql
β”‚   └── view_definitions.sql
β”œβ”€β”€ frontend
β”‚   β”œβ”€β”€ components
|   β”œβ”€β”€ models
β”‚   β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ public
β”‚   β”œβ”€β”€ services
β”‚   β”œβ”€β”€ styles
β”‚   β”œβ”€β”€ utils
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”œβ”€β”€ utils
β”‚   └── start_clean.sh
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .gitignore
└── README.md

Pre-requisites

  • Docker Desktop (for containerized deployment)
  • Node.js & npm (for local frontend dev)
  • Python 3.9+ & pip (for local backend dev)

Setup & Run

Quick Start (Docker)

./utils/start_clean.sh       # Mac M1+ friendly
# or:
docker-compose up --build    # builds and runs frontend, backend, DB

Manual Installation

Frontend

cd frontend
env: npm install
npm run dev
# Access at http://localhost:3000

Backend

cd backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload
# Runs at http://localhost:8000

Database

  • Execute SQL scripts in databaseDefinition/ to create tables and views.
  • Ensure tariffs table is populated with current rates.

API Endpoints

Estimate Cost

Calculates energy and cost in one call.

POST /estimate

Body (JSON):

{
  "battery_capacity": 75.0,
  "vehicle_age": 5.0,
  "charging_duration": 2.0,
  "company": "CNFL",
  "period": "Punta"
}

Response:

{
  "energy_kwh": 40.0,
  "estimated_cost": 6278.40
}

Lookup Metadata

Fetch lists of valid companies and periods.

GET /lookup

Response:

{
  "companies": ["CNFL","ICE"],
  "tariffs": ["Punta","Valle","Nocturno"]
}

Companies with Tariffs

Returns detailed tariff structure per company.

GET /companies-with-tariffs

Response:

[
  {
    "companyName": "CNFL",
    "tariffs": [
      { "periodName": "Punta", "costKwh": 156.96 },
      { "periodName": "Valle", "costKwh": 64.35 },
      { "periodName": "Nocturno", "costKwh": 26.94 }
    ]
  },
  {
    "companyName": "ICE",
    "tariffs": [
      { "periodName": "Punta", "costKwh": 152.53 },
      { "periodName": "Valle", "costKwh": 104.80 },
      { "periodName": "Nocturno", "costKwh": 76.45 }
    ]
  }
]

Prolog Query Endpoints

  • GET /query?rule=&args= β†’ raw Prolog query (useful for debugging).
    E.g. /query?rule=energy_required.
  • POST /query/add_fact β†’ dynamically assert a new Fact.

Docker & Deployment

Use docker-compose.yml to orchestrate:

  • frontend (Next.js)
  • backend (FastAPI + Prolog)
  • postgres
docker-compose up --build\```

About

A machine learning-powered system for predicting the impact of electric vehicle (EV) charging on electricity costs. Users can input their consumption data, EV model, and tariff details to receive personalized cost estimates. Built with FastAPI, React, and PostgreSQL. πŸš—βš‘

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •