An application that fetches hourly electricity prices, recommends the best time for a sauna session, and tracks electricity usage. It consists of a NodeJS backend and a React frontend.
-
Scheduled Data Fetching:
- Fetches electricity prices from a public API every day at 15:00 and stores the data in a PostgreSQL database.
-
API Endpoints:
GET /prices: Retrieve all electricity prices.GET /prices/today: Retrieve today's hourly electricity prices. WIPGET /prices/tomorrow: Retrieve tomorrow's hourly electricity prices. WIPGET /sauna/best-time: Suggest the best time to go to the sauna based on electricity prices. On weekends, the timeframe is 14-19, and on weekdays, it is 17-19.POST /usage: Add a new datapoint for the amount of electricity used at a specific time. WIPGET /usage/costs: Retrieve all datapoints with electricity usage and its cost. WIPPUT /usage/:id: Edit a specific electricity usage datapoint. WIPDELETE /usage/:id: Delete a specific electricity usage datapoint. WIP
-
Prisma ORM:
- Uses Prisma ORM to interact with the PostgreSQL database.
- Uses Prisma Migrate to manage database migrations.
-
PostgreSQL Database:
- Uses a PostgreSQL database to store electricity prices and electricity usage data.
-
Limitations
- API is NOT production ready. It is currentyl only meant for localhost usage and testing purposes.
- API does not have any authentication or authorization.
- API does not have any input validation.
-
Electricity Price Visualization:
- Display today's electricity prices as a line chart.
- Display tomorrow's electricity prices as a line chart.
- Switch views between today and tomorrow.
-
Sauna Time Recommendation:
- Show the best time to go to the sauna today and tomorrow based on electricity prices and specified timeframes.
-
User Interactions (WIP):
- Allow the user to input the amount of electricity used and the timeframe it was used.
- Display electricity usage as a list of cards showing the amount used, the timeframe, and the cost.
- Provide the option to delete specific electricity usage datapoints.
- Navigate to the backend directory.
- Install the required packages:
npm install
- Go to
/backend/dbdirectory and add DB_USER, DB_PASS, and DB_NAME environment variables to a .env file. - Add DATABASE_URL in the same .env file, which should be as follows:
postgresql://<DB_USER>:<DB_PASS>@localhost:5432/<DB_NAME> - Start the PostgreSQL container:
docker-compose up -d
- Run the migrations:
npx prisma migrate deploy
- Generate Prisma Client:
npx prisma generate
- Build the backend:
npm run build
- Create new user in the database:
npm run createuser
- Run the backend server:
npm start
NOTE: For more in-depth instructions on setting up the PostgreSQL database, please refer to the README.md file in the /backend/db directory.
- Navigate to the frontend directory.
- Install the required packages:
npm install
- Run the frontend server:
npm start
Additional features that are planned to be implemented in the future:
- Add authentication and authorization to the API.
- Add input validation to the API.
- Add input validation to the frontend.
- Add the ability to add new electricity usage datapoints.
- Add the ability to view electricity usage as a list of cards.
- Add the ability to edit and delete electricity usage datapoints.
- React Native mobile app
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.