An iOS App To Automatically Track Polluting Travel – Eco
Tags: devgrad2020, octograd2020, showdev, swiftui
Published: 2020-05-20 12:07:08

*This is a summary of my Computer Science degree dissertation & project completed at the University of Portsmouth, in support of my entry into [$ git remote graduation](https://github.com/education/graduation).*

## The Project

For the final project of my degree, I built Eco (working title): an iOS app that automatically tracks your polluting travel, and gives suggestions and goals to reduce it.

![Travel summary screen of the iOS app](https://dev-to-uploads.s3.amazonaws.com/i/0s7uzcqh9vx0z0aqi91d.jpeg)
![Settings screen of the iOS app](https://dev-to-uploads.s3.amazonaws.com/i/mno1yro0udvt8fdgy0lp.jpeg)

The overall goal was to improve people’s understanding of one high-impact area of their carbon footprint – travel (at least, before the COVID-19 pandemic 😅) – and to try and affect a change in behaviour.

Automatic tracking, rather than manual input, was a must in order to avoid guesswork and inaccurate estimates from users. Beyond this, the three main pillars of the project were identifying journeys travelled from GPS location data, classifying each journey into a specific mode of transport, and then presenting this in such a way as to encourage and change behaviour.

## How I Built It

The app was designed in Figma, and built entirely with SwiftUI in 6 months.

Data flow through the app was achieved through a unidirectional architecture that could be considered Redux-like, or similar to [Point-Free](https://www.pointfree.co/)’s fantastic [Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture) (which I’ll definitely be using in future SwiftUI projects!)

The app required ‘Always’ location permission in order to collect visited location data in the background throughout the day via `CoreLocation`, of which 2 weeks’ worth were stored on-disk. Some heuristics were created to identify the mode of transport (walking, running, cycling, driving, bus or train) between pairs of visited locations based on time, speed and distance – these worked well for most modes of transport, but accuracy could still be improved in future, especially for bus and train travel.

Travel was shown from most recent to oldest, grouped by day, with a set of generated ‘Highlights’ above on the feed for average pollution, average travel time, a goal for the number of days carbon-free this week based on last week’s travel, and the average air quality at visited locations (from data supplied by [OpenAQ](https://openaq.org/), using location & timestamp combinations reduced via K-Means clustering to save network requests & processing).

## Open-Sourced Components

* A [SwiftGen template to generate SwiftUI code for colours and images from Xcode asset catalogs](https://github.com/sebj/SwiftGen-SwiftUI-xcassets)
* A [Python script to generate a single `.json` file with the licenses of all Swift Package Manager dependencies of an Xcode project](https://github.com/sebj/SwiftPM-Xcode-Project-Licenses) – this `.json` file can be generated, bundled with the app, and then parsed & presented in about screens to the user as needed.

## Misc Thoughts

The project was as much an exercise in code quality, organisation, and project management as it was in pure coding effort (an area I’ve never felt lacking for). I feel as though I’m happy with the quality of the code, the unit tests that were written along the way (87% of non-View code), minimising [SwiftLint](https://github.com/realm/SwiftLint) warnings, and my management of user stories, bugs and tasks. Also managed to fit some [Gitmoji](http://gitmoji.carloscuesta.me) into my commits!

An interesting find was the balancing act of larger more intensive feature work along with smaller and more enjoyable under-the-hood technical tweaks and UI work, in order to avoid occasional monotony and burnout.