# DeviceAtlas Connectivity Analyser #
The DeviceAtlas Connectivity Analyser is used to measure the round trip time when
sending a payload of a fixed size to a client. This measures a combination of
latency and bandwidth. The measured time is then used to categorize the
client's current connection into low, medium or high.
### Usage ###
In order to use the Connectivity Analyser into your Ruby on Rails web
application, follow these steps:
1) Install the deviceatlas_connectivity_analyser gem (add a reference from
Gemfile if needed).
2) (OPTIONAL) Set the checker's options through an initializer config file
associated to your app. If you do not use a config file, the options will be
set with the default values:
- The amount of data to send to the client as part of the bandwidth
measurement. Defaults to 1KB.
payloadSizeBytes = 1024
- The thresholds to define the low and mid tiers. The threshold is defined in
ms. Everything faster than the mid threshold is classified as high quality.
lowThresholdMs = 900
mediumThresholdMs = 400
- Frequency of measurement for a given user. If the frequency is not every
request then the previous results are forwarded to the destination instead
of re-measuring the bandwidth for the times when measurement should not be
frequency = 1
3) Include the Connectivity Analyser controller helper. This will let you get an
instance of ConnectivityAnalyser and use the methods to decide what actions
to apply after checking the user's bandwidth.
4) Get the duration in ms and quality from your controller's methods.
### Step By Step ###
#### Steps (1), (3) and (4). ####
# Your app's controller script.
class YourAppController < ActionController::Base
# Controller helper to have access to ConnectivityAnalyser objects
# Get an instance of ConnectivityAnalyser
connectivity_analyser = get_deviceatlas_connectivity_analyser_instance
@duration_ms = connectivity_analyser.get_duration_ms
@quality = connectivity_analyser.get_quality
# Put your code here to use the above variables.
# For example, you could generate an optimized webpage if the
# quality is low.
#### Step (2). ####
# Your initializer config file.
# For example: /path/to/your/project/config/initializers/deviceatlas_connectivity_analyser.rb
config.payloadSizeBytes = 1024
config.lowThresholdMs = 900
config.mediumThresholdMs = 400
config.frequency = 3
# Additionally, you can also display the duration and quality from your app with
# a simple .html.erb file as follows.
DeviceAtlas Connectivity Analyser
DeviceAtlas Connectivity Analyser
Duration: <%= @durationMs %>ms
### Example ###
The DeviceAtlas Connectivity Analyser comes with an example application,
with the default values set, which you can find inside example directory.
This example uses DeviceAtlas Connectivity Analyser to find out the
quality of user's network, then based on the quality an appropriate photo is
selected and shown to the user. There are three photos with different size and
jpeg compression ratio, therefore different file size.
The given example contains the basic files you would need to use this application
from a Ruby on Rails project.
Once the gem is installed and controllers, viewers and assets are placed in the
respective folders from your Rails server, the example app will be ready to be
checked from your browser.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_(c) 2021 DeviceAtlas Limited. All rights reserved. https://deviceatlas.com _
Quality: <%= @quality %>