Code Monkey home page Code Monkey logo

energy-consumption's Introduction

energy-consumption

A system that allows to receive and collect data about energy consumption from different villages.

Installation

After downloading repository you need to do some configurations to start the project.

Creating user and database in MYSQL

For this run the following SQL:

create database energy_consumption;
create user 'username'@'%' identified by 'password';
use energy_consumption;
grant all on energy_consumption.* to 'username'@'%';

If you change 'username' and 'password' in the above code, make sure to update src/main/resources/application.properties with the same data

Run the application

Run the following lines in commmand prompt with directory set to this project.

mvnw clean package
java -jar target/energy-consumption-0.0.1-SNAPSHOT.jar

(Optional) You can fill the database with fake data

For testing the system, you can fill the database with fake data. You need to run the following sql in MYSQL

use energy_consumption;
insert into village(name) values("Abcd");
insert into village(name) values("Dabs");
insert into village(name) values("Vent");
insert into village(name) values("Vete");
insert into village(name) values("Vetera");
insert into village(name) values("Venore");
insert into village(name) values("Ventore");
insert into counter(village_id, id) values(1,101);
insert into counter(village_id, id) values(1,102);
insert into counter(village_id, id) values(1,103);
insert into counter(village_id, id) values(1,104);
insert into counter(village_id, id) values(2,105);
insert into counter(village_id, id) values(2,106);
insert into counter(village_id, id) values(2,107);
insert into counter(village_id, id) values(2,108);
insert into counter(village_id, id) values(3,109);
insert into counter(village_id, id) values(3,110);
insert into counter(village_id, id) values(4,111);
insert into counter(village_id, id) values(4,112);
insert into consumption(amount, date_time, counter_id) values(0, '2020-06-05 00:04:22.426991', 101);
insert into consumption(amount, date_time, counter_id) values(10000.0, '2020-06-05 5:04:22.426991', 101);
insert into consumption(amount, date_time, counter_id) values(10500.0, '2020-06-06 10:04:22.426991', 101);
insert into consumption(amount, date_time, counter_id) values(0, '2020-06-05 01:04:22.426991', 102);
insert into consumption(amount, date_time, counter_id) values(20000.0, '2020-06-05 06:04:22.426991', 102);
insert into consumption(amount, date_time, counter_id) values(10000.0, '2020-06-05 13:04:22.426991', 102);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 02:04:22.426991', 103);
insert into consumption(amount, date_time, counter_id) values(15000.0, '2020-06-05 07:04:22.426991', 103);
insert into consumption(amount, date_time, counter_id) values(10300.0, '2020-06-05 14:04:22.426991', 103);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 01:04:22.426991', 104);
insert into consumption(amount, date_time, counter_id) values(13000.0, '2020-06-05 07:04:22.426991', 104);
insert into consumption(amount, date_time, counter_id) values(15000.0, '2020-06-05 09:04:22.426991', 104);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 03:04:22.426991', 105);
insert into consumption(amount, date_time, counter_id) values(1200.0, '2020-06-05 06:04:22.426991', 105);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 10:04:22.426991', 106);
insert into consumption(amount, date_time, counter_id) values(15000.0, '2020-06-05 00:04:22.426991', 106);
insert into consumption(amount, date_time, counter_id) values(10000.0, '2020-06-05 03:04:22.426991', 106);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 15:04:22.426991', 107);
insert into consumption(amount, date_time, counter_id) values(10020.0, '2020-06-04 15:04:22.426991', 107);
insert into consumption(amount, date_time, counter_id) values(5000.0, '2020-06-05 00:04:22.426991', 107);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 04:04:22.426991', 108);
insert into consumption(amount, date_time, counter_id) values(1200.0, '2020-06-04 16:04:22.426991', 108);
insert into consumption(amount, date_time, counter_id) values(1080.0, '2020-06-04 23:04:22.426991', 108);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 10:04:22.426991', 109);
insert into consumption(amount, date_time, counter_id) values(7000.0, '2020-06-05 00:04:22.426991', 109);
insert into consumption(amount, date_time, counter_id) values(2000.0, '2020-06-05 05:04:22.426991', 109);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 09:04:22.426991', 110);
insert into consumption(amount, date_time, counter_id) values(10800.0, '2020-06-05 02:04:22.426991', 110);
insert into consumption(amount, date_time, counter_id) values(1300.0, '2020-06-05 09:04:22.426991', 110);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 15:04:22.426991', 111);
insert into consumption(amount, date_time, counter_id) values(13000.8, '2020-06-04 20:04:22.426991', 111);
insert into consumption(amount, date_time, counter_id) values(10500.0, '2020-06-05 05:04:22.426991', 111);
insert into consumption(amount, date_time, counter_id) values(0.0, '2020-06-05 09:04:22.426991', 112);
insert into consumption(amount, date_time, counter_id) values(10850.0, '2020-06-05 13:04:22.426991', 112);
insert into consumption(amount, date_time, counter_id) values(1800.0, '2020-06-05 15:04:22.426991', 112);

Usage

Adding villages

Request example

POST http://localhost:8080/villages
Content-type: application/json
RequestBody
{
    "name": "VillageName"
}

Response example

{
    "id": 8,
    "name": "VillageName",
    "counters": []
}

Adding counters

Request example

POST http://localhost:8080/counters
Content-type: application/json
RequestBody
{
	"id":114,
	"villageId":4
}

Response example

{
    "id": 114,
    "villageName": "Vete"
}

Adding consumption

Request example

POST http://localhost:8080/counter_callback
Content-type: application/json
RequestBody
{
	"counter_id":103,
	"amount":10000.123
}

Response example

{
    "id": 38,
    "dateTime": "2020-06-06T08:50:53.0574662",
    "amount": 10000.123
}

Getting counter

Request example

GET http://localhost:8080/counters/102
Content-type: application/json

Response example

{
    "id": 102,
    "villageName": "Abcd"
}

Getting consumption report

Request example

GET http://localhost:8080/consumption_report?duration=36h
Content-type: application/json

Response example

[
    {
        "villageName": "Abcd",
        "consumption": 113800.123046875
    },
    {
        "villageName": "Dabs",
        "consumption": 32280.0
    },
    {
        "villageName": "Vent",
        "consumption": 21100.0
    },
    {
        "villageName": "Vete",
        "consumption": 23150.0
    }
]

energy-consumption's People

Contributors

huseynovramilx avatar

Watchers

James Cloos avatar  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.