A basic django app that exposes a RESTful API endpoint for a random number generator and display a graph using a streaming plot.ly graph.
The project uses Django Rest Framework, Django Channels, Channels API, and Plot.ly.
- Clone this repository:
git clone https://github.com/SteveWaweru/randomstream.git
. cd
intorandomstream
:cd randomstream
.- Create virualenv from directory:
virtuaenv .
- Activate virtualenv:
source bin/activate
cd
into projectrandomstream
file:cd randomstream
- Install project requirements:
pip install -r requirements.txt
- Make migrations:
python manage.py makemigrations
- Run migrations:
python manage.py migrate
- Run application:
python manage.py runserver
- Navigate to your browser on localhost:
http://127.0.0.1:8000
Click on Button Start Stream
when on localhost on browser and random
numbers will be plotted on a plot.ly graph
The approach used for this app is for the websocket to keep track of updates to a resource. This is instantiated automatically when started initiating a value with a primary key of 1 and updating value of the object through each update on the database. This is an expensive operation as the stream of data is dependant on an operation that requires an update of a value in the database.
Also, there is some use of ajax to send a signal to the server on when to update the value when called upon in order to receive a random number.
This are features that would need looking further into for improving the functionality of the streamer
- 1 WebSocekt per user requiring user to authenticate or tying websocket to a session.
- Generating a random number without the need of a model.