Automating Bike to Work Week with FME
Twice a year, a group of Safe Software employees participates in the Bike to Work Week (BTWW) organized by HUB Cycling, a charitable non-profit organization established to improve cycling conditions in Metro Vancouver. BTWW is an initiative to motivate people to use bikes for their daily commutes to work, a whole week long. It’s always a fun week with a bigger group of Safers joining in every year. We always organize at least one longer group ride during the week with a nice evening social event, which is great to get to know new members of the team.
A big part of BTWW is trip logging. Every biker logs the distance of his or her trips for every single day. Along with winning prizes, all logged trips help to improve cycling infrastructure in the communities of Metro Vancouver. All participating teams are also listed in an online leaderboard with a summary of distance, calories burned and greenhouse gases saved. But you need to go to the website every day and log your trips manually to make them count. There must be a way to automate this!
3 steps to automate BTWW trip logging
1. Track rides during BTWW and access them with FME
I have been logging quite a few of my bike rides and runs using an activity tracker, which easily syncs with the Strava app on my phone via Bluetooth. A while ago, I uploaded a Strava Web Connection to the FME Hub. This web connection allows me to interact with my activities tracked with Strava via the Strava REST API, directly in FME. Web Connections are the perfect way to interact with any web services that provide a REST API. So the first step needed to automate trip logging was already done and is still easily accessible thanks to FME Hub.
2. Log my trips on the HUB Cycling webpage
The second step turned out to be a little bit trickier. The HUB Cycling webpage does not provide an API that would allow us to simply log trips by sending a request to a single URL so I had to improvise. But as it often turns out, almost nothing is impossible with FME. I connected a couple of HTTPCallers following the same steps I would usually do manually: Log in to the webpage, navigate to the trip logging page and finally upload the information about my ride. This worked so well that I decided to create a custom transformer.
To make the HUBTripLogger custom transformer available to my co-workers and everybody else who wants to log trips with FME during BTWW, I again published it to the FME Hub, which is a great platform to share little projects like this. The new Upload & Edit dialog is very intuitive and walks you through all the steps to upload or update your custom transformers.
Now if we take a closer look at the full workspace, we can see a few fairly new date & time transformers in action. Working with date & time information can be quite challenging when we work with different formats and web services, and this project is a good example. In total there were 3 common challenges related to date & time information that I had to overcome:
- Make sure my request to Strava catches only bike rides of the current day
Solution: DateTimeStamper & DateTimeCalculator
- Provide the timestamp in Unix epoch format for the Strava API request
- Provide the date in the expected format for the HUB Cycling webpage
Solution: Again the DateTimeConverter
3. Automate the workflow with a daily schedule
Now that the workflow is ready to get all tracked rides of a single day from Strava to log them as BTWW trips, we need to automate the process for the whole week. So it’s time for FME Server. While not everybody might have access to FME Server, with FME Cloud we can easily launch an FME Server instance within a couple of minutes. With FME Server Schedules we can now set up our workspace to run on a daily basis for a whole week.
Now the BTWW trip logging is fully automated, and all I need to do is track my rides with an activity tracker and let FME do the rest of the work.