Dev team at work

Perks of being SW developer.

Hello, I am Pavel, a Software Engineer at Sujuwa and I’m a big fan of bicycle commuting. It is fun, sporting and environmentally friendly.

In the beginning of last year, I made a New Year’s resolution: cycle at least 5000 km during the year. But the main problem was how to track my progress. Cheap cyclocomputers are not accurate, not reliable and cannot show the progress of my challenge.

One way to solve this problem is to use excel tables. This is a classical approach - for example, I have excel tables for tracking car costs or to track my progress of going through Stephen King’s bibliography (I’m not kidding, I’ve read 74.55% of his books).

Backend development

Stephen King’s bibliography

But this time I decided to use my engineering skills and make the tracking of the progress as easy as possible, without updating it manually. So we can split this task into few subtasks:

  • Track the mileage on every trip
  • Store and update the data during the year
  • Show the progress

The first two subtasks I delegated to Strava, a mobile app used to track athletic activity via satellite navigation. The service uses GPS functionality of a mobile phone - or in my case a sport watch - to record position and time data during cycling. There are a lot of applications with the same functionality but I chose Strava because it is free and includes free API which can be used to visualise my progress.

The Strava API usage is limited on a per-application basis using a short term limit (15 minutes) and a long term daily limit. The default rate limit allows 600 requests every 15 minutes, with up to 30,000 requests per day. So this limit allows me to check my progress as much as I want. For visualising my progress, I decided to write a mobile app because with a mobile app I can track it any moment. To learn new technology, I chose React Native as the implementation platform. React Native is a framework for building native application using JavaScript and it is easy to get started. You only need three commands to start the project:

$ react-native init newAwesomeProject
$ cd newAwesomeProject
$ react-native run-android (run-ios)

All I needed in my simple app was to fetch the data from Strava API, get the total distance for this year and pass this number to the parser to visualise it nicely. Here is a sample of the code:

fetchData(){
    fetch('https://www.strava.com/api/v3/athletes/athlete_id/stats', {
        method: 'GET',
        headers: {
            'Authorization': 'Bearer ' + '_my_secret_code_'
        }
    }
    ).then((response) => response.json())
    .then((responseData) => {
        this.setState({
            totals: responseData.ytd_ride_totals.distance
        })
    })
}

After that you use the number “Totals” to make any kind of progress bar. In my case, I came up with this one:

Backend development

Screenshot of the app

I made a three sub goals, minimum, medium and maximum and added estimation based on my routing distance, so it’s easier for me and it keeps me motivated if I know how many days I need to cycle to hit a goal.

So, to sum up, I made a simple app to track my New Year resolution progress and all I need is to press one button on my phone or watch before ride and press another button at the end. It could not be easier, there are no excuses for not reaching your goals.