Tuesday, January 24, 2012

GCal4RubyFAIL

Wow, has it really been almost a year since I updated this? It's not that I haven't been coding and working (though I haven't been coding as much as I would like), I just kind of forgot about documenting it here.

Some other time, I'll show you guys my hott QR code event programs (I'm going to make a demo video--and it's not really coding, and it's not rails, but it's just a neat idea that I had to combine tech and theater), and also my neat-o e-costume-measurement-sheets (and that IS RoR and IS totally hott and also useful. Besides being a great way to keep your costume measurement data on the cloud, you can do things like put your actors in order by arm length, should you ever need to do that). Oh, and my robot that tells me when my doubling is broken! ALL OF THESE THINGS WORK AND ARE SHINY.

BUT today what I want to write about is a victory/failure I'm experiencing right now. If anyone has used the gcal4ruby gem, maybe you can help me out. I've been fighting with it for months now, and it just won't give in.

So, the original problem that started me down this whole "learn to code and make things for theaters" road was that scheduling play rehearsals SUCKS. People always say, "Can't you just use Google calendar and see when people are available?" but it doesn't work like that. Here's the breakdown of what you have to do in order to schedule, say, a week of rehearsal.


  1. Make a chart of every scene (or French scene, which is a subdivision of a scene--you have a new French scene when a character leaves or arrives. So if you are in Act 2, Scene 1, you start in French scene 1.2.a. Then Fonzie shows up, and you're in 1.2.b, just like that!), with what characters are in each scene.
  2. Make a chart on top of the first chart that tells you which actors are in each scene (remember, one actor might play many parts).
  3. Get everyone's conflicts (in gcal or whatever)
  4. Look at each time block of your rehearsals. I like to schedule in 30-minute chunks. I start with the first 30 minutes. I take all the people in the cast, throw out the names of those who are not available during that time block, and then consult the chart from step 2 to determine what scenes I could do with the people who are available.
  5. Repeat step 4. Realize that there's only one, very short scene that you can rehearse on Thursdays between 7:30 and 9. Curse.
  6. Finally figure out a half-way reasonable schedule, send to actors.
  7. Read the emails pointing out that I made this or that error in going from a calendar to another calendar to a chart and back to my first calendar, all by hand.
  8. Drink to excess.
You might have noticed that most of that could be done more accurately by computers. Computers like doing repetitive and annoying tasks. They are very good at dealing with all the little details that humans forget. When this process is assisted by computers, it is way less error prone.

After a lot of work--it seemed like every piece I built needed some other piece--I finally managed to build a rehearsal scheduler! Sort of. I can get it to work in the console. Here's some code to show you how that looks:

alisha@Madagascar:~/code/henslowe$ script/console

Loading development environment (Rails 2.3.14)

>> r= Rehearsal.find(2)

=> #<Rehearsal id: 2, start_time: "2011-11-12 21:41:00", end_time: "2011-12-13 00:41:00", act_id: nil, scene_id: nil, french_scene_id: nil, created_at: "2011-12-29 21:42:07", updated_at: "2011-12-29 21:42:07", production_id: 1>
>> p = Production.find(1)
=> [all the details about the production go here]

>> frenchies = p.play.french_scenes
=> [This part lists all the French scenes in the play and all their attributes. I took it out because it is massive.
>> frenchies.each do |fs|
?> if fs.can_rehearse?(p, r.start_time, r.end_time)
>> puts fs.full_path
>> end
>> end
1.1.a
Joel cannot rehearse 2.1.a
1.1.b
Joel cannot rehearse 2.1.b
Joel cannot rehearse 1.1.c
Joel cannot rehearse 2.1.c
Joel cannot rehearse 1.1.d
Joel cannot rehearse 2.1.d
Joel cannot rehearse 1.1.e
Joel cannot rehearse 2.1.e
Joel cannot rehearse 1.1.f
Joel cannot rehearse 2.1.f
Joel cannot rehearse 1.1.g
Joel cannot rehearse 2.1.g
1.1.h
Joel cannot rehearse 2.1.h
Joel cannot rehearse 1.1.i
1.1.j
1.1.k
Joel cannot rehearse 1.1.l
1.1.m
Joel cannot rehearse 1.1.n
1.1.o
Joel cannot rehearse 1.1.p
Joel cannot rehearse 1.1.q

In the above example, an actor named Joel is in a lot of the scenes, and he has a conflict that precludes him from attending the rehearsal. I've asked my robot slaves to tell me not just that a scene cannot be rehearsed with the available actors, but also who the problem is. If an actor has a small part in a scene, it's possible that I would want to rehearse the other actors without him. Now I can see that I have seven French scenes to choose from, assuming I want all the actors present. I can edit the rehearsal record to tell it which French scene (or scene, or act) I want to rehearse.

The problem is that this is all on the console, and it's all on my local machine. I want to turn it into a usable web application. I want the actor-users to be able to log in and enter their own conflicts instead of sending me confusing emails and expecting me to figure out that when they say "next Thursday," they don't necessarily mean the one that is coming next.

I thought it would be great to use Google calendar for that aspect, and for managing the production calendar. I could even use Google's Open Auth for logins, which is way more secure and user-friendly than managing that stuff on my server. Before I bother trying to build a webified version of what I have working in the console and THEN adding the Google calendar piece, I thought it would be simplest to just start with the calendar piece so I don't have to rip stuff out and rebuild.

After looking at a number of gems, I decided that gcal4ruby does most of what I need and doesn't seem to have a lot of extra junk. It also seems to be relatively well-documented, as RoR gems go. So, I added it to my Gemfile and ran the rake thing--no errors reported. Bundler says it's installed at /usr/lib/ruby/gems/1.8/gems/gcal4ruby-0.5.5 , right next door to all my gems that are working (like, for example, mysql).

In the gcal4ruby documentation, it says that the first thing to do is to declare and begin a Service. Now, I'm not going to lie, I have no idea where that information should even begin to live in my rails app, but I'm sure I can figure it out. However, when I try to declare a new Service, this is what I get:


>> service = Service.new
NameError: uninitialized constant Service
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:469:in `load_missing_constant'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
from (irb):1
>>



I'm stuck on STEP ONE. My best guess is that I don't really know what I'm doing--I really don't quite know how to use gems and plugins (is there a difference between the two? I DON'T KNOW), and I've just gotten really lucky with the ones I've used so far. But um...If anyone can point out my error, or tell me where to start looking for it, I'd really appreciate that. I'm super frustrated right now, and have been for a really long time. This is why I abandoned this ship and built the aforementioned "sort actors by shoe size" app. Because it was dead simple.