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
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.