Re-opening the bins
The Leeds Bin App was made by Tom and Dan at imactivate. It was built on top of open data about bin collections published by Leeds City Council. It is very simple: you search for your address and it tells you your bin collection dates. It can add reminders to your device's calendar too so that you don't miss the collection. As of 21st August 2019, over 1 million lookups have been done for over 13,000 unique postcodes. The app has a multiplier affect because, as long as some people on a street have it, others can tell which bin to put out by following the lead of their neighbours.
The bin app is obviously helpful for those of us that can't remember which bin to put out this week, but it can also help Leeds City Council. Every year, around Christmas/New Year, they have to contact every household in Leeds to let them know about changes to bin collections over the holiday period. Posting that many letters can lead to a cost in the hundreds of thousands of pounds. If they are able to keep people up-to-date about bin collections for a minimal cost, that money can go into other things. Especially as council budgets get reduced. So bin apps make citizens lives easier and save money for councils.
Although Leeds Bin App originally used a dataset published on Data Mill North, copyright issues arose and it turned out the dataset wasn't as open as thought. Originally, Leeds City Council were publishing a file with the premises ID (used for bin collections), the address line, the locality, and the postcode. This allowed the citizen to search by postcode and then narrow down the address in a process familiar from online shopping. However, having both the address and the postcode infringed on Royal Mail's copyright as they own the Postcode Address File which is not open data. As a result, the Leeds dataset no longer includes postcode and the Leeds Bin App now has to use closed data in order to work.
Recently I decided to try to replicate what Tom and Dan do but only using open data sources. I thought I'd also use this as an opportunity to make a progressive web app and, for extra fun, work out how to insert anonymisation into the process right from the start.
Finding an address whilst protecting privacy
The first task was to re-imagine an address look-up that doesn't involve postcode. It has been suggested that people prefer to search by postcode but, in 2019, many people are used to entering the first line of their address into online forms. It is increasingly likely that their street name is in their predictive text. Typing the street name is much quicker than it might have been in previous decades. However, whereas postcodes are unique, street names are not. To break that ambiguity, we need to rely on the locality to make sure people pick the correct street. We could make a type-ahead search (that people are used to with Google etc) to make it easier for people too. With what seemed like a workable solution to avoid postcodes, the next consideration was how to do this in a privacy-first way.
The simplest and most privacy-protecting solution would be to send the premises data for the whole of Leeds to the browser. That file comes in at 33MB so is not practical. There needed to be a solution that split the data into small enough chunks to be useful whilst also preserving a level of anonymity. In the end I came up with the following method:
- Sort all the street names in a local authority alphabetically (ignoring spaces and non A-Z characters).
- Clean up the names of streets and localities (which are all in UPPERCASE) by using the OS Open Names dataset to get all the cases correct (rather than just assume that every word starts with a capital letter).
- Split the list of streets up into chunks of at least 50 making sure that all streets that start with the same 3 letters are in the same file e.g. for Leeds, every street starting AAA to ACO goes in one file, every street from ACP to AIN goes in a second, and so on.
- Create an index for these chunks of addresses so that any three letters can be mapped to one specific street file.
Once the user has entered the first three letters of their street name (and in many cases before that), the browser can work out which file to request. This means that the server only gets to know the range of the first three letters i.e. Street Lane is in the file
premises-STP-SUM.csv. These files range from 12kB to 148kB (but are largely under 50kB) and contain every street address, the locality, the postcode district, the latitude/longitude, and every house along with the corresponding premises ID e.g.
Here I've taken the extra step of encoding the premises ID in base64 in order to save some bytes. Each of these files contain multiple streets in multiple parts of the city. The result is that the server has returned the address whilst not really knowing where the user is searching for. When the web page has a premises file, it can create a type-ahead search contained entirely within the browser. So the first stage of the type-ahead is to narrow down by street name. The second step is to limit those results by house number/name. Hopefully it is just as intuitive and just as fast to use as Leeds Bin App's postcode and street address steps.
Once the user has selected a specific address we then need to get the collection dates for it. But we don't want to send the premises ID to the server as that undoes all the privacy we just preserved. So, I've packaged up the collection dates data in the same way as the addresses. The browser just requests a file named
jobs-STP-SUM.csv which contains all the jobs for all the premises with street addresses in the range STP to SUM. The server hasn't learned anything new about the address in this step as the key information sent (the range of the first three letters) is identical to before. In summary, we've now got a process that can find bin collections quickly, entirely with open data, and in a way that the server never really knows where you looked up.
Now that I had a privacy-protecting mechanism for looking up addresses, the next step was to make a progressive web app. That meant creating a Service Worker and a Manifest file neither of which I have done before. Mozilla Developer Network and Google have some useful documentation on making a Manifest. It also turns out that the Developer tools in Chrome have a useful feature named Lighthouse that can help spot issues. After a few basic mistakes I got it working. That means you should be able to "pin to home screen" or even be prompted by your browser to "install" the page as an "app" once you've visited it a few times.
I kept imactivate's simple input field process to focus the user's attention. I've hidden everything else in a menu. I've added a cookie (only read by the browser and not sent to the server) which saves the form inputs so they can be auto-completed next time you come back. If you've disabled cookies that isn't a problem; you just have to fill in the form again yourself. Here's the result:
Alert! Alert! Alert!
A big point of a "bin app" is to be alerted when your bin collection is about to happen. That means waiting perhaps several weeks before alerting the user. I'm currently exploring how best to do this. One option - and the one I'm using at the moment - is to create iCal files that the user can download to add to their device's calendar. This isn't the cleanest option and doesn't work on all devices. Another option I'm exploring is to keep the alerts entirely within the app using Web Notifications.
You may have noticed Web Notifications become a thing in recent months as more and more websites prompt you to allow notifications. I've become very used to automatically saying "No" to these because they often occur when I'm not expecting them. That learned behaviour makes it more likely that people accidentally don't allow notifications when they want them. This might be mitigated by only asking to allow notifications as a result of the user clicking a button that lets them know they will be asked to allow notifications. Hopefully that is enough to make them be more conscious when the browser prompts them.
Having worked out how to create a notification I ran into another issue. An "app" such as this is mostly "off". That seems like a blocker. But, it turns out that the Service Worker should stay running in the background. I've experimented with sending the bin collection dates to the Service Worker and then running a
setInterval event to check if any notifications need to be created. This only seems to last until the browser deletes cookies (which includes the Service Worker) and that seems to occur more frequently than bin collections so doesn't seem to be reliable enough. For the moment, I'll have to stick with the iCal solution. If you've had experience of setting a notification for a future time in a web app I'd be interested to hear how you did it.
After creating a fully open bin app, I tried testing it with the addresses of people I know. As a result I've found some differences in results between the imactivate app and my results. Initially I thought I might be doing something wrong but, after talking to Dan, it looks as though there are differences in the source data. I've fed that back to Bartec who operate the bin collections on behalf of the council. Hopefully they can find the issues and make sure the open and closed data sets are consistent.
This process has resulted in me creating a friendly "rival" to Tom and Dan's bin app to provide some competition to the bin app market. My version is entirely web-based. It only uses open data. It only uses static files so can run on Github pages. It also goes out of its way to make sure the server knows as little as possible about the address the user has searched for.
Next steps might include adding useful features around recycling. To start with I could include the city council's open data set of their recycling sites. But that is a limited dataset and, for instance, doesn't include all the battery recycling sites. I'm not sure there is a complete dataset of those in existence but that could be crowd-sourced through Open Street Map. What else would you like to see in a bin app? Let us know on Twitter.