{"id":26045132,"url":"https://github.com/imrlopez/wattsup","last_synced_at":"2026-04-13T12:01:58.417Z","repository":{"id":280732481,"uuid":"942984035","full_name":"iMrLopez/WattsUp","owner":"iMrLopez","description":"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. 🚗⚡","archived":false,"fork":false,"pushed_at":"2025-03-05T02:03:10.000Z","size":246,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T03:18:09.225Z","etag":null,"topics":["fastapi","postgresql","react"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iMrLopez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-05T01:54:45.000Z","updated_at":"2025-03-05T02:04:30.000Z","dependencies_parsed_at":"2025-03-05T03:18:10.665Z","dependency_job_id":"e0aecd44-524b-4c4c-83f4-09b84b177c20","html_url":"https://github.com/iMrLopez/WattsUp","commit_stats":null,"previous_names":["imrlopez/wattsup"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMrLopez%2FWattsUp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMrLopez%2FWattsUp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMrLopez%2FWattsUp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMrLopez%2FWattsUp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iMrLopez","download_url":"https://codeload.github.com/iMrLopez/WattsUp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242451437,"owners_count":20130399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","postgresql","react"],"created_at":"2025-03-07T19:31:50.996Z","updated_at":"2026-04-13T12:01:58.347Z","avatar_url":"https://github.com/iMrLopez.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"| ![WattsUp Logo](./assets/logo-nobg.png) | 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. 🚗⚡ |\n|--|--|\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Features](#features)\n- [Project Structure](#project-structure)\n- [Pre-requisites](#pre-requisites)\n- [Setup \u0026 Run](#setup--run)\n- [API Endpoints](#api-endpoints)\n  - [Estimate Cost](#estimate-cost)\n  - [Lookup Metadata](#lookup-metadata)\n  - [Companies with Tariffs](#companies-with-tariffs)\n- [Prolog Query Endpoints](#prolog-query-endpoints)\n- [Docker \u0026 Deployment](#docker--deployment)\n\n## Overview\nA 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:\n\n- A `/estimate` endpoint to calculate energy (kWh) and estimated cost (₡) based on battery capacity, vehicle age, charging duration, company and period.\n- Metadata endpoints to fetch available companies, periods, and detailed tariff tables.\n- A modern Next.js frontend with React \u0026 TypeScript for interactive user input and result display.\n\n## Features\n\n- **Energy Prediction**: Uses Prolog rules (`energy_required`, `charging_rate_value`) for kWh estimation.\n- **Cost Estimation**: Combines energy estimate with dynamic tariffs from the database via the `/estimate` endpoint.\n- **Metadata Lookup**: Single `/lookup` endpoint returns lists of companies and tariff periods.\n- **Detailed Tariffs**: `/companies-with-tariffs` returns structured tariff info by company and period.\n- **Prolog Integration**: Dynamic seeding of Prolog facts (battery_capacity, vehicle_age, charging_duration, tariffs) from PostgreSQL.\n- **Frontend**: Next.js + TypeScript + Tailwind CSS interactive form and modal components.\n- **Dockerized**: Full-stack setup with Docker Compose for consistent deployment.\n\n## Project Structure\n```\n├── backend\n│   ├── app\n│   │   ├── routers\n│   │   ├── rules\n│   │   ├── engine\n│   │   │   └── prolog_engine.py\n│   │   ├── models.py\n│   │   ├── database.py\n│   │   ├── config.py\n│   │   └── main.py\n│   ├── requirements.txt\n│   └── Dockerfile\n├── databaseDefinition\n│   ├── a_init_cars.sql\n│   ├── b_init_energy_facts.sql\n|   ├── c_init_energy_tarifss.sql\n│   └── view_definitions.sql\n├── frontend\n│   ├── components\n|   ├── models\n│   ├── pages\n│   ├── public\n│   ├── services\n│   ├── styles\n│   ├── utils\n│   ├── package.json\n│   └── tsconfig.json\n├── utils\n│   └── start_clean.sh\n├── docker-compose.yml\n├── .gitignore\n└── README.md\n```\n\n## Pre-requisites\n\n- **Docker Desktop** (for containerized deployment)\n- **Node.js** \u0026 **npm** (for local frontend dev)\n- **Python 3.9+** \u0026 **pip** (for local backend dev)\n\n## Setup \u0026 Run\n\n### Quick Start (Docker)\n```bash\n./utils/start_clean.sh       # Mac M1+ friendly\n# or:\ndocker-compose up --build    # builds and runs frontend, backend, DB\n```\n\n### Manual Installation\n\n#### Frontend\n```bash\ncd frontend\nenv: npm install\nnpm run dev\n# Access at http://localhost:3000\n```\n\n#### Backend\n```bash\ncd backend\npython -m venv venv \u0026\u0026 source venv/bin/activate\npip install -r requirements.txt\nuvicorn app.main:app --reload\n# Runs at http://localhost:8000\n```\n\n#### Database\n- Execute SQL scripts in `databaseDefinition/` to create tables and views.\n- Ensure `tariffs` table is populated with current rates.\n\n## API Endpoints\n\n### Estimate Cost\nCalculates energy and cost in one call.\n\n**POST** `/estimate`\n\n**Body** (JSON):\n```json\n{\n  \"battery_capacity\": 75.0,\n  \"vehicle_age\": 5.0,\n  \"charging_duration\": 2.0,\n  \"company\": \"CNFL\",\n  \"period\": \"Punta\"\n}\n```\n\n**Response**:\n```json\n{\n  \"energy_kwh\": 40.0,\n  \"estimated_cost\": 6278.40\n}\n```\n\n### Lookup Metadata\nFetch lists of valid companies and periods.\n\n**GET** `/lookup`\n\n**Response**:\n```json\n{\n  \"companies\": [\"CNFL\",\"ICE\"],\n  \"tariffs\": [\"Punta\",\"Valle\",\"Nocturno\"]\n}\n```\n\n### Companies with Tariffs\nReturns detailed tariff structure per company.\n\n**GET** `/companies-with-tariffs`\n\n**Response**:\n```json\n[\n  {\n    \"companyName\": \"CNFL\",\n    \"tariffs\": [\n      { \"periodName\": \"Punta\", \"costKwh\": 156.96 },\n      { \"periodName\": \"Valle\", \"costKwh\": 64.35 },\n      { \"periodName\": \"Nocturno\", \"costKwh\": 26.94 }\n    ]\n  },\n  {\n    \"companyName\": \"ICE\",\n    \"tariffs\": [\n      { \"periodName\": \"Punta\", \"costKwh\": 152.53 },\n      { \"periodName\": \"Valle\", \"costKwh\": 104.80 },\n      { \"periodName\": \"Nocturno\", \"costKwh\": 76.45 }\n    ]\n  }\n]\n```\n\n## Prolog Query Endpoints\n\n- **GET** `/query?rule=\u0026args=` \u0026rarr; raw Prolog query (useful for debugging).  \n  E.g. `/query?rule=energy_required`.\n- **POST** `/query/add_fact` \u0026rarr; dynamically assert a new Fact.\n\n## Docker \u0026 Deployment\n\nUse `docker-compose.yml` to orchestrate:\n- **frontend** (Next.js)\n- **backend** (FastAPI + Prolog)\n- **postgres**\n\n```bash\ndocker-compose up --build\\```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrlopez%2Fwattsup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimrlopez%2Fwattsup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrlopez%2Fwattsup/lists"}