Coder Social home page Coder Social logo

dianaow / power-gen-dashboard Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1006 KB

Svelte/D3.js/Flask: Visualizing power generation data by fuel source

Procfile 0.09% HTML 1.39% Svelte 74.19% CSS 0.54% JavaScript 2.10% Python 21.70%
d3js svelte data-visualization dataviz

power-gen-dashboard's Introduction

A web application to visualize power generation for different fuel sources

Technologies: Python and Flask for the backend API, JavaScript and Svelte for the UI

The dataset comprises power generation data categorized by type of fuel and provided on an hourly basis for four European countries: Germany, Austria, Denmark, and France.

I explored and wrangled the data in Python so that it can be in the correct structure to render easily as a stacked area chart with D3.js on the frontend (Svelte). I calculated the aggregated daily generation for each type of fuel and stored the results. I also categorized the fuel sources into renewables and non-renewables and then calculated aggregated daily and monthly electricity generation from these two categories. An API route is set up in Flask to transmit these datasets to the frontend.

A stacked area chart is chosen to represent the daily data to make it easy to compare the relative proportions of different fuel sources at any given point in time. The height of each stack represents the total for that day, and the segments within the stack show the contribution of each fuel source to the total.

A dropdown menu allows the user to select different countries from the dataset. When the user selects a country, both charts update automatically to reflect the selected country's power generation data.


Stacked area chart with tooltips created with D3.js

Stacked area chart with tooltips created with D3.js


Aggregated daily electricity generation from fuel sources (%)

Aggregated daily electricity generation from fuel sources (%)


Interactivity: Click on a legend item to highlight the fuel source

Interactivity: Click on a legend item to highlight the fuel source

Backend: Flask

  1. Navigate to the server folder. Create a Python virtual environment where the dependencies for this project will be installed.
cd server
python3 -m venv venv
  1. Activate the environment and install all the packages available in the requirement.txt file.
source venv/bin/activate
pip install -r ./requirements.txt
  1. If a .env file is not present in the server folder, create one to store the private API key, which is required to extract data from the API
  API_KEY=XXXXXXXXXX
  1. Run the server
flask run -h localhost -p 3000

Frontend: Svelte

  1. Open a new terminal tab and navigate to the client folder. Install the dependencies
cd client
npm install
  1. Run the command below to build the app and have the Vite build tool watch for changes
npm run autobuild
  1. View the app on http://localhost:3000/

Note: I have decided not to name the backend and front end files separately with the naming convention specified in the document, because of the interconnectedness of the two.

power-gen-dashboard's People

Contributors

dianaow avatar

Stargazers

Marc G avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.