Genii Weblog

Fun with formulas in session db for social networking

Tue 4 Jan 2011, 12:40 PM

by Ben Langhinrichs
It is fun once in a while to have to do something with formula language.  I added a Tweet button to the LS 2011 Sessions database (although I plan to rename it Share so that I can add facebook and such).  Feel free to tell me what a lousy job I did and how I could have done it better with @Transform.  I love that stuff.  The rules are simple.

1) It needs the Subject (which is the session id plus title) and some wrapper text.  I included the #LS11 hashtag so that it would be more easily found.

2) It needs to reference the speakers, some of whom have a filled-in TwitterID field and some of whom do not.  Those with a Twitter id should appear as @blanghinrichs while those who do not should appear as Ben Langhinrichs.  In other words, all speakers should appear, whether or not they have an id, but the ones with an id should also have an @ in front of them.

3) It must fit into 140 characters.  I chose to shorten the subject and add an ellipses (three dots) at the end if the whole thing was too long.  Obviously, the person tweeting can alter any and all of this, but I thought it would be good to start somewhere.

Here is what I came up with:

sp1:= @DbLookup("""""People"; Speaker[1]; "TwitterID"; [FailSilent]:[PartialMatch]);
sp1a:= @If(sp1=""; Speaker[1]; "");
sp2:= @If(@Count(Speaker) < 2; ""@DbLookup("""""People"; Speaker[2]; "TwitterID"; [FailSilent]:[PartialMatch]));
sp2a:= @If(@Count(Speaker) < 2; ""; sp2=""; Speaker[2]; "");
sp3:= @If(@Count(Speaker) < 3; ""@DbLookup("""""People"; Speaker[3]; "TwitterID"; [FailSilent]:[PartialMatch]));
sp3a:= @If(@Count(Speaker) < 3; ""; sp3=""; Speaker[3]; "");
speakerids := @Trim(sp1:sp2:sp3);
speakerstr := @If (@Implode(@Trim(speakerids); " ") = """"@Implode("@"+@Unique(@Trim(speakerids)); " "))+@Implode(@Trim(sp1a:sp2a:sp3a); " ");
idlen := @Length(speakerstr);
subjlen := @Length(Subject);
extralen := @If (idlen+subjlen+24 > 140;  (idlen+subjlen+24)-140; 0);
msg := "Look at #LS11 "@If (extralen > 0 & subjlen > extralen+3; @Left(Subject; subjlen-extralen-3)+"..."; Subject) + @If(idlen = 0; """ given by "+speakerstr);
url := @Text(@URLEncode("Domino"; msg));
""+@If(@IsError(url); SessionTitle; url)

Fun to play with some of these coding tricks I haven't used in a while.

Copyright 2011 Genii Software Ltd.

What has been said:

No documents found