Visualizing The Heartbeat Data
The final script in this repo helium_heartbeat_plots.py
is used to visualize the
data the helium_heartbeat.py
script is collecting.
Also please note, this script handles a lot of edge cases, but not ALL of them, so please bear that in mind (and submit pull requests!)
Loading Data
The first step to visulzliing the data is loading the data! The load_data()
function does exactly
that.
The function will find all of the Heartbeat JSON files in the ./data
directory, but will only
plot the last specified n
days. For effeciency, the script assumes that a day includes at max 144
Heartbeats (this assumes a 10 minute Heartbeat interval, calculated from
6 per hour * 24 hours = 144
) and will only load most recent 144
Heartbeat JSON files.
Make note of how frequently you are checking for Heartbeats and adjust the values here as needed, a 10 minute interval is plenty of information.
Create a DataFrame
Pandas is a popular Data Science Python Library and kind of overkill for this plotting work, but it is easy to follow.
Pandas works with the concept of "DataFrames" which is comparable to a fancy Excel sheet (DataFrames are so much more than that, but this is all we need for this project)
Load the JSON files into a DataFrame and clean up the data
Plot the Data
Visual plots are a great way to convey a lot of information quickly. A Hotspot Heartbeat plot will look something like this:
This example shows the Activity Gap of two Hotspots on a 1o minute interval. As the Blue Line gets
higher, the Hotspot has been innactive longer. These two Hotspots are in good shape. The line is
blue, and below the dashed line
at the "inactive threshhold" (in this case 450, which is roughly
7.5 hours given current block times).
The plots also include a rolling median
line, which is a 30 interval median. This is useful when
diagnosing longer term trends in HOtspot Activity.
What About The Bad Times?
In the case that a Hotspot has gone more than 450 blocks without any activity, the line will turn red and fill the plot. This serves as a quick visual marker that something may not be working as expected.
In this example, the second Hotspot has crossed the threshold and is now considered Innactive.
The plot_data()
function handles all of the plotting and formatting work, it also generates the
output image as a .png
file.
This function is long, please see the file in the Github repo for all of the details, the snippet code here is truncated for clarity
Quick Access to the Charts
The chart output by helium_heartbeat_plots.py
overwrites itself, so as to save space and really
the most recent data is the most important. With that a very simple webpage is accessible on the
local machine to view the latest data via the plots.html
file. Open this in any web browser to
view the plots, or just open the .png
image file directly.
More Information
More information on this project can be found on the companion posts here: