followben / datalogger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

datalogger

Consumes a temperature feed and implements a GraphQL API to query the processed data.

Quick start

Ensure docker is running & you have docker compose

# start all containers
docker compose up

# setup the django admin
docker compose run web python manage.py createsuperuser

The following GraphQL queries and mutations are then available at http://localhost:8080/graphql:

# get the latest temperature reading
query {
  currentTemperature {
    timestamp
    value
  }
}

# get min and max temperature in a window
query {
  temperatureStatistics(
    after: "2020-12-06T12:00:00+00:00"
    before: "2020-12-07T12:00:00+00:00"
  ) {
    min
    max
  }
}

# turn the feed off or on
mutation {
  toggleFeed(input: { status: "on" }) {
    status
  }
}

What is this?

A sample backend created in early 2021 as part of a coding challenge. It's a little out of date now, but still demonstrates the use of Django, Channels and Graphene-Django to build a GraphQL api.

If this were real I'd:

To do:

  • move off graphene-django (it's no longer maintained) migrate to graphene-django v3.0.0
  • improve documentation
  • use pytest for testing
  • CI/ CD incl. tests and linting for mypy etc.
  • Return the real status of the feed rather than echoing the mutated one
  • Use an enum for feed status (embarrassed to say I was a bit stumped by string enums at the time)
  • Use pydantic to load & validate env vars and (de)serialize messages

About


Languages

Language:Python 97.0%Language:Dockerfile 3.0%