This Django project provides a GraphQL API for monitoring and retrieving temperature readings. The application uses Graphene-Django to define and expose GraphQL queries for current temperature data and historical temperature statistics within specified time ranges.
- Django app which can store temperature readings (a timestamp and a value) in the database.
- Subscribe to the temperature feed (see how to set up the temperature feed) to continuously populate the database.
- Current Temperature Query: Fetch the most recent temperature reading.
- Temperature Statistics Query: Fetch minimum and maximum temperatures over a specified date range.
- WebSocket Subscription: Real-time temperature updates (if applicable).
- A Dockerfile to make the whole setup portable and easy to-use.
- Python 3.7 or higher
- pip
- PostgreSQL
- Clone the Repository:
git clone https://github.com/Ashnayak/Temperature-Feed.git
cd Temperature-Feed
- Install Required Packages:
pip install -r requirements.txt
- Configure the Database:Edit the settings.py file to configure the database settings under the DATABASES section.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_database_name',
'USER': 'your_database_user',
'PASSWORD': 'your_database_password',
'HOST': 'localhost',
'PORT': '5432',
}
}
- Run Migrations:
python manage.py migrate
- Start the Server:
python manage.py runserver
Access the GraphQL interface through http://localhost:8000/graphql/ where you can execute queries like the following:
- Fetch Current Temperature:
query {
currentTemperature {
value
timestamp
}
}
- Fetch Temperature Statistics:
query {
temperatureStatistics(after: "2024-01-01T00:00:00Z", before: "2024-01-02T00:00:00Z") {
min
max
}
}
Data:
GraphQL APIs:
Run the following command to execute automated tests:
pytest