Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Automate Visualization of realtime data streams in chart.JS using Flask in python3.

License

NotificationsYou must be signed in to change notification settings

grebtsew/Visualize-Realtime-Data-Stream-Chart-in-Flask

Repository files navigation

Visualize arbitrary realtime data streams with just a few lines of code!

demo2

Table of Contents (click to expand)

About

Visualizing data flows are important in a project where maintaining data streams are of priority.The abiliy to visualize data in realtime can contribute with huge advantages while debugging code or demonstrating. In this implementation we are visualizing data in charts using Chart.JS, a simple powerful library for creating charts in Javascript. The server can now also visualize image streams and heatmaps using Plotly, a modern analytics app for enterprises. This implementation utilizes Flask and is developed mainly in python3 and Javascript.

Solution

This implementation is started by running themain.py file. TheStarter will then set a timer for triggering the webbrowser after one second and then start theFlask Handler. TheFlask Handler will start the website containing aFlask-SocketIO server. TheFlask-Server will receive json objects and update theGUI listview. When theFlask-Server is started theScheduler will be triggered. TheScheduler will start the middle-man servers consisting of aTCP Socket Server, aTCP Socket Server for large files and aHTTP Server which has the purpose of receiving messages and proxy them to the flask server. In thedemo we also start some data streams with the scheduler. You basicly have two alternatives on sending data to this implementation. Either create a data stream in thescheduler or create a seperatetcp socket client orhttp client and send data to the tcp socket server while running. See examples.

See program structure image below:structure

Getting Started

  1. Install program by firstly installing all the required packages in python3:Note: If you want to use docker seehere.
pip install -r requirements.txt
  1. Start the implementation by running:
python3 main.py
  1. If the website doesn't open automatically, open a webbrowser of your choice and go to:https://127.0.0.1:5000/

  2. Edit theScheduler file and Comment thedemo() line, to make sure the demo data streams won't start.

  3. Create your stream by looking at theheading below.

Example data json:

data = {  "id":1337,   "value": [1,1],   "type":"line",  "active_points": 20,  "label":"Label",  "legend": ["one", "two"],  "name":"Example",  "borderColor":["#3e95cd", "#e8c3b9"],  "backgroundColor":["#3e95cd","#e8c3b9"],  "api_crypt":"password-1"  }

Change Config

Ports and addresses can be changed in theconfig.ini file.

How to Send data to your Server

As mentioned in thesolution heading above there are two ways of sending data streams to this implementation, creating a socket client or creating data stream in the implementation.

Create a seperate TCP Socket Client

I created two simple example of tcp socket clients inexamples/. One that creates a data stream from live stock share prices and one that create a data stream from random numbers.

Using the scheduler

Take a closer look at thescheduler.py file, where more functions can be added to server start. In the current implementation there are two stream examples using scheduler in thedemo() function.

The first one is a seperate tcp socket client started from the scheduler. Check out the scheduler andsocket_client.py. The second one is a stream using theDataStream class. Check outdata_streams/samples.py.

Showing RTSP Streams

To create a video feed send a json with rtsp address as value and a unique id. Example:

video_data= {            'id': 12,            'value': rtsp://192.168.0.25:554/live.sdp,            'type': 'video_stream',            'name': 'Video Stream HTTP Example',            # Crypt password from config.ini            'api_crypt':CRYPT         }

Docker

  1. Build the docker image for this project by running:
docker build . --tag="JSChart-flask:1.0"
  1. Run the image in background by running:
docker run -d -p 80:80 JSChart-flask:1.0
  1. Or Run image in interactive mode by running:
docker run -it -p 80:80 JSChart-flask:1.0
  1. Open your webbrowser of choice and go to:
http://127.0.0.1/orhttp://localhost/

Note: all ports and addresses can be changed inconfig.ini

Demo

This is the output on the console during execution.demo1

This is how the implementation looks like during execution of thedemo().demo3

Examples of how each chart look and how the data should be represented in json see:

What is flask?

Flask is a micro web framework, enabling websites to be hosted in python.

What is Chart.JS?

Chart.JS is an opensource project with the main purpose to provide awesome charts for html5 and javascript.

What is Plotly?

Plotly is a collection of open source Graphing Libraries for visualizing data in a vast amount of formats.

Licenses

Seelicense

Known Issues

List of known issues:

  • Ignore theWebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance. warning as eventlet doesn't support Flask-socketio! Make sure eventlet is not installed in your python environment!

Sources

The main inspiration and solutions comes from the following sources:

Deprecated Demo

A deprecated demo can be intresting to see how the application has developed from earlier versions!demo2

TODO

These are functions that I will add

  • geo tagging free api map
  • 3d graphs
  • 3d algoritm
  • Bubble matrix
  • Tree

About

Automate Visualization of realtime data streams in chart.JS using Flask in python3.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp