Create a web app, to help your local Municipality to track electricity usage per household. Each month the Municipality gives each household 50 units each for free. Households can topup if they need extra electricity.
The factory function is missing some methods and queries. Please sort that out.
Use the Problem Solving Template to clarify your thinking. Ensure to deploy you application to Travis and Heroku.
As you use appliances, your units will drop accordingly.
The factory function in electricity-meters.js
have the following methods. You need to implement them.
Function name | Description |
---|---|
streets |
List all the streets that we have records |
streetMeters |
for a given street show all the meters and their balances (use where clause) |
appliances |
List all appliances and their rates |
meterData |
For a given meterId, return all the data for it |
useElectricity |
allow a house to use electricity - use meterId and units |
lowestBalanceMeter |
return the meter with the lowest balance. Return the meter_id, balance, street_number and the street_name for the given meter. (order by, join, limit 1 ) |
highestBalanceStreet |
Return the street name & totalBalance for the street with the highest total balance (group by + sum + order by, limit 1 ) |
Extra things to try if you still have time left:
Function name | Description |
---|---|
totalStreetBalance |
returns the total balance for each street - this is the total electricity available to use in the whole street. Return a list street names and totals. |
topupElectricity |
buy electricity for a given meterId and units (use upate with where) |
Create a database called topups_db
in postgresql. Set it up so that your application can use it.
Please use the sql/db.sql
script to create your tables and to insert data into your database.
NOTE: - We have already created tables and data for you. You don't need to create any other tables.
Route name | Route type | Route description |
---|---|---|
/streets |
GET | Show a list of all the streets. This screen should be working if all your initial database setup is completed |
/appliances |
GET | Show all the appliances and their respective electricity usage rates. |
/meter/:street_id |
GET | Show a list of all the meters in a given street. |
/meter/use/:meter_id |
GET & POST | Create a screen where households can use electricity. Using electricity should decrease the balance in the table for the appropriate table. The users can select the appliance type for which electricity is used from a dropdown. |
Show this information on top of the /streets
route screen:
- the details of the meter with the lowest balance
- the balance of the street with the highest balance
Note: The routes that needs the meter_id
can be linked to from the /meter/:street_id
screen.
Extra things to try if you still have time left:
Route name | Route type | Route description |
---|---|---|
/street/balances |
GET | Create a screen that shows the total electricity balances available for each of the streets. Show the street name and the balance on the screen. Use a group by and a sum . |
/meter/use/:meter_id |
GET & POST | Create a screen where households can buy electricity. Buying electricity should increase the balance in the table for the appropriate table. |
Fix the failing unit tests in the /test/electricity-meters.test.js
file.
If your initial setup is done correctly you should have one passing unit test
Run the tests using npm test
.
Create Travis deploy and add a Travis badge to your readme file. Deploy your application to Heroku.
- Once you have setup your GitHub Repo and Problem Solving Template please complete this form: Electricity Assessment Links
- As soon as you have the App Deployment link, please update the form.
- We need all three links by latest 13h00
- We will review up to your final commit by 17h00.