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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.
-
Kubuntu Focus Team Releases New Mini Desktop
The team behind Kubuntu Focus has released a new NX GEN 2 mini desktop PC powered by Linux.