Project 0

So I’ve decided I want to push forward on some of my creative endeavors that had stagnated while I went into Oh-crap-I’m-almost-out-of-money mode. I’ve always thought of myself is having a stronger eye for art than hand for art. That is, I’m a better critic than an artist, self criticism included. I can do a fairly decent drawing, but the process is arduous, full of dissatisfaction, and almost completely reliant on the digital world’s ability to resize and reposition parts of a drawing without starting over from scratch or erasing huge swaths of work; I probably erase three times as many lines as I commit to. That being said, I’m aware, thanks to my harsh-but-necessary self criticism, that I’m not the most creative person. I have a hard time with original designs, and my costume work and scenery work is definitely wanting. And I’ve come to the realization that what I want isn’t necessarily something that is completely original, made in a vacuum without any outside influence, but something intelligent, good looking, and enjoyable.

To that end, today I stumbled upon the obvious solution of commissioning concept work from people who are good at that sort of thing. I’m totally cool with sitting in the Art Director’s chair and not the Artist’s chair: the Director probably gets paid better anyway. I’ve begun a list of things that I’m pretty sure I’d do a piss poor job at, or are important enough that I’d want their representation to look professional and interesting, such as iconic ships, costumes, and locations.

The downside of this is actually finding an artist(s) who is
A) up to my standard of quality,
B) proficient at the kind of design I need, and
C) available for work.

While I’ve mentally signed off on a budget of a few thousand (the list is pretty big) for this, I haven’t been able to find anyone in my brochure of artists or a few hours of DA surfing who meets A, B, & C, with C being the most common problem. For today, this is acceptable, as there’s a bunch of writing I need to do to figure out what exactly I need done anyway.

Extracting a Lotto Number Database

I recently discovered the show Numb3rs, which somehow ran 5 seasons on primetime TV without me noticing, and got caught up in the spirit of applying only-vaguely-related mathematical processes to an esoteric problem. My task was deciding which lottery numbers to play this week, and I decided to try a strategy I had learned for playing roulette, which has a similar “guess which random number will appear” challenge. The strategy utilized Standard Deviation which, as the PDF explained, involved keeping track of which numbers appear over a certain amount of time, and betting on the numbers that have appeared too few times.

The real challenge here was getting a usable list of which numbers were played when. The Florida Lotto provides a handy-dandy HTML file with drawing results all the way back into the 80’s. However, the data is arranged awkwardly in a number of HTML tables, with three tables on each “page”, and 49 drawings in each table:

My target data structure was a 2D array, with the first object being the most recent drawing and the last being the oldest drawing. Each object in the primary array should be an array with 7 indexes, 0 being the drawing date, and 1-6 being the 6 numbers drawn on that date. However, the tables are arranged in a way that the next object is 49 drawings away from the current one. To make my array, I’d need…. AN ALGORITHM!

First off, I need to be able to extract only the information I need for each drawing, and ignore the table and formatting data from the HTML file. I first considered using bulky Search string functions, but since my data is already formalized, I decided on using some Regular Expressions, one for the date, and one for the six numbers:

var datePattern:RegExp = new RegExp(“[0-9][0-9]?\/[0-9][0-9]?\/[0-9][0-9]?”, “g”);
var numPattern:RegExp = new RegExp(“\”>[0-9][0-9]?<\/”, “g”);

My datePattern expression seeks out data with the format “nn/nn/nn“, where n is any number, and my num pattern looks for one or two numbers between less-than/greater-than signs (these are opening/closing tags in the HTML file, and were useful for singling out drawing numbers as opposed to, say, font sizes) “>nn<”. The “g” flag on the RegExp objects allows the objects to keep track of where in the HTML file it found the last matching string, so that the next time the exec() function is called on those expressions, they start from where they left off instead of the beginning of the file. So far, my function looks like so:

var Result:Object;
Result = datePattern.exec(e.target.data); // (e.target.data is the HTML file loaded in via URLLoader)
date = Result[0];

Result = numPattern.exec(e.target.data);
num1 = Number(Result[0].slice(2, -2));

Result = numPattern.exec(e.target.data);
num2 = Number(Result[0].slice(2, -2));

Result = numPattern.exec(e.target.data);
num3 = Number(Result[0].slice(2, -2));

Result = numPattern.exec(e.target.data);
num4 = Number(Result[0].slice(2, -2));

Result = numPattern.exec(e.target.data);
num5 = Number(Result[0].slice(2, -2));

Result = numPattern.exec(e.target.data);
num6 = Number(Result[0].slice(2, -2));

The first time I call the numPattern expression, it finds the very first lotto number in the HTML file, which happens to be the first number of the most recent drawing. Because the “g” flag is set, each subsequent call starts from the last number found and finds the next number. If I call it five more times, it returns the second, third, fourth, fifth, and sixth number of the first drawing. When I call it again, it then finds the first number of the second drawing, and so on. The problem now is putting the drawings in the right order, since the second drawing in the HTML file is actually the 50th drawing chronologically. After some experimentation and compensation, I arrived at the following algorithm:

position = (Math.floor(i/3)+((i%3)*49))+(Math.floor(i/147)*98);
dataArray[position] = new Array(date, num1, num2, num3, num4, num5, num6);

The first half of the position calculation handles intra-table positioning; that is, organizing each 147 numbers in a given table correctly. I do this by using modulo 3 to determine which of the three columns on a page the number comes from. The first column contains positions 0-48, the second column has 49-97, and the third 98-146. The second half of the table came later after I realized tables on other pages were overriding each other. To compensate, I divide the current index position by 147 to figure out which “page” the current index is on. Finally, with the correct chronological position calculated, I can add an array containing the extracted data to the primary array of drawings.

Running this function in a loop in Flash takes about 5 minutes (I had to extend the Script Timeout Limit past 15 seconds to facilitate this) to extract all 1,764 drawings (at the time I wrote the program). Running the array through a tracing function allows me to output the data to an XML file, which I then used in a second program to calculate how long it’s been since each number has been drawn. That function looks like this:

var lottoNumbers:Array = new Array(54);
for(var i=xmlData.drawing.length()-1; i>-1; i += -1) {
for(var j=53;j>0;j+=-1) {
lottoNumbers[j]++;
}
for(var k=5;k>-1;k+=-1) {
lottoNumbers[xmlData.drawing[i].num[k]] = 0;
}
}

for(var index in lottoNumbers) {
trace(index+” => “+lottoNumbers[index]);
}

While solving the problem of extracting, ordering, and running calculations on the lotto data was fun, as it turns out, the six numbers that had gone the longest without being drawn (the six I picked) didn’t turn up at all in the drawing that week. Back to the drawing board I suppose!

XBMC Control Via Crestron, Part II

Have successfully tested XBMC’s HTTP API for GUI control, with some caveats. First, let’s look at the process. I establish connection by creating a TCP/IP object on port 8080 (the default port for XBMC’s HTTP interface, this must first be enabled in XBMC’s settings) and connecting on startup. Using a Serial I/O symbol, I’m sending GET requests to XBMC’s web server via commands like:

GET /xbmcCmds/xbmcHttp?command=SendKey(270) HTTP/1.1\n\n

As it turns out, XBMC doesn’t have traditional keyboard mappings. Instead, I’m mimicking the digital signals for Up/Down/Left/Right, A, and B on (presumably) an XBox controller. The codes for these buttons are listed in Key.h. So no hex keyboard codes. The problem I’m finding is that the event server only recognizes the action as a whole, and not a press/release combo. So pressing-down and holding-down do the same thing: move the GUI down one item. In order to be able to HOLD down and have the list scroll continuously until I release the key, I have to implement a second command, KeyRepeat, which takes a time value (ms) as a parameter, and repeats the previous SendKey action continuously until you resend the command with a 0 time parameter. Luckily, Crestron has a pre-built Press-And-Hold symbol which I can utilize to send a SendKey command on a PRESS, or a SendKey+KeyRepeat command on a HOLD. I’ve found a parameter of about 10-20 ms for the repeat to be a decent scroll speed for large lists.

XBMC Control Via Crestron

I’ve been brainstorming for years on a sophisticated home entertainment system with a fancy interface that can navigate and play all kinds of network content, and for as long as I’ve been doing that, I’ve always liked XBMC. Back in the day, I bought the hardware & software necessary to hack the original XBox and installed XBMC on it, but the software has come a long way since then. As of its 10.0 “Dharma” release, it has a new remote control interface using the JSON RPC 2.0 specification. And since I now have a Crestron processor of my very own, this week’s project is to start writing a module to interface with XBMC.

Preliminary tests were simple and successful. I’m using the raw TCP interface, and after a connection to port 9090, I’m able to issue play, pause, forward, and previous commands to the audio player like so:

{“jsonrpc”: “2.0″, “method”: “AudioPlayer.PlayPause”, “id”: 1}

To which the XBMC server replies:

{ “id” : 1, “jsonrpc” : “2.0″, “result” : { “paused” : true, “playing” : true } }

Knowing this, I’ve set up serial-send symbols to issue commands, and parsing feedback should be fairly straightforward. Where things get a little murky is in navigation. The JSON 2.0 interface allows you to get playlist and library data such as artist and track info, but it doesn’t allow for some simple things like navigating the UI. Ideally, I’d like my touchpanel to have an XBMC page similar to what you’d find for a Kaleidescape or VideoRequest system with On-Screen-Display: navigation transports alongside player controls. The machine running XBMC (mine’s running on my MacBook Pro) can navigate the UI using the keyboard, Up/Down/Left/Right, Enter, and Esc. In order to replicate an OSD function through Crestron, it looks like I’ll need to use both the JSON 2.0 interface AND the (supposedly) deprecated HTTP API which it replaced, using the SendKey command. This command utilizes hex 0xF000 + the ASCII code for the keystroke, so while the complexity is simple, using two interfaces for one device is somewhat inelegant.

Ultimately, the “grand design” is to host XBMC on a dedicated Mac Mini machine, store home media on a meaty NAS, and control the whole 1080p experience from an IPad via Crestron.

CS4 Is Crazy Buggy

I’d almost swear Photoshop has it out for me. It seems to KNOW when I’ve made important progress and haven’t saved, because it picks just those moments to tank. I’ve gotten pretty quick on OSX’s claw-fingered printscreen key combo to snap off a screenshot before PS dumps; I can’t save the layer info but I’ll be damned if I lose work over a crash one more time.