Real Time Visualization of Data Through Web Based Solutions
Real Time Visualization of Data Through Web Based Solutions
Real Time Visualization of Data Through Web Based Solutions
On
Submitted by
DATE:
ACKNOWLEDGEMENT
ITR, Chandipur
Balasore
1. INTRODUCTION 7-11
1.1 Motivation
1.2 Problem Statement
1.3 Concepts
2. SOFTWARES AND TOOLS USED 12-13
3. INITIAL DEVELOPMENT OF SERVER SENT
EVENTS 14-16
3.1 Client Side
3.2 Building Real-Time Backends
4. ADVANCING FURTHER WITH GRAPHS 17-18
5. OPTIMIZATION 19-21
5.1 Initial Problem
5.2 Reason for Optimization
6. CONNECTING TO MONGODB 22-27
6.1 HTTP requests
6.2 Handling Post Requests and Middleware
6.3 Installing Mongoose
6.4 Saving Data to the Database
7. CONCLUSION 28
8. FUTURE CONCEPTS 29
9. REFERENCES 30
1. INTRODUCTION
MOTIVATION:
Generally this was taken up for two possible reasons one being web
based development was something which was yet to be explored by
me so as a challenge to learn and expand my knowledge and the
second being that in ITR there was a working model of this project
however what was missing was the data render was not close to
100ms and the data was supposed to be retrieved from a database in
real time.
PROBLEM STATEMENT:
The working model present in ITR was a server-client model where
data was being uploaded to the server from a file , processed by the
server and uploaded onto the client every 1000ms . So what the target
was to first implement a database which would store real time data a
feed the data to the server and the server would upload it to the client
in a graphical format rendering every 100ms.
CONCEPTS USED:
REACT
COMPONENT
FRONT END
2. SOFTWARES AND TOOLS USED
The Client:
The EventSource function initiates a connection with the server over
good old HTTP or HTTPS. It has a similar API to WebSocket and you
can provide an onmessagehandler for receiving data from the server.
Here’s an annotated example showing all of the important events.
INITIAL PROBLEM:
So, as we had that problem we went for a different route. After a lot of
research, I came to a solution that using Rickshaw.js SVG charting
library that is based on D3.js will actually might solve the problem.
Rickshaw provides the elements you need to create interactive graphs:
renderers, legends, hovers, range selectors, It's all based on d3
underneath, so graphs are drawn with standard SVG and styled with
CSS. D3 stands for Data-Driven Documents. It is an open-source
JavaScript library developed by Mike Bostock to create custom
interactive data visualizations in the web browser using SVG,
HTML and CSS
D3 Features
Uses Web Standards: D3 is an extremely powerful
visualization tool to create interactive data visualizations. It
exploits the modern web standards: SVG, HTML and CSS to
create data visualization.
Data Driven: D3 is data driven. It can use static data or fetch it
from the remote server in different formats such as Arrays,
Objects, CSV, JSON, XML etc. to create different types of
charts.
DOM Manipulation: D3 allows you to manipulate the
Document Object Model (DOM) based on your data.
Data Driven Elements: It empowers your data to dynamically
generate elements and apply styles to the elements, be it a table,
a graph or any other HTML element and/or group of elements.
Dynamic Properties: D3 gives the flexibility to provide
dynamic properties to most of its functions. Properties can be
specified as functions of data. That means your data can drive
your styles and attributes.
Types of visualization: With D3, there are no standard
visualization formats. But it enables you to create anything from
an HTML table to a Pie chart, from graphs and bar charts to
geospatial maps.
Custom Visualizations: Since D3 works with web standards, it
gives you complete control over your visualization features.
Transitions: D3 provides the transition() function. This is quite
powerful because internally, D3 works out the logic to
interpolate between your values and find the intermittent states.
Interaction and animation: D3 provides great support for
animation with functions like duration(), delay() and ease().
Animations from one state to another are fast and responsive to
user interactions.
This is a screenshot of how the final output looks on the client side.
6. CONNECTING TO MONGODB
HTTP Requests:
GET
The GET method is used to retrieve information from the given server
using a given URI. Requests using GET should only retrieve data and
should have no other effect on the data.
POST
A POST request is used to send data to the server, for example,
customer information, file upload, etc. using HTML forms.
PUT
Replaces all current representations of the target resource with the
uploaded content.
DELETE
Removes all current representations of the target resource given by a
URI.
Now the main objective of these requests handlers is a get request can
retrieves data from a web server by specifying parameters in the URL
portion of the request. This is the main method used for document
retrieval.Once that is done the object is created in MongoDb as shown
in the UI of Robo 3T and we know that we have received it.To check
if the request handlers are working or not we can test them using
Postman through which we can use any of the HTTP requests .
Handling POST requests and Middleware:
As we know between any request and response there are lots of code
acting as middlewares which gets executed before a response is
received. So here instead of using a lot of these we can use Body
parser , so these look for any requests and as soon as it gets it parses
the code and attaches it to the request object. Now those request object
can be accessed in the route handlers present. So in order to do all this
we install body parser through npm install body parser and save it to
our dependencies directory.
Models and Data Schemas:
Unlike SQL databases, where you must determine and declare a
table’s schema before inserting data, MongoDB’s collections, by
default, does not require its documents to have the same schema. That
is:
The documents in a single collection do not need to have the same set
of fields and the data type for a field can differ across documents
within a collection.
To change the structure of the documents in a collection, such as add
new fields, remove existing fields, or change the field values to a new
type, update the documents to the new structure.
This flexibility facilitates the mapping of documents to an entity or an
object. Each document can match the data fields of the represented
entity, even if the document has substantial variation from other
documents in the collection.
Installing Mongoose:
Mongoose is an Object Data Modeling (ODM) library for MongoDB
and Node.js. It manages relationships between data, provides schema
validation, and is used to translate between objects in code and the
representation of those objects in MongoDB.
A Mongoose model is a wrapper on the Mongoose schema. A
Mongoose schema defines the structure of the document, default
values, validators, etc., whereas a Mongoose model provides an
interface to the database for creating, querying, updating, deleting
records, etc.
This project is now able to meet the needs as was stated in the
problem statement as not only can access data from a database it is
able to render data every 100ms without any loss. Instead of going
with the typical node and express combination a different route was
taken which proved to be helpful in the optimization as the Rickshaw
js with SVG saved a lot of data loss and eventually everything fell into
place as it should have been . This project is still open to changes
though it can be modified in various ways and lot of other things can
be improved or added but for now it can give real-time visualization
of data through a webserver.
FUTURE WORK
Now given the project that the project was able to meet its
requirement there is however a lot of things that can be improved or
altered. As of now the database connectivity had some issues which
can be rectified or maybe instead of using MongoDB any other
NoSQL database which might be compatible can be used .Next is the
put requests has a lot of bugs which can be rectified as once the data is
added retrieving it was always a tough task which sometimes did
actually fail to be honest so that definitely can be rectified. Next is the
approach used is Rickshaw js with SVG library so instead of that one
can use Canvas js and can implement zooming and lot of other
properties to the graph and can improve the frontend even way better
changing the style sheets. Last is the instead of showing the data
rendering on a 2D graph maybe a 3D graph with hover options and
other functionalities could be shown. And even so the rendering time
can be reduced to further less with more accuracy.
REFERENCES
https://www.youtube.com/watch?
v=cOt8LfcA9wY&list=PL4cUxeGkcC9jBcybHMTIia56aV21o2cZ8&index=10
https://www.freecodecamp.org/news/introduction-to-mongoose-for-mongodb-
d2a7aa593c57/
https://www.sitepoint.com/real-time-apps-websockets-server-sent-events/
https://www.youtube.com/watch?v=gOcGbphplfM
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
https://auth0.com/blog/developing-real-time-web-applications-with-server-sent-
events/