The Occasional Occurence

A Cool New Dejavu Feature

November 18, 2006 at 11:17 AM | categories: Python, work, General

So I was working on something for Amor and came up against a limitation in Dejavu. I was working with a Unit setup similar to this:

::

import datetime from dejavu import Unit, UnitProperty

class Event(Unit):
Name = UnitProperty(unicode) Start = UnitProperty(datetime.datetime) End = UnitProperty(datetime.datetime) # a far Contact.ID ContactID = UnitProperty(int) # also a far Contact.ID HostID = UnitProperty(int)
class Contact(Unit):
FirstName = UnitProperty(unicode) LastName = UnitProperty(unicode) BirthDate = UnitProperty(datetime.date)

Event.many_to_one('ContactID', Contact, 'ID')

Conceptually, Events are associated to two Contacts; a general "contact" for the event and a "host". Dejavu allowed rigging up the first association easily (see Event.many_to_one(...) above). So I had Events and Contacts, and a many-to-one association between them based on the Event.ContactID and the Contact.ID.

That allows some nice recalling (querying) possibilities:

::

from myapp import arena box = arena.new_sandbox()

expr = lambda evt, con: con.LastName == 'Smith' # recall (Event, Contact) pairs where Contact.LastName == 'Smith' results = box.recall(Event & Contact, expr)

But what if I wanted to recall all Events and Contacts based on some attribute of the host Contact? I could create a custom UnitAssociation, which Dejavu provides for:

::
class EventHostAssociation(UnitAssociation):

to_many = False register = False

def related(self, unit, expr=None):
'''Define a magic recaller method...''' host = unit.sandbox.unit(Contact, ID=unit.HostID) return host

descriptor = EventHostAssociation('HostID', Contact, 'ID') descriptor.nearClass = Event Event._associations['Event Host'] = Event.Host = descriptor

Once I had recalled some Event units, I could call Event.Host() on them to get the related Contact. That is convenient, but for doing large scale operations based on some attribute of the host Contact, it would mean many potential hits on the underlying storage mechanism (probably a DB).

The problem was that even though Dejavu allows for custom UnitAssociations, there is no way to define what association path to prefer when doing a multirecall (JOIN). Since the Event>--Contact association was already defined using Event.ContactID and not Event.HostID, I was stuck.

I brought this situation to the attention of Dejavu's author, Robert Brewer. After a short while, he came up with a solution and an idea on how to implement it. I set off to work, and the result is that in the latest Dejavu trunk code, you can do this:

::

#create a UnitJoin object from two related Units join = Event & Contact #set a non-default custom UnitJoin path join.path = 'Event Host'

# setup an expression that will yield Events and (host) Contacts that are # older than a certain demographic expr = lambda evt, hst: hst.BirthDate < datetime.date(1978, 8, 17) results = box.recall(join, expr)

By setting the join.path to 'Event Host', I instructed Dejavu to use the custom UnitAssociation that I created above when performing that particular recall of Events and Contacts. Since the underlying storage mechanism I was using was a database that supports JOINs, I was able to recall all the Events and (host) Contacts that met my criteria in one hit on the DB.

So now Dejavu rocks just a little bit more*.

cw

* This implementation of this functionality as I described it is present in the trunk as of now, but might change somewhat before the next official release of Dejavu (1.5).

The Road Goes On

May 17, 2006 at 08:30 PM | categories: work, General

I just finished my career at Greenville College today. It has been a great place to work for the past 4 1/2 years. I am going to miss all of my co-workers in IT. They are an amazing group of people. If I didn't have enough memories from the past few years, they made sure I left with plenty from my final three days this week.

Monday

I had an official "farewell reception" that was open to everyone on campus. A number of people stopped by to say goodbye. It was a nice time. We had cake, "Clinton County" punch, nuts and lots of laughs. Deb set it all up and made everything really nice.

During the reception, my workspace was "altered". I came back to my desk to find a huge monochrome screened NCR computer where my flat-panel display typically sits. It had some rockin' "draws a line on the screen" screensaver running. My laptop was in the dock with a BSOD (blue screen of death). After a few seconds, I realized it was an identical model with a gag screensaver running. I also received a number of awards, including the "E for Effort Beard Award". My task list of things to teach Kevin was extended with "teach how to be Polish".

After taking in all the "upgrades" I was given, I went to the all-employee recognition reception where I was among a number of employees recognized for 5 years of service. I didn't tell them that officially I hadn't quite reached my 5 year mark. I really wanted that paperweight.

Tuesday

Tuesday started with staff meeting. Unbeknownst to me beforehand, the entire meeting was a series of gags. First, Paul passed around copies of my original resume from 2001 and everyone cracked jokes about it. There was even a typo on it - to think I was hired anyhow! I was then the subject of one of Rick's top ten lists. I can't remember the contents of the list, but it was basically a list of "memorable" accomplishments. Dan blasted me in the head with a foam rocket at some point. I was then presented with a pen from each member of the team. Didn't they do that in some movie? Brian said the one he gave me lights up. Paul went over some of the odd quotes that I made while working there, and Brian quizzed me on Ohio trivia to make sure I was up to moving back. I did fairly well, in my estimation.

After that, we left for Casa Gallardo, a regional Mexican restaurant. Paul drove one of the new GC people movers. It reeked of new vehicle plastic. At one point, Scott turned the ventilation fan on and for 30 seconds no one in the vehicle could breath. I don't know what chemicals were flying through the air, but they were smothering. Will "somehow" beat us to the restaurant even though he left after us and didn't know all the "shortcuts" that Paul did. All in all, it was a fun outing, and we all ate more than our fair share.

We rounded out the day with a few rousing rounds of Soldat. We did some capture the flag and some death match games. I held my own against Kevin, my replacement, but I was no match for Dan. He has a real knack for shooting at people. Perhaps he should consider an alternate career path? Scott even blasted me a few times. And Dan #2, playing as "Mr. T" was quick with his combat knife.

Wednesday

This was my last day. I was at the business end of more foam rockets and rubber bands than any day I can remember. Dan shot me in the head again. I did some packing and some photo and video documentary stuff of my last day. I got shot some more. I thought about how much I was going to miss the place and my coworkers. I got shot. Again. Again.

Paul walked in and asked for a refresher on how to transfer a call. Seconds later, one of the most difficult customers we have was transferred to my phone. She was asking questions about some Mac video editing software and said that Paul really thought I should give some input on the matter. Paul and the others in the office were busting up while I navigated my way through the twists and turns and ups and downs of the conversation with the familiar psychic vampire.

The day was finally coming to a close, I said some goodbyes, and went out to pull my car up to load up some stuff. When I found my car, it had been "decorated" by my friends. It had a bunch of cans and bottles tied underneath the car (wedding style) and a "Just Fired" sign stuck to the back window. There was also a flag on my antenna that said "Greenville College - Who Knew It Was In Illinois?". I also had about a dozen parking tickets on my windshield and my front seat (via my popped-up sunroof). I got some funny looks as I drove from work to the post office to send a letter.

Good thing I locked my car though - the real plan was to load it up with past-their-prime junker computers. At least I dodged one bullet this week :-)

If you want to see some of the people and events mentioned above, check out the pictures on Flickr.

cw

Lazy or Impatient?

May 25, 2005 at 07:24 PM | categories: Python, work

Man, I really enjoy programming in Python. I mean, it is really fun. Like digital Play-Doh.

I took an idea from, um, idea to socket-based networked client application with IP based security in one afternoon. Then, I continued with the idea and made a socket-based networked controller application that reads its configuration data from XML files in a few more hours. I have never written an app that uses XML config files before. By the way, this is all cross platform - Windows, MacOS, *nix.

This afternoon, I took it a step further and created a new version of the client that runs as a Windows service. Yep. It can be started/stopped from the Control Panel and logs messages to the system's Application Log. Oh yeah, I have never written a Windows service before.

So yeah, for the lazy/impatient programmer, Python rocks.

cw

Microsoft's New Mantra

April 22, 2005 at 02:36 PM | categories: work, computing

FORTUNE - Microsoft's New Mantra: "It Just Works"

Interesting article.

My favorite quote:

Microsoft’s research shows that the average corporate employee spends about 20% of her time on the PC simply looking for items.

Are they serious? Methinks that personal organization skills need some work, not operating systems. And I'm not even a super organized person. Sheesh.

cw

a new start

August 27, 2004 at 07:23 PM | categories: work

Today marked the start of a new school year. Freshman and teary-eyed parents arrived. There is a very exciting buzz at the beginning of a new year of school; Maybe it's just the tons of stuff that all needs to get done before the beginning of the year. Or maybe it's because it hardly seems like it has been seven years since I was arriving with teary-eyed parents. Pretty wild.

cw

« Previous Page