In a queue in a coffee shop a couple of weeks ago, the Barista recognised my colleague and asked him if he wanted "his usual" coffee. After commenting on how cool this was we continued to discuss what if a new Barista had started? How could the coffee shop use technology to provide the same great service? So we discussed:
- Perhaps the coffee shop could allow you to register your photo and your preferred coffee online and then use facial recognition as you join the queue to spot you and tell the Barista what your preference is.
...but them, as Geek conversations go, we evolved this to be:
- Facial recognition plus access to personal API data. This API data will tell the coffee shop how tired you're likely to be and thus they can recommend the coffee you need rather than the coffee you prefer.
For some reasons the person serving behind the counter wasn't up for this as an idea so I decided to build it myself...
So overall this is based upon the premise that caffeine is a stimulant and the more tired you are the more caffeine you need. Sounds plausible to me.
First to think about what information is readily available about how tired I might be. Based upon the Geek work I've done recently I have:
- Fitbit data based upon the FitBit API. This will tell me how many steps I did the day before, how many floors I climbed and how well I slept the previous night.
- Strava data from my Garmin Forerunner that I've accessed using the Strava API.
- General exercise data I've logged using my "Jerks" system.
The big idea was that I could write a Python script on my Raspberry Pi to:
- Gather data from these sources.
- Compare the results against pre-defined thresholds.
- Accumulate coffee points if the thresholds are breached.
- Map the resulting number of points to a coffee (more points is a coffee with more caffeine) and email the result to myself.
There's a full code listing at the bottom but here's a quick summary of the key points.
Using Python Fitbit (see my last post on this which tells you how to authenticate and access the API using Python objects).
To get steps and floors I created a Fitbit object and then did:
fitbit_activities = authd_client._COLLECTION_RESOURCE('activities',date=MyDate)
- More than 10,000 means a coffee point is accumulated.
- More than 25 floors means a coffee point is accumulated.
- Less than 420 minutes (7 hours) means a point accumulated.
- Used the GetADate function described above to get yesterday's date.
- Turned this into Unix time using a function I wrote called ConvertToUnix()
- 0 points means a nice cup of tea.
- 1 point means a small coffee.
- 2 points means a medium coffee.
- 3 points means a large coffee.
- 4 points means a large coffee and a single espresso.
- 5 points means a large coffee and a double espresso.
- The overall algorithm is far too simplistic. For example, if I had 5 minutes sleep or 6 hours 59 minutes sleep this still only equates to 1 coffee point. Equally a Strava (which could be pretty hard) is given the same weighting as a jerk (which could be relatively easy).
- The data structures I use are really lame. I use multiple lists rather then using a single data structure. I need to investigate this more. Comments please on this.
- The email is a bit boring. I experimented with adding images to the HTML content of the email but it didn't work. I think I need to use MIME multipart structures for this but didn't get round to doing it.
- There's loads of code there; far too much. I need to streamline it a bit. Perhaps write it in Java...