Colin's brain dump

Taps Aff - How it got to Version 3.0

Impetus

It’s funny how a silly idea can end up taking over your life.

Back in 2012 I was out walking the dog down the River Kelvin in Glasgow trying to think up a simple JavaScript project. I was wanting to learn about something called Ajax transactions. I’d need to build a website which could pull data from another website, do something with it, and produce a result for a user.

Pretty generic idea right? That kind of describes every single website-as-a-service out there, however programming is an incredibly creative persuit so as dry as my remit sounded the execution could be as weird as I wanted.

This is the result

Taps Aff Header

The site is billed as Glasgow’s premier website as it provides a single critical observation, is it Taps Oan or Taps Aff?

Nationally endorsed sun-stroke

There’s an unagreeable temperature upon which Glaswegian’s will deem it appropriate to start undressing in response to a lick of heat coming from the sky. Although no-one can settle upon when it’s appropriate (some say never) what we can agree upon is the taxonomy of the conditions: it’s Taps Aff weather.

Removing one’s shirt under favourable atmospheric conditions is not unique to the west-coast of Scotland, but the fervour with which locals descend upon every sun-kissed park, patio and beer garden is a source of civic pride. This could perhaps have something to do with Glasgow receiving the fewest hours of sun per year than any other European city clocking in at an average total of 1202 hours. Even Reykjavik in Iceland pulls in more with 1268 hours per year and it’s a bawhair off being in the arctic circle.

This phrase Taps Aff has therefore come to embody far more than just paradoxical undressing. It represents shucking your responsibilities in favour of topping up your vitamin-D, meeting with friends under the sun and making the most of the good weather as soon as it arrives.

Taps-Aff (Scots Vernacular) Literally “tops off.” The removing of one’s shirt in the event of warm weather, a phenomenon rarely seen in Glasgow. Now an expression describing good times being had.

Antonym: Taps-Oan, “tops on”.

So when is it Taps Aff?

Since its inception the website has been through 3 phases, each time getting better at identifying when it’s Taps Aff:

  1. A dumb client-side JS driven version
  2. Slightly smarter PHP server-side implementation
  3. The current smarty-pants version implemented using Django

Taps Aff v1.0

At first the website would just look at the current temperature in Glasgow, including wind-chill. I very scientifically pulled the threshold of 17°C out of my arse and had the site say Taps Aff if the local temperature was greater, Taps Oan if it was lower.

Here’s the guts of the very first version of the site written using JQuery. Note that all the weather data I retrieved was in Fahrenheit so the actual threshold was 63°F

var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D%22UKXX0061%22&format=json";

function TapsAff()
{
    $("#dynamic-taps-message").html("aff");
    $("#dynamic-taps-message").css("color","#FF5454");
}

function TapsOan()
{
    $("#dynamic-taps-message").html("oan");
    $("#dynamic-taps-message").css("color","#2A44F0");    
}

function TapsError()
{
    $("#dynamic-taps-message").html(" error");
}

$(document).ready(function(){
    var Result = $.getJSON(url, "",
        function (data)
        {
            temp_f = data.query.results.channel.wind.chill;
            if (!isNaN(temp_f))
                if(temp_f>63) TapsAff();
                else TapsOan();
            else TapsError();
        })
        .error(TapsError);
});

By this point I figured I was done and I had learnt all I needed about Ajax and Json. That was until I started getting hundreds of visitors per day.

Being a coder I’m by de facto full of hubris so the thought of all that traffic on something I’d put minimal effort into gave me the heebee jeebees. I done the only logical thing: purchased the domain taps-aff.co.uk and started working on a proper version.

Taps Aff v2.0

Version 2.0 of the site gave me a chance to learn more about using a new (to me) paradigm whilst structuring a project. I also had some website work using Zend coming up so I figured learning a lighter PHP framework would be a good stepping stone so I opted to use KissMVC.

Anyone who has had the pleasure of seeing one of their personal projects take off in popularity understands the praise-to-critisim ratio. By the time v2.0 of the site was flying around the internet I was getting thousands of hits per day and only the negative feedback seemed to register. This was almost always to do with the site giving its opinion on the weather and the general public disagreeing.

An example friendly email

Taps Aff v2.1

By this point the site was now allowing people to search the weather anywhere in the UK so I was on the receiving end of even more criticism encouragement. It was important to make the site smarter so I started diving deeper into the weather data I was receiving from Yahoo.

Amoungst Yahoo’s current observations are a bunch of weather codes. When deciding if it was Taps Aff the site started considering these codes along with whether the sun was up. Here’s the weather codes I was using to see whether if it was definitely not Taps Aff.

// List of codes of non-aff weather
$GLOBALS['terrible_weather'] = array(
    0,   // tornado
    1,   // tropical storm
    2,   // hurricane
    3,   // severe thunderstorms
    4,   // thunderstorms
    5,   // mixed rain and snow
    6,   // mixed rain and sleet
    7,   // mixed snow and sleet
    8,   // freezing drizzle
    9,   // drizzle
    10,  // freezing rain
    11,  // showers
    12,  // showers
    13,  // snow flurries
    14,  // light snow showers
    15,  // blowing snow
    16,  // snow
    17,  // hail
    18,  // sleet
    19,  // dust
    20,  // foggy
    21,  // haze
    22,  // smoky
    25,  // cold
    35,  // mixed rain and hail
    36,  // hot
    37,  // isolated thunderstorms
    38,  // scattered thunderstorms
    39,  // scattered thunderstorms
    40,  // scattered showers
    41,  // heavy snow
    42,  // scattered snow showers
    43,  // heavy snow
    45,  // thundershowers
    46,  // snow showers
    47   // isolated thundershowers
);

This incarnation of the site stood for a few years and has served the most amount of traffic over the site’s life. However I was still getting beef off people for the site not being accurate enough. On top of that people were after an API, forecasts, maps…

More importantly I wasn’t too happy having to keep feeding the feature creature in a programming language I wasn’t interested in (sorry php), using a framework that had been dingied by its creator 10 years ago.

Not going to slag Taps Aff v2.1 too much though as it’s seen a lot of visitors.

Tracking Data

Taps Aff v3.0

In April 2018 I finally conceded that a complete rewrite of the site would give me the chance to reinvent The Tap and build something I’d be happy to keep working on.

Remember that time spent working on taps-aff.co.uk is meant to be educational and fun? A redesign also would give me the chance to brush up on some software development tools; my idea of a great time.

For the nerds: I decided that for v3.0 what I’d like to play with was:

My apologies for the technobabble above, sincerely. What I meant to say was I was going to build a website so fancy I’d be able to mess with it’s millions of settings from my phone.

The admin interface


And what about all those missing features people were after? By rebuilding the site in a more favourable framework anything’s possible. Maps? No bother. API? Piece of piss. Forecasting? Don’t sweat it.

In the end the rebuild and implementation of new features only took a few of weeks and was the requisite level of fun.

Workload


The core of whether it’s Taps Aff now looks a bit more professional.

Once weather data has been pulled from Yahoo the database considers whether the conditions are tolerable then has a look at the temperature.

def _test_taps_aff(code, temp_f, daytime):
    """
    Return the current status of the weather

    Arguments:
    code -- Weather code returned by Yahoo API
    temp_f -- Current temperature with windchill
    daytime -- Is the sun is up?
    """
    taps = {
        'status': OAN,
        'message': ""
    }

    if not Weather.objects.filter(code=code, terrible=True) and daytime:
        delta = Weather.objects.get(code=code).delta
        theshold = CONFIG().threshold + delta
        if temp_f >= theshold:
            taps["status"] = AFF

        elif temp_f + CONFIG().delta > theshold:
            taps["message"] = "...but only by a bawhair!"
    
    return taps

The source code for the current version of Taps Aff is available here.

WHEN IS IT TAPS AFF?

If you’ve read this far you deserve to know. On the first sunny day of the year, if there’s no wind and the sky is clear the threshold sits around 17°C. The “almost there” warning comes on at about 15°C.

Outside of those parameters though it’s all over the place. I suppose you could reverse engineer the default settings if you were really interested.

To be honest though the way the site’s currently configured I find myself wandering around tweaking the settings from my phone as I’m out and about. I suppose the final answer of when it’s Taps Aff is when I decide it is. What a superpower.

Phone Admin

Where does all this weather data come from?

Since its inception I’ve been using Yahoo’s free weather service to provide realtime status information along with future forecasting and location services (i.e. converting postcodes to place names).

Recently they updated their service and you need to have a whitelisted application in order to retrieve data from them. I’ve documented the move to this service here along with any sample code you might need to do the same.

To keep in Yahoo’s good-books I heavily cache requests so that I don’t lose access to their free service. I’ve never made a penny off this site and don’t plan on it, so there’s no chance I could move over to a paid-for weather service. For the amount of traffic taps-aff.co.uk receives I’d have to pay the likes of Weather Underground thousands of pounds per year… although being able to do hourly forecasting would be super cool.

Weekly Forecast Map

Afterthoughts

This website has been a really weird part of my life for ages now.

I’ve had job interviews where the employer has been more interesting talking about how I parse the weather outside rather than the work at hand. I was a little freaked out another time someone said “you look like that guy who made Taps Aff”.

There’s a whole bunch of things I’d like to get to over time. Not forgetting the personal goal for Taps Aff is to have a sandbox to play in and improve as a developer I would like to investigate:

Most of all I can’t believe this is what I’m now an expert in, it reminds me of this joke:

A man goes into a pub in a small town and, for whatever reason, gets introduced to the clientele. There’s Farmer Jack, Barman Jim, Maurice “Dancer” and Sheepshagger John. After a few pints, the visitor’s curiosity gets the better of him and he asks John what’s with the nickname.

“See this pub?” asks John, “I built it, but they don’t call me Pubbuilder John? I’m the local doctor, I saved Barman Jim’s life once when he choked on a peanut, but they don’t call me Lifesaver John. Every year, I supply a huge Christmas tree for the village green, but the don’t call me Christmas Tree John.

“But you shag one lousy sheep…”

A feature in the metro

And the Sunday Sun