repak shawahb
I like to think of myself as the master of my own destiny

^

   

rsw@jfet.org


blogroll

       
Wed, 13 Oct 2004

PosseBot

In what appears to be a trend, I've gone and made another software monstrosity for automating something that just doesn't need it.

At work, we go out to lunch every day; we call our lunch group "Posse." Many days, we end up going to the same place we went just a few days ago despite being within easy reach of many other good choices. To solve this problem, a former employee had what is jokingly known as "the C program," i.e., a program which would act as an oracle concerning posse location. That former employee, Joe, still goes out to lunch with us, because he now works at a different IC company here in Austin, but "the C program" was lost when he left.

You can see where this is going: I volunteered to rewrite it, and in the process ended up making it, ummm, awesome. First of all, it's now supported by a mySQL backend. Second, it's no longer an oracle; instead, it mails everyone at 6:30a with three choices and directs them to a website where they can vote on lunch. At 11:30a, the votes are tallied, the decision is made, and records are updated as appropriate in order to ensure that tomorrow's restaurant choices are sufficiently different from recent choices as to keep us going somewhere new every day. Of course, popularity figures in, too—a place that wins a lot is more likely to be trotted out for the vote than a place that's come in dead last every time.

The coolest part of all this is that in writing PosseBot, as I've decided to call it, I ended up teaching myself quite a bit of SQL. In fact, almost all the crunching is done by the database instead of by the perl scripts with which it interfaces—and yes, Jim, you're right, it's probably unnecessary, but Goddamnit it's cool to generate a PDF (not the Adobe thing, the 6.041 thing) in SQL.

For your amusement:

create temporary table tmp.tmp1
        (id smallint unsigned primary key not null,
        efftick float not null);
insert into tmp.tmp1 (id,efftick) select 
        id,log(1+tick) from restaurants;
set @y = (select type from history,restaurants where 
        winner=id order by day desc limit 0,1);
replace into tmp.tmp1 (id,efftick) select 
        id,log(1+tick/if(@y = 'general',1,10)) 
        from restaurants where type = @y;
set @y = (select type from history,restaurants where 
        winner=id order by day desc limit 1,1);
replace into tmp.tmp1 (id,efftick) select 
        id,log(1+tick/if(@y = 'general',1,5)) 
        from restaurants where type = @y;
set @y = (select type from history,restaurants where 
        winner=id order by day desc limit 2,1);
replace into tmp.tmp1 (id,efftick) select 
        id,log(1+tick/if(@y = 'general',1,2)) 
        from restaurants where type = @y;
set @y = ((select sum(tot) from (select count(*) 
        as tot from history group by winner) as foo) 
        + (select sum(winbonus) from restaurants));
update tmp.tmp1,restaurants set efftick = 
        (efftick + .25 * winbonus / @y ) where 
        tmp.tmp1.id = restaurants.id;
update tmp.tmp1,(select winner,count(winner) 
        as tot from history group by winner) as 
        foobar set efftick = (efftick + 
        .25 * tot / @y ) where winner = id;
set @y = (select sum(efftick) from tmp.tmp1);
update tmp.tmp1 set efftick = efftick / @y;
select tmp.tmp1.id,efftick,name,type from 
        tmp.tmp1,restaurants where 
        restaurants.id = tmp.tmp1.id;

I rule.


[ permalink | 6 comments ]

writebacks

May wrote

Wow
You do. You're also crazy. Loves it.

jim wrote


SELECT name FROM possible_cool_group_names WHERE name LIKE "pussy";

jim wrote


ps. your code is always unreadable.

gwax wrote

ah SQL
SQL is great stuff, though I think that you may be doing too much stuff in the database. Of course, that may just be me. Keep up the inane work.

Rodin wrote


SELECT mood FROM moods_of_jim WHERE mood LIKE "cheerful";
rm -f core

Gautham wrote


Bigtime's is more elegant. None of this voting or PDF bullshit. It delivers a verdict, and you better like it.

http://goatmeat.mit.edu/~mespence/perl/Restaurant.cgi




post a comment:

Save name/email/&c
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Comments:
Key:
(Required)