Skip to content

Latest commit

 

History

History
124 lines (73 loc) · 4.49 KB

File metadata and controls

124 lines (73 loc) · 4.49 KB

CrateDB Offshore Wind Farms Demo: Python

Introduction

Follow the instructions below to configure and run the Python implementation of this project. You'll need to have completed the instructions in the main README first and should have created a CrateDB database and loaded the example data into it.

Configuring the Database Connection

You'll need to configure the project to talk to your CrateDB database.

The first step is to create a .env file in which to store your database credentials:

cd python
cp env.example .env

The next step depends on whether you chose the cloud or local option...

Cloud Option

Use your text editor / IDE to open the file .env.

The file's contents should look like this:

CRATEDB_URL=http://crate:@localhost:4200
PORT=8000

Edit the value of the key CRATEDB_URL to include your cloud database credentials. The format is:

https://username:password@hostname:4200

For example, if your host name is my-cluster.gke1.us-central1.gcp.cratedb.net, username is admin and password is sdfW234fwfTY^f then your URL should look like this:

https://admin:sdfW234fwfTY^[email protected]:4200

Save your changes.

Local Option

The project comes pre-configured to expect CrateDB to be at http://127.0.0.1:4200 so there's nothing to do here.

Preparing a Virtual Environment

You should create and activate a Python Virtual Environment to install this project's dependencies into. To do this, run the following commands:

python -m venv venv
. ./venv/bin/activate

Now install the dependencies that this project requires:

pip install -r requirements.txt

Running the Project

Start the application like this:

python app.py

Once you have the server running, point your browser at port 8000 and you should see the map front end:

http://localhost:8000/

Interacting with the Project

When the project is first loaded, it displays a map of the UK with a blue marker for each wind farm. Click on one of these markers to show a pop-up containing details about that wind farm's latest and monthly average outputs, as well as a table with the running total of the output for each hour of the most recent day in the dataset.

The user has clicked on the marker for Rampion wind farm

Next, zoom in a bit until the wind farm markers are replaced with polygons showing the boundaries of each wind farm. Click on one of the polygons to see a marker containing data about the maximum output of the wind farm for the 10 most recent days in the dataset.

The user has clicked on the polygon for Triton Knoll wind farm

Finally, zoom in some more to see the locations of individual turbines in the wind farms. These markers are not clickable.

Zoomed in further to show the turbine locations of several wind farms

Try out the API Calls

You can see the raw that that the front end uses by visiting the API URLs whilst the application is running:

  • When the page initially loads, it calls this endpoint to get data about all of the wind farms:

http://localhost:8000/api/windfarms

  • Clicking on a wind farm marker on the map loads additional data for that wind farm, using the wind farm's ID. Here's an example for North Hoyle (NHOYW-1):

http://localhost:8000/api/latest/NHOYW-1

  • When you click on a wind farm marker, the average output percentage for the month is returned from this endpoint. The parameters are the wind farm ID (NHOY-1 here) and the timestamp for the 1st of the month (1727740800000 here). Example:

http://localhost:8000/api/avgpctformonth/NHOYW-1/1727740800000

  • Cumulative output for the most recent day in the dataset is also displayed when you click on a wind farm marker. Parameters for this endpoint are also the wind farm ID (NHOY-1 here) and the timestamp for midnight for the day you want data for (1730073600000 here). Example:

http://localhost:8000/api/outputforday/NHOYW-1/1730073600000

  • Clicking on the polygon for a wind farm loads further data for that wind farm, showing the maximum output percentage for a number of days. Here's an example for Teeside (TEES-1) for 10 days:

http://localhost:8000/api/dailymaxpct/TEES-1/10

Shutting Down

To stop the application, press Ctrl-C in the terminal window that you started it from.

If you're using Docker to run CrateDB, stop the container like so:

docker compose down