a work on process

links for 2007-09-23

23 September 2007 (4:19 am)

By James Stewart
Filed under: Notes
Tagged:

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

links for 2007-09-17

17 September 2007 (4:25 am)

By James Stewart
Filed under: Notes
Tagged:

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

Modelling Business Hours with ActiveRecord

16 September 2007 (5:16 pm)

By James Stewart
Filed under: Notes
Tagged:

One of the many tasks that’s been languishing on my ‘to do’ list has been improving the handling of opening/operating/business hours for Grand Rapids WiFi. So today, in a fit of wanting to reduce that ever-present list, I decided to take a proper stab at it. Since it’s got to be a fairly standard situation but I couldn’t find any other write ups online I thought the process might be worth a little documentation.

So far I’d been modelling business hours using the rather naive approach of having a column for the opening and closing times for each day. A snippet of the rails migration to create the table (adjusted to use the DRYed up migrations in Edge Rails, and then expanded for clarity) would therefore be:

create_table :locations do |t|
	t.string :name
	t.time :monday_open, :monday_close
	t.time :tuesday_open, :tuesday_close
	t.time :wednesday_open, :wednesday_close
	t.time :thursday_open, :thursday_close
	t.time :friday_open, :friday_close
	t.time :saturday_open, :saturday_close
	t.time :sunday_open, :sunday_close
end

This approach had several things going for it, primarily that it became easy to use a MySQL BETWEEN() query to check whether a location was open at a given time, and that representing this data in forms was nice and simple. But it quickly fell down when places were open 24 hours, or open post-midnight.

There are a huge number of options for business hours and to fully model all the possibilities quickly becomes a complex task. Shops usually have special hours around public holidays, they’ll often have different hours in summer and winter, and so on. An ideal solution would probably scope its opening time data with active dates, but I decided to go for something similar.

Instead of simply listing an opening and closing time each day, it makes sense to think of ‘openings’. A shop or cafe will open at one time, and close at another, hopefully on a pattern that fits into and repeats weekly. So the first step was to generate the model in rails and set up a migration:

create_table :openings do |t|
	t.integer :location_id, :opening_day, :closing_day
	t.time :opening_time, :closing_time
	t.integer :location_id
end

My migration also contained code to move the opening times currently stored in the locations table into the new openings table, and I used a script to update my fixtures file ready for refining the tests:

locations = YAML.load_file 'test/fixtures/locations.yml'
openings = {}
 
locations.each do |key, location|
  %w(monday tuesday wednesday thursday friday saturday sunday).each_with_index do |day, index|
    if location["#{day}_open"] and location["#{day}_close"]
      openings["opening_#{openings.size}"] = {
        'location_id' => location['id'],
        'opening_day' => index + 1, 
        'closing_day' => index + 1, 
        'opening_time' => location["#{day}_open"], 
        'closing_time' => location["#{day}_close"] 
      }
    end
  end
end
 
File.open("test/fixtures/openings.yml", 'w' ) { |out| YAML.dump(openings, out) }

So far, that’s fine, and once the associations are declared we can easily loop through all the openings and display their details. What about searching? How would I find all the places that are currently open?

Here we need a join, but it remains quite straightforward:

Location.find(:all, :include => :openings, :conditions => 
	['? BETWEEN openings.opening_time AND openings.closing_time AND 
	? BETWEEN openings.opening_day AND openings.closing_day', 
	Time.now.strftime('%H:%M'), Time.now.wday])

And really, that’s all there is to it. Depending on your usage you may want to encapsulate some queries in methods on your model (eg. Location.find_open) but it’s pleasing to be reminded of how simple ActiveRecord makes a project like this. Once you’ve worked out how to conceptualise the problem, it’s very little work to translate it to code and get it implemented.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

links for 2007-09-14

14 September 2007 (4:25 am)

By James Stewart
Filed under: Notes
Tagged:

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 

On Apple, misbehaving laptops and poor service

13 September 2007 (7:55 am)

By James Stewart
Filed under: Notes
Tagged: , ,

Along with travelling for two months and moving to another country, one of the main reasons this blog has been quiet for the past few months is that I have been having ongoing problems with my MacBook Pro. I’ve frequently toyed with writing about them here, but decided to wait and see if Apple could redeem the experience. The saga seems to be reaching a conclusion, but Apple don’t emerge from it looking very good.

Ever since I got my MacBook Pro last May I’ve had issues with it. The logic board was replaced a month after I got the machine, the battery was replaced, the screen developed strange grey blobs and had to be replaced, the top-case was replaced and the inverter board under the screen was replaced. But still it proved unreliable and kernel panics, random freezing and spontaneous reboots became more and more common.

Finally, having been advised to do so by staff at two different Apple Stores in the US, I decided it was time to ask Apple to replace the machine. After all, I’d been without it for over a month during the short time I’d owned it and it had begun to seem unlikely that any further part replacements were going to solve the problem.

When we arrived in London last month I went into the Apple Store to ask the “Genius Bar” staff if they could arrange a replacement. They looked over my records and told me they couldn’t find details of all the repairs I claimed had taken place. Since all my physical documentation of those repairs was sitting in customs, I wasn’t able to provide that very quickly.

By calling the store back in Grand Rapids I was able to get repair IDs for most of the work, and it turned out those repair records had been spread between multiple customer records. Even then, the Apple Store staff weren’t able to authorize a new machine and wanted to take it in for yet another repair. It was time to contact Apple directly to complain.

Apple don’t make it easy to work out how to make these sorts of complaints, but Customer Relations turned out to be the people to speak to and a couple of weeks ago I finally got through to a guy there who said he’d explore the case. A few days later he called back and told me that they would indeed replace the laptop with the latest and greatest model.

Naturally I was relieved that it looked like I might finally have a new laptop, but the sting was that they would need my existing laptop to be picked up before they could dispatch the new one. So that’s more time without it; more time working on borrowed computers without full access to my usual range of tools; and more time lost making extra backups and installing software on other computers so I could be somewhere close to productive.

I asked if it would be possible to simply swap the machine at the local Apple Store, or whether they’d be willing to take my credit card number as security to ship out the new machine before I’d returned the old one (which they have done with other replacement parts) but was told that neither of those was a possibility. So left with little other choice, I packaged up the new machine with assurances that it would only be a few days before I had a new laptop in my hands.

And now, a week later, I do. A full week. Not the couple of days that I was initially offered, not the five that they later revised that to, but the full week that the shipping company tells me had been the planned delivery date all along.

Every manufacturer ends up with some number of bad products. Good manufacturers not only work on their quality assurance processes to keep that number as small as possible, but respond quickly when customers complain. Apple may eventually have replaced my laptop, but I’m left feeling that they handled the case very poorly

Low level staff were keenly aware of the problem and encouraged me to request a replacement, but weren’t given the authority to direct that request appropriately; information was poorly stored and it was down to me as the customer to collect what should have been available from a central database; and they failed to make use of their impressive network of retail stores to ensure a smooth customer experience.

Much as I love the experience of using Apple computers, the experience leaves me wondering if I should be looking elsewhere for my next computer, or at the very least transitioning away from mac-only tools so it’s easier to move away if I need to.

Recommend this post:

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

 
Next Page »