Categories: Personal Experience

Simple Script to Plot Number of Steps

Given that python is available on iOS, I decided to see what I could do with it. In this post, I’ll describe one experiment that I tried — the purpose of this post is to give you an idea of what you can do with python, I hope it inspires you to try new ideas of your own.

iOS devices contain a wealth of health data, and while the built in health app does a good job of presenting the data in a readable manner, and there are many third party apps that provide more detailed analysis, the hacker in me would not rest until I could extract the data from the app and do my own personal analytics with custom programs.

There are probably many different ways to do this, but I chose to extract the data with the Shortcuts app and then send the data to python for processing. Here is a screenshot of the shortcut that does this for me.

As can be seen, the shortcut collects the number of steps for the last two years, places this data on a variable and then calls a python script. Below is the code for the python script:

import clipboard
import sys
import numpy as np
import matplotlib.pyplot as plt
def main():
 tot = len(sys.argv)
 x = []
 for i in range(tot-1):
  text = sys.argv[i+1]
  if (int(text)!=0):
   print(text)
   x.append(int(text))
 arr = np.array(x)
 
 max = np.amax(arr)
 print('Max number of steps %s' % max)
 plt.plot(arr)
 plt.show()
 
if __name__ == '__main__':
 main()

As can be seen, the code takes the input from the shortcut and places it into an array. It then uses matplotlib to draw a simple plot of the data.

That’s it, those few lines of code allow me to draw a time series of my steps each day for the last two years. Given the wealth of data in the Health App, and the expressive power of python, the only limit on what you can do is your imagination. Below is the plot of this shortcut.

That spike in the chart was when I trained and ran for a marathon. As I play around more with the app, I’m sure that I’ll find more interesting things to do. I’ll post anything I find interesting on this blog.

Sherif Fadel Fahmy

You get what you see.

View Comments

    Recent Posts

    Exploring the Different Mount Systems for Nikkor Lenses

    Nikon, one of the leading brands in the photography world, offers a plethora of lenses…

    8 months ago

    Best Camera Lens Companies: Capturing Moments in Perfection

    Capturing perfect moments requires the perfect camera lens. Whether you're a professional photographer or an…

    8 months ago

    What is the Difference Between Nikkor FX and DX Lenses

    In the world of digital photography, Nikon is a brand that has consistently stood out…

    8 months ago

    A Comprehensive Review: Best Camera Lenses for Every Type of Photographer

    For photographers, the right camera lens can make a world of difference. Whether you're a…

    8 months ago

    Using Node.js for grades website

    As I tell my students very often, there is no Goldilocks solution. I have previously…

    8 months ago

    Unraveling the Difference: Front-End JavaScript vs Node.js

    In the realm of web development, two terms that frequently arise are front-end JavaScript and…

    8 months ago