Fixed for Canadian Postal Codes – Again
Once again, I had a report of a bug in the system and I started tracking it down. This particular bug was reporting that the number of closed deals to adjust the demand for was being seriously under-reported. Like major under-reporting. So I started looking at the fetching code, and then how the closed deals were being matched up against the demand, and it literally popped off the screen at me.
Canadian postal codes.
I've seen this before.
Thankfully, I knew just what to do. The problem was that in Canada, the postal codes are six characters with a middle space, and only the first three are significant to the spatial location data we use. That means we needed to look at the country and then correctly deal with the postal code.
The code I came up with was very similar to what I'd used in the past:
all_zips = recent_close['locations'].map do |loc| loc['country'] == "CA" ? loc['zip_code][0,2] : loc['zip_code'] end
and then we can use them just like we do with the Merchant to Demand pinning. Makes perfect sense why were weren't seeing a lot of matches with the previous code - the postal codes were far too specific.
That was a nice one to get out.