Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

ThoughtWorksInc/developer-joyofenergy-Python

Repository files navigation

PowerDale is a small town with around 100 residents. Most houses have a smart meter installed that can save and sendinformation about how much power a house is drawing/using.

There are three major providers of energy in town that charge different amounts for the power they supply.

  • Dr Evil's Dark Energy
  • The Green Eco
  • Power for Everyone

Introducing JOI Energy

JOI Energy is a new start-up in the energy industry. Rather than selling energy they want to differentiate themselvesfrom the market by recording their customers' energy usage from their smart meters and recommending the best supplier tomeet their needs.

You have been placed into their development team, whose current goal is to produce an API which their customers andsmart meters will interact with.

Unfortunately, two members of the team are on annual leave, and another one has called in sick! You are left withanother ThoughtWorker to progress with the current user stories on the story wall. This is your chance to make an impacton the business, improve the code base and deliver value.

Story Wall

At JOI energy the development team use a story wall or Kanban board to keep track of features or "stories" as they areworked on.

The wall you will be working from today has 7 columns:

  • Backlog
  • Ready for Dev
  • In Dev
  • Ready for Testing
  • In Testing
  • Ready for sign off
  • Done

Examples can be foundherehttps://leankit.com/learn/kanban/kanban-board/

Users

To trial the new JOI software 5 people from the JOI accounts team have agreed to test the service and share their energydata.

UserSmart Meter IDPower Supplier
Sarahsmart-meter-0Dr Evil's Dark Energy
Petersmart-meter-1The Green Eco
Charliesmart-meter-2Dr Evil's Dark Energy
Andreasmart-meter-3Power for Everyone
Alexsmart-meter-4The Green Eco

These values are used in the code and in the following examples too.

Requirements

The project requiresPython 3.12 or higher and thePoetry package manager.

Useful Python commands

Installation

After installing poetry, install the project dependencies with:

poetry install --with ci,tests

This will install main dependencies together with optional ones.For more information seeoptional groups settings.

Run the tests

Run all tests

poetry run pytest

Run the application

Run the application which will be listening on port8020.

poetry run python app.py

Pre-commit hooks

The project is offeringpre-commit hooks, please install them via

pre-commit install

GitHub Actions

Each commit in the main branch will trigger a pipeline which will run unit tests and different linting tools.When successful it will also containerize the application, finally its scans the docker image for vulnerabilities withTrivy.

Building Docker Image

The application can be containerized by using:

docker build -t joy-energy .

Building Docker image

Once the docker image is built, it can be run with:

docker run -p 8020:8020 joy-energy

API

Below is a list of API endpoints with their respective input and output. Please note that the application needs to berunning for the following endpoints to work. For more information about how to run the application, please refertorun the application section above.

Autogenerated documentations

The application will automatically generate documentations and provide them under:

Store Readings

Endpoint

POST /readings/store

Example of body

{"smartMeterId":<smartMeterId>,"electricityReadings": [    {"time":<timestamp>,"reading":<reading>    }  ]}

Parameters

ParameterDescription
smartMeterIdOne of the smart meters' id listed above
timeThe date/time (as epoch) when thereading was taken
readingThe consumption inkW at thetime of the reading

Example readings

Date (GMT)Epoch timestampReading (kW)
2020-11-29 8:0016066368000.0503
2020-11-29 8:0116066368600.0621
2020-11-29 8:0216066369200.0222
2020-11-29 8:0316066369800.0423
2020-11-29 8:0416066370400.0191

In the above example, the smart meter sampled readings, inkW, every minute. Note that the reading is inkW andnotkWH, which means that each reading represents the consumption at the reading time. If no power is being consumedat the time of reading, then the reading value will be0. Given that0 may introduce new challenges, we can assumethat there is always some consumption, and we will never have a0 reading value. These readings are then sent by thesmart meter to the application using REST. There is a service in the application that calculates thekWH from thesereadings.

The following POST request, is an example request using CURL, sends the readings shown in the table above.

curl \  -X POST \  -v \  -H "Content-Type: application/json" \  "http://localhost:8020/readings/store" \  -d '{"smartMeterId":"smart-meter-0","electricityReadings":[{"time":1606636800,"reading":0.0503},{"time":1606636860,"reading":0.0621},{"time":1606636920,"reading":0.0222},{"time":1606636980,"reading":0.0423},{"time":1606637040,"reading":0.0191}]}'

The above command will return the submitted readings.

{"electricityReadings": [    {"reading":0.0503,"time":1606636800    },    {"reading":0.0621,"time":1606636860    },    {"reading":0.0222,"time":1606636920    },    {"reading":0.0423,"time":1606636980    },    {"reading":0.0191,"time":1606637040    }  ],"smartMeterId":"smart-meter-0"}

Get Stored Readings

Endpoint

GET /readings/read/<smartMeterId>

Parameters

ParameterDescription
smartMeterIdOne of the smart meters' id listed above

Retrieving readings using CURL

curl "http://localhost:8020/readings/read/smart-meter-0"

Example output

[  {"reading":0.0503,"time":1606636800  },  {"reading":0.0621,"time":1606636860  },  {"reading":0.0222,"time":1606636920  },  {"reading":0.0423,"time":1606636980  },  {"reading":0.0191,"time":1606637040  },  {"reading":0.988,"time":989707945  },  {"reading":0.402,"time":992419009  },  {"reading":0.785,"time":1006196973  },  {"reading":0.327,"time":989837737  },  {"reading":0.485,"time":1003722501  }]

View Current Price Plan and Compare Usage Cost Against all Price Plans

Endpoint

GET /price-plans/compare-all/<smartMeterId>

Parameters

ParameterDescription
smartMeterIdOne of the smart meters' id listed above

Retrieving readings using CURL

curl "http://localhost:8020/price-plans/compare-all/smart-meter-0"

Example output

{"pricePlanComparisons": [    {"price-plan-2":1.8573933524727018e-06    },    {"price-plan-1":3.7147867049454036e-06    },    {"price-plan-0":1.8573933524727016e-05    }  ],"pricePlanId":"price-plan-0"}

View Recommended Price Plans for Usage

Endpoint

GET /price-plans/recommend/<smartMeterId>[?limit=<limit>]

Parameters

ParameterDescription
smartMeterIdOne of the smart meters' id listed above
limit(Optional) limit the number of plans to be displayed

Retrieving readings using CURL

curl "http://localhost:8020/price-plans/recommend/smart-meter-0?limit=2"

Example output

[  {"price-plan-2":1.8573933524727018e-06  },  {"price-plan-1":3.7147867049454036e-06  }]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp