Giter Club home page Giter Club logo

ai-meter's Introduction

ai-meter

JSON objects

JSON objects

Device

{
  "type": "object",
  "properties": {
    "id": { "type": "number" },
    "name": { "type": "string" },
    "consumption": { "type": "number" },
    "duration": { "type": ["number", "null"] }
  },
  "additionalProperties": false
}

Meter device

{
  "type": "object",
  "properties": {
    "id": { "type": "number" },
    "name": { "type": "string" },
    "consumption": { "type": "number" },
    "duration": { "type": ["number", "null"] },
    "on": { "type": "bool" }
  },
  "additionalProperties": false
}

Datapoint

{
  "type": "object",
  "properties": {
    "day_consumption": { "type": "number" },
    "night_consumption": { "type": "number" },
    "current_consumption": { "type": "number" },
    "datetime": { "type": "number" }
  },
  "additionalProperties": false
}

House

{
  "type": "object",
  "properties": {
    "occupants": { "type": "number" },
    "latitude": { "type": "number" },
    "longitude": { "type": "number" },
    "devices": {
      "type": "array", 
      "items": "meterdevice"
    }
  },
  "additionalProperties": false
}

Meter

{
  "type": "object",
  "properties": {
    "id": { "type": "number" },
    "last_data_point": { "type": "datapoint" },
    "house": { "type": "house" }
  },
  "additionalProperties": false
}
Endpoints

Endpoints

  • /device
    • GET: list all devices
      Returns: array of devices

      curl --request GET --url http://localhost:3000/device 
      
    • POST: create a new device
      name: String -> Name of the device
      consumption: integer -> How much the device consumes in kWh
      duration: null/integer -> how long the device runs for in seconds (null = forever)

      Returns: the device created

      curl --request POST \
          --url http://localhost:3000/device \
          --header 'Content-Type: application/json' \
          --data '{
              "name": "crypto farm",
              "consumption": 99999,
              "duration": null
          }'
      
      • /:device_id or /:device_name
        • GET: Return a specific device
          Returns: the device

          curl --request GET --url http://localhost:3000/device/1
          curl --request GET --url http://localhost:3000/device/device%201
          
        • PATCH: Update a device
          Same keys as POST /device if a key is not present it will not be updated

          Returns: updated device
          NOTE: the value null is normally the same as leaving out the key
          except for duration since it can have the value null

          curl --request PATCH \
              --url http://localhost:3000/device%201/2 \
              --header 'Content-Type: application/json' \
              --data '{
                  "name": "renamed device"
              }'
          
  • /meter
    • GET: list all meters with their attached devices
      Returns: array of meters

    • POST: Create a meter
      occupants:integer -> how many people live in the house
      day_consumption:integer(f32) -> day consumption to start with
      night_consumption:integer(f32) -> night consumption to start with

      Returns: created meter

        curl --request POST \
            --url http://localhost:3000/meter \
            --header 'Content-Type: application/json' \
            --data '{
                "occupants": 4,
                "day_consumption": 0,
                "night_consumption": 0,
                "latitude": 50.5039,
                "longitude": 4.4699
            }'
      
      • /:meter_id
        • GET: return a specific meter
          Returns: specific meter

        • PATCH: Update the meter
          Same keys as POST /meter if a key is not present it will not be updated

          Returns: updated meter

          curl --request PATCH \
              --url http://localhost:3000/meter/4 \
              --header 'Content-Type: application/json' \
              --data '{
                  "occupants": 1,
                  "latitude": 50.5039,
                  "longitude": 4.4699
              }'
          
        • /update

          • PATCH: Same as GET /meter/:meter_id but this also update/recalculates the usage
            Returns: meter with updated day/night consumption
        • /device

          • POST: Add a device to the current meter from the device listed in GET /device
            device: number/string -> device identifier this can be the id or the name
            on: bool -> Is the device on or off when added

            Returns: created meterdevice

            curl --request POST \
                --url http://localhost:3000/meter/4/device \
                --header 'Content-Type: application/json' \
                --data '{
                    "device": 5,
                    "on": true
                }'
            
          • /:meterdevice_id

            • GET: Returns a specific meter devices attached to the current meter Returns: specific meterdevice

            • PATCH: Update a meter device on: bool -> turn the device on/off

              Returns: updated meterdevice

              curl --request PATCH \
                  --url http://localhost:3000/meter/4/device/13 \
                  --header 'Content-Type: application/json' \
                  --data '{
                      "on": true
                  }'
              

Setup

Native

  1. Install the following:
  1. Setup the db
cp example.env .env
docker run --name postgres -e POSTGRES_PASSWORD=toor123 -p 5432:5432 -d postgres
# Wait for a few seconds for the db to start
diesel setup
  • To start the docker db again
docker start postgress
  1. Run the server
  • Debug: cargo run
  • Release: cargo run --release
  • arguments: cargo run -- --help
  • NOTE: Values in databse-url must be url encoded

Docker

#docker run ewoutvdb/ai-meter --database-url 'postgres://<user-name>:<password>@<server>:<port>/<database>'
docker run -p 3000:3000 ewoutvdb/ai-meter --database-url 'postgres://ai:Ai2022%[email protected]:5432/meter' --addr 0.0.0.0:3000 --log-level debug

Notes

  • insomnia-req-collection.json is created with and can be imported by insomnia
  • tables.drawio is a diagrams.net file

ai-meter's People

Contributors

vdbe avatar alfredo-vargas avatar

Watchers

Hannah Witvrouwen avatar Peter avatar

Forkers

vdbe

ai-meter's Issues

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.