Perl scripts analyze Jawbone UP data
Graphing Activity
With all this data available, you can now indulge in all kinds of neat experiments. For attractive charts, you just need a graphics package such as Chart::Clicker [4] to generate aesthetically pleasing results without much manual work. Figure 6 shows two graphs in a chart with the distance covered during the past 24 hours in purple and the steps measured dynamically at fixed intervals in yellow.

To save space on the device, the UP saves data sets in measurement intervals of varying length: If nothing happens for a long time, while the wearer is sleeping or watching television, the time window with the movement count can be one hour or longer. At full speed, however, the bracelet writes an entry to memory every minute to record the number of steps. The UP server estimates the distance covered by the UP wearer, the average speed, the calories burned during the activity, and the number of seconds in which the user was active in the time interval.
All of this information is tapped by the script in Listing 2 and rendered in graphical form using the chart package. The Chart::Clicker package from CPAN draws beautiful curves and is so flexible that it can even bundle two types of graphs in a single chart, as shown in Figure 6.
Listing 2
bandchart
A rendering engine called Chart::Clicker::Renderer::Area plots the number of meters covered over a timeline as a filled area (purple in Figure 6), and the graph shows the spikes of step count values as thin bars in yellow, also over the time axis.
On the Move
Left to its own devices, Chart::Clicker represents data as xy coordinates. If the x-values take the form of dates in Unix seconds, the Chart::Clicker::Axis::DateTime module ensures that they appear on the x-axis in a neat day or time data format.
The script uses the band()
method in line 31 to fetch the raw data for the past 24 hours from the bracelet. Optionally, an arbitrary time window could be defined. The results are an array of entries, each containing a reference to a hash – with steps
for the number of steps per period of time, distance
for the distance traveled, and speed
for the average speed during the measurement period. The time
method fetches the timestamp, active_time
the portion of the time window in which the user was active, and calories
the number of calories burned.
The script then fills three arrays with the retrieved values: @time
with the timestamps in Unix format, @steps
with the step count at these times, and @distance
with the total distance covered up to the point in time. Lines 56 and 70 generate one data series each of the type Data::Series from the time-step or time-distance combinations.
A record of the Data::DataSet type for a graph can store multiple data series in Chart::Clicker, but lines 56 and 64 respectively generate one data set with only one series each for the two graphs. The script wants to render these differently – one as an area graph and the other as a bar chart – but in the same diagram.
Rendering in Context
Chart::Clicker works in contexts to render the graphs; default
is the preset, and line 53 picks up an object of the same name. To render the second data set, line 80 defines an additional context named steps
; line 83 adds it to the system. Lines 88 and 89 then call add_to_datasets()
to add both series to the Clicker, and the domain_axis()
method assigns the two to the Axis::DateTime time axis via the context. The time axis then interprets the x values of data series as date values and renders them accordingly.
The %H:%M
specification tells the formatter to plot only the hours and minutes of the Unix date in the axis. The time zone America/Los_Angeles
is for the San Francisco area and may need to be adapted to your location. The time zone name matches the Olson database on which the DateTime module is based; the Wikipedia page [5] lists the values for Europe and the rest of the world.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

News
-
First Release Candidate for Linux Kernel 6.14 Now Available
Linus Torvalds has officially released the first release candidate for kernel 6.14 and it includes over 500,000 lines of modified code, making for a small release.
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.