Giter Site home page Giter Site logo

deviceservice's People

Contributors

kskitek avatar nieomylnieja avatar

Watchers

 avatar  avatar

deviceservice's Issues

Add device

  • provide endpoint POST /devices that accepts payload

     {
     Name: string,
     Interval: int,
     Value: float
    }
    
  • Interval > 0

  • Name cannot be empty

  • endpoint returns Device object

 {
  Id: int,
  Name: string,
  Interval: int,
  Value: float
 }
  • example request: http :8000/devices name="test name" interval:=-1
  • example request2: http :8000/devices < device1.json where
    device1.json is a file that looks like:
    {"name": "test name",
     "interval": -1
    }
    

Implement measurements persistence

Create new implementation of MeasurementsWriter that saves measurements in InfluxDB.

  • for every value received, write it to influxDB as influx's value, deviceId as Influx's tag and with timestamp = now() and precision set to second. values should be stored in influx's measurement called deviceValues, database called mydb
    • in case write fails just log it
  • InfluxDB address should be read from environment variable. If InfluxDB is not reachable during deviceService start it should panic

Example test InfluxDB query: SELECT * FROM deviceValues group by deviceId

Get device by Id

  • implement endpoint GET /devices/:id that returns device object
  • it should return 400 if id was not a number
  • it should return 404 if device was not found
  • it should return 500 in case there was an error in DAO

GET all devices

  • implement endpoint GET /devices that returns list of all devices
  • endpoint has to accept size and limit HTTP query parameters:
    • limit - limits length of returned. Default limit = 100. If limit == 0, ignore page (even if provided) and return all devices
    • page - tells which page should be returned. Page starts from 0. Default page = 0.
  • it should return 400 if page or limit are not integer or less than zero
  • it should return empty json array ([]) when there were no devices
  • it should return 500 in case there was an error in DAO

Example request: http :8000/devices page==2 limit==4

Communicate Ticker and Writer using RabbitMQ

Ticker service should push new dataPoints/measurements on RabbitMQ topic (instead of golang channel).

  • topic name: measurements
  • routing key should be set to device id

Writer service should accept measurements on the RabbitMQ topic. It should listen to measurements from all devices.

Implement TickerService

  • Ticker service, when started, reads all devices from. For every device:
    • create new time.Ticker that ticks in intervals read from device
    • on tick, send new measurement to chan<- Measurement, setting value and id read from device
  • Add endpoint POST /start that starts the Ticker

  • Implement MeasurementsWriter
  • MeasurementsWriter, when started, waits for measurements from <-chan Measurement
  • on new measurement it just prints it out to the console

type Measurement struct {
  Id int
  Value float64
}

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.